From 91205540c41bdd67d019bbb067d0e755bfca88ce Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 10 Jun 2024 09:39:56 -0500 Subject: [PATCH] fix: restore `wasOpenedAtLogin` functionality (#42411) fix: restore opened at login functionality --- docs/api/app.md | 2 +- shell/browser/browser.h | 5 +++++ shell/browser/browser_mac.mm | 2 ++ shell/browser/mac/electron_application_delegate.mm | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/api/app.md b/docs/api/app.md index 3a59aae972..9097d26462 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -1265,7 +1265,7 @@ Returns `Object`: * `openAtLogin` boolean - `true` if the app is set to open at login. * `openAsHidden` boolean _macOS_ _Deprecated_ - `true` if the app is set to open as hidden at login. This does not work on macOS 13 and up. -* `wasOpenedAtLogin` boolean _macOS_ _Deprecated_ - `true` if the app was opened at login automatically. This setting is not available on [MAS builds][mas-builds] or on macOS 13 and up. +* `wasOpenedAtLogin` boolean _macOS_ - `true` if the app was opened at login automatically. * `wasOpenedAsHidden` boolean _macOS_ _Deprecated_ - `true` if the app was opened as a hidden login item. This indicates that the app should not open any windows at startup. This setting is not available on [MAS builds][mas-builds] or on macOS 13 and up. * `restoreState` boolean _macOS_ _Deprecated_ - `true` if the app was opened as a login item that should restore the state from the previous session. This indicates that the app should restore the windows that were open the last time the app was closed. This setting is not available on [MAS builds][mas-builds] or on macOS 13 and up. * `status` string _macOS_ - can be one of `not-registered`, `enabled`, `requires-approval`, or `not-found`. diff --git a/shell/browser/browser.h b/shell/browser/browser.h index ef5205b046..b349d65eb9 100644 --- a/shell/browser/browser.h +++ b/shell/browser/browser.h @@ -236,6 +236,10 @@ class Browser : private WindowListObserver { // Set docks' icon. void DockSetIcon(v8::Isolate* isolate, v8::Local icon); + void SetLaunchedAtLogin(bool launched_at_login) { + was_launched_at_login_ = launched_at_login; + } + #endif // BUILDFLAG(IS_MAC) void ShowAboutPanel(); @@ -370,6 +374,7 @@ class Browser : private WindowListObserver { #if BUILDFLAG(IS_MAC) std::unique_ptr password_input_enabler_; base::Time last_dock_show_; + bool was_launched_at_login_; #endif base::Value::Dict about_panel_options_; diff --git a/shell/browser/browser_mac.mm b/shell/browser/browser_mac.mm index c42d2c6cab..1320d8dc40 100644 --- a/shell/browser/browser_mac.mm +++ b/shell/browser/browser_mac.mm @@ -392,6 +392,7 @@ v8::Local Browser::GetLoginItemSettings( platform_util::GetLoginItemEnabled(options.type, options.service_name); settings.open_at_login = status == "enabled" || status == "enabled-deprecated"; + settings.opened_at_login = was_launched_at_login_; if (@available(macOS 13, *)) settings.status = status; #else @@ -405,6 +406,7 @@ v8::Local Browser::GetLoginItemSettings( settings = settings_deprecated; } else { settings.open_at_login = status == "enabled"; + settings.opened_at_login = was_launched_at_login_; settings.status = status; } } else { diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index 968ab0d29f..9102fa1bf1 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/shell/browser/mac/electron_application_delegate.mm @@ -84,6 +84,14 @@ static NSDictionary* UNNotificationResponseToNSDictionary( } } + NSAppleEventDescriptor* event = + NSAppleEventManager.sharedAppleEventManager.currentAppleEvent; + BOOL launched_as_login_item = + (event.eventID == kAEOpenApplication && + [event paramDescriptorForKeyword:keyAEPropData].enumCodeValue == + keyAELaunchedAsLogInItem); + electron::Browser::Get()->SetLaunchedAtLogin(launched_as_login_item); + electron::Browser::Get()->DidFinishLaunching( electron::NSDictionaryToValue(notification_info)); }