From 7f643973dd7af84b84de0056508440c5fa58c534 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Thu, 23 Apr 2026 22:19:53 +0300 Subject: [PATCH 1/2] p#479 make sure running app is the one handling urls --- indra/newview/llappviewermacosx-objc.h | 1 + indra/newview/llappviewermacosx-objc.mm | 25 +++++++++++++++++++++++++ indra/newview/llappviewermacosx.cpp | 15 +++++++++++++++ indra/newview/llappviewermacosx.h | 1 + 4 files changed, 42 insertions(+) diff --git a/indra/newview/llappviewermacosx-objc.h b/indra/newview/llappviewermacosx-objc.h index 3fbf4202f1a..bfbb48dadbf 100644 --- a/indra/newview/llappviewermacosx-objc.h +++ b/indra/newview/llappviewermacosx-objc.h @@ -31,5 +31,6 @@ #include void force_ns_sxeption(); +void register_url_schemes(); #endif // LL_LLAPPVIEWERMACOSX_OBJC_H diff --git a/indra/newview/llappviewermacosx-objc.mm b/indra/newview/llappviewermacosx-objc.mm index 96a6bc6edce..75d6b56e3eb 100644 --- a/indra/newview/llappviewermacosx-objc.mm +++ b/indra/newview/llappviewermacosx-objc.mm @@ -38,3 +38,28 @@ void force_ns_sxeption() NSException *exception = [NSException exceptionWithName:@"Forced NSException" reason:nullptr userInfo:nullptr]; @throw exception; } + +void register_url_schemes() +{ + @autoreleasepool // Objective-C automatic memory tracking and release. + { + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; + NSURL *bundleURL = [NSURL fileURLWithPath:bundlePath]; + + // Force Launch Services to re-register this app bundle + OSStatus status = LSRegisterURL((__bridge CFURLRef)bundleURL, true); + + if (status == noErr) + { + // Explicitly set this app as the default handler for our URL schemes + NSArray *schemes = @[@"secondlife", @"x-grid-location-info"]; + NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; + + for (NSString *scheme in schemes) + { + LSSetDefaultHandlerForURLScheme((__bridge CFStringRef)scheme, + (__bridge CFStringRef)bundleID); + } + } + } +} diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index 2bd9c8661a5..830e2d4473d 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -412,6 +412,21 @@ bool LLAppViewerMacOSX::restoreErrorTrap() return reset_count == 0; } +bool LLAppViewerMacOSX::initSLURLHandler() +{ + if (isSecondInstance()) + { + return false; + } + // Main secondlife:// registration is in info.plist, but macOS + // Launch Services caches URL scheme handlers, and a different + // viewer might still be registered. + // Register URL schemes with Launch Services on every launch + register_url_schemes(); + + return true; +} + std::string LLAppViewerMacOSX::generateSerialNumber() { char serial_md5[MD5HEX_STR_SIZE]; // Flawfinder: ignore diff --git a/indra/newview/llappviewermacosx.h b/indra/newview/llappviewermacosx.h index d50812a35ee..35fc99dbd90 100644 --- a/indra/newview/llappviewermacosx.h +++ b/indra/newview/llappviewermacosx.h @@ -46,6 +46,7 @@ class LLAppViewerMacOSX : public LLAppViewer protected: virtual bool restoreErrorTrap(); + virtual bool initSLURLHandler(); std::string generateSerialNumber(); virtual bool initParseCommandLine(LLCommandLineParser& clp); From 1eb60504f4dfe12e153ddb22fd496fcee9f1f7ee Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:44:28 +0300 Subject: [PATCH 2/2] p#5719 Detect hybernation I'm not sure if viewer should actually be shutting down on this, but as a minimum we should be updating or clearing marker files. If viewer crashes because of a hibernation, it isn't our problem. Viewer isn't built for that and we can't maintain 'heartbeats' in hibernation. --- indra/llwindow/llwindowwin32.cpp | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index 3cb2911f9a9..7e956983d02 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -2587,6 +2587,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { window_imp->post([=]() { + LL_INFOS("Window") << "Shutting down due to session terminating" << LL_ENDL; // Check if app needs cleanup or can be closed immediately. if (window_imp->mCallbacks->handleSessionExit(window_imp)) { @@ -2605,6 +2606,47 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ // if session is ending OS is going to take care of it. return 0; } + case WM_POWERBROADCAST: + { + LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_POWERBROADCAST"); + switch (w_param) + { + case PBT_APMSUSPEND: + LL_INFOS("Window") << "System is suspending (sleep/hibernate)" << LL_ENDL; + // System is about to enter sleep or hibernation + // Viewer can't function in hibernation, try to shut down. + // The system allows approximately two seconds for an + // application to handle this notification. + window_imp->post([=]() + { + LL_INFOS("Window") << "Shutting down due to system suspending (sleep/hibernate)" << LL_ENDL; + if (window_imp->mCallbacks->handleSessionExit(window_imp)) + { + // Get the app to initiate cleanup. + window_imp->mCallbacks->handleQuit(window_imp); + } + }); + ms_sleep(1000); + return TRUE; + + case PBT_APMRESUMESUSPEND: + LL_INFOS("Window") << "System is resuming from suspend" << LL_ENDL; + // Shouldn't be up, but log just in case. + return TRUE; + + case PBT_APMPOWERSTATUSCHANGE: + LL_INFOS("Window") << "Power status has changed" << LL_ENDL; + // Power status change (AC/battery) + // Viewer requires high performance, not much we can do. + // about it, but log for diagnostic purposes (example: + // OS trying to throw viewer at an iGPU after this message) + return TRUE; + + default: + break; + } + break; + } case WM_POST_UNINSTALL_: { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_POST_UNINSTALL_");