Skip to content

Commit

Permalink
fix: restore wasOpenedAtLogin functionality (#42422)
Browse files Browse the repository at this point in the history
fix: restore opened at login functionality

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
  • Loading branch information
trop[bot] and codebytere committed Jun 10, 2024
1 parent 8035eff commit 9ab67cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ class Browser : public WindowListObserver {
// Set docks' icon.
void DockSetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon);

void SetLaunchedAtLogin(bool launched_at_login) {
was_launched_at_login_ = launched_at_login;
}

#endif // BUILDFLAG(IS_MAC)

void ShowAboutPanel();
Expand Down Expand Up @@ -370,6 +374,7 @@ class Browser : public WindowListObserver {
#if BUILDFLAG(IS_MAC)
std::unique_ptr<ui::ScopedPasswordInputEnabler> password_input_enabler_;
base::Time last_dock_show_;
bool was_launched_at_login_;
#endif

base::Value::Dict about_panel_options_;
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/browser_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ LoginItemSettings GetLoginItemSettingsDeprecated() {
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
Expand All @@ -405,6 +406,7 @@ LoginItemSettings GetLoginItemSettingsDeprecated() {
settings = settings_deprecated;
} else {
settings.open_at_login = status == "enabled";
settings.opened_at_login = was_launched_at_login_;
settings.status = status;
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions shell/browser/mac/electron_application_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notify {
}
}

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));
}
Expand Down

0 comments on commit 9ab67cc

Please sign in to comment.