From e1675019d40d8a25503b15664778c9b255ce158d Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:31:59 -0500 Subject: [PATCH] fix: restore `wasOpenedAtLogin` functionality (#42423) fix: restore opened at login functionality Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- 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 3a59aae97229..9097d2646248 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 ea08eec4a1f1..308a970cd6c7 100644 --- a/shell/browser/browser.h +++ b/shell/browser/browser.h @@ -236,6 +236,10 @@ class Browser : public 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 : public 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 c42d2c6cabd8..1320d8dc40c0 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 968ab0d29ff4..9102fa1bf1e3 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)); }