From 98a97a52ea7d5194145f868ced55025a1cffac6c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 11:43:44 -0700 Subject: [PATCH 01/13] Add getLoginItemLaunchStatus API --- atom/browser/api/atom_api_app.cc | 4 ++-- atom/browser/browser.h | 2 ++ atom/browser/browser_mac.mm | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index a39f9809ebf0..0e4421316e53 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -527,8 +527,8 @@ void App::BuildPrototype( .SetMethod("show", base::Bind(&Browser::Show, browser)) .SetMethod("setUserActivity", base::Bind(&Browser::SetUserActivity, browser)) - .SetMethod("getCurrentActivityType", - base::Bind(&Browser::GetCurrentActivityType, browser)) + .SetMethod("getLoginItemLaunchStatus", + base::Bind(&Browser::GetLoginItemLaunchStatus, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 37d2e11e6799..e3d7db92e330 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -134,6 +134,8 @@ class Browser : public WindowListObserver { // Set docks' icon. void DockSetIcon(const gfx::Image& image); + + v8::Local GetLoginItemLaunchStatus(mate::Arguments* args); #endif // defined(OS_MACOSX) #if defined(OS_WIN) diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index bb789365ffb2..8472ef757981 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -11,9 +11,11 @@ #include "atom/browser/window_list.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" +#include "base/mac/mac_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/sys_string_conversions.h" #include "brightray/common/application_info.h" +#include "native_mate/dictionary.h" #include "net/base/mac/url_conversions.h" #include "url/gurl.h" @@ -148,6 +150,14 @@ bool Browser::ContinueUserActivity(const std::string& type, return prevent_default; } +v8::Local Browser::GetLoginItemLaunchStatus(mate::Arguments* args) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); + dict.Set("loginItem", base::mac::WasLaunchedAsLoginOrResumeItem()); + dict.Set("hidden", base::mac::WasLaunchedAsHiddenLoginItem()); + dict.Set("restoreState", base::mac::WasLaunchedAsLoginItemRestoreState()); + return dict.GetHandle(); +} + std::string Browser::GetExecutableFileVersion() const { return brightray::GetApplicationVersion(); } From b55f55cfc4ac397116d9f5a397a50b1f781b6d53 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 13:17:39 -0700 Subject: [PATCH 02/13] Add app.getLoginItemStatus API --- atom/browser/api/atom_api_app.cc | 2 ++ atom/browser/browser.h | 4 ++++ atom/browser/browser_mac.mm | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 0e4421316e53..f032e7043d67 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -529,6 +529,8 @@ void App::BuildPrototype( base::Bind(&Browser::SetUserActivity, browser)) .SetMethod("getLoginItemLaunchStatus", base::Bind(&Browser::GetLoginItemLaunchStatus, browser)) + .SetMethod("getLoginItemStatus", + base::Bind(&Browser::GetLoginItemStatus, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index e3d7db92e330..32fa67b30744 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -135,7 +135,11 @@ class Browser : public WindowListObserver { // Set docks' icon. void DockSetIcon(const gfx::Image& image); + // Get login item status of current app launch v8::Local GetLoginItemLaunchStatus(mate::Arguments* args); + + // Get login item status of app + v8::Local GetLoginItemStatus(mate::Arguments* args); #endif // defined(OS_MACOSX) #if defined(OS_WIN) diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 8472ef757981..0da56347ef66 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -158,6 +158,14 @@ v8::Local Browser::GetLoginItemLaunchStatus(mate::Arguments* args) { return dict.GetHandle(); } +v8::Local Browser::GetLoginItemStatus(mate::Arguments* args) { + bool hidden = false; + mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); + dict.Set("loginItem", base::mac::CheckLoginItemStatus(&hidden)); + dict.Set("hidden", hidden); + return dict.GetHandle(); +} + std::string Browser::GetExecutableFileVersion() const { return brightray::GetApplicationVersion(); } From c5610b218621db770d04eeb05d5b4014eaec3a01 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 13:26:16 -0700 Subject: [PATCH 03/13] Add API to add/remove app as login item --- atom/browser/api/atom_api_app.cc | 4 ++++ atom/browser/browser.h | 6 ++++++ atom/browser/browser_mac.mm | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index f032e7043d67..979c7b45fe2b 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -531,6 +531,10 @@ void App::BuildPrototype( base::Bind(&Browser::GetLoginItemLaunchStatus, browser)) .SetMethod("getLoginItemStatus", base::Bind(&Browser::GetLoginItemStatus, browser)) + .SetMethod("setAsLoginItem", + base::Bind(&Browser::SetAsLoginItem, browser)) + .SetMethod("removeAsLoginItem", + base::Bind(&Browser::RemoveAsLoginItem, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 32fa67b30744..6921e946d466 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -140,6 +140,12 @@ class Browser : public WindowListObserver { // Get login item status of app v8::Local GetLoginItemStatus(mate::Arguments* args); + + // Set app as a login item + void SetAsLoginItem(mate::Arguments* args); + + // Remove app as a login item + void RemoveAsLoginItem(); #endif // defined(OS_MACOSX) #if defined(OS_WIN) diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 0da56347ef66..0bc2187a9cd4 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -166,6 +166,16 @@ v8::Local Browser::GetLoginItemStatus(mate::Arguments* args) { return dict.GetHandle(); } +void Browser::SetAsLoginItem(mate::Arguments* args) { + bool hidden = false; + args->GetNext(&hidden); + base::mac::AddToLoginItems(hidden); +} + +void Browser::RemoveAsLoginItem() { + base::mac::RemoveFromLoginItems(); +} + std::string Browser::GetExecutableFileVersion() const { return brightray::GetApplicationVersion(); } From 2406c82ef53b9cbd807519a4fbb37a9c2c35b24f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 13:34:14 -0700 Subject: [PATCH 04/13] Add specs for login item APIs --- spec/api-app-spec.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 111d387d3404..fdb71548401d 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -298,4 +298,33 @@ describe('app module', function () { assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42) }) }) + + describe('app.getLoginItemStatus API', function () { + if (process.platform !== 'darwin') return + + afterEach(function () { + app.removeAsLoginItem() + assert.equal(app.getLoginItemStatus().loginItem, false) + }) + + it('returns the login item status of the app', function () { + app.setAsLoginItem(true) + assert.equal(app.getLoginItemStatus().loginItem, true) + assert.equal(app.getLoginItemStatus().hidden, true) + + app.setAsLoginItem(false) + assert.equal(app.getLoginItemStatus().loginItem, true) + assert.equal(app.getLoginItemStatus().hidden, false) + }) + }) + + describe('app.getLoginItemLaunchStatus API', function () { + if (process.platform !== 'darwin') return + + it('returns the login item status launch of the app', function () { + assert.equal(app.getLoginItemLaunchStatus().loginItem, false) + assert.equal(app.getLoginItemLaunchStatus().hidden, false) + assert.equal(app.getLoginItemLaunchStatus().restoreState, false) + }) + }) }) From 60ab71a70698ba16c5c8496d6a559e85965d0ff8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 13:57:20 -0700 Subject: [PATCH 05/13] Combine launch and current status login item APIs --- atom/browser/api/atom_api_app.cc | 2 -- atom/browser/browser.h | 3 --- atom/browser/browser_mac.mm | 16 ++++++---------- spec/api-app-spec.js | 26 +++++++++++--------------- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 979c7b45fe2b..4eb026549a33 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -527,8 +527,6 @@ void App::BuildPrototype( .SetMethod("show", base::Bind(&Browser::Show, browser)) .SetMethod("setUserActivity", base::Bind(&Browser::SetUserActivity, browser)) - .SetMethod("getLoginItemLaunchStatus", - base::Bind(&Browser::GetLoginItemLaunchStatus, browser)) .SetMethod("getLoginItemStatus", base::Bind(&Browser::GetLoginItemStatus, browser)) .SetMethod("setAsLoginItem", diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 6921e946d466..6aeb6ed0923e 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -135,9 +135,6 @@ class Browser : public WindowListObserver { // Set docks' icon. void DockSetIcon(const gfx::Image& image); - // Get login item status of current app launch - v8::Local GetLoginItemLaunchStatus(mate::Arguments* args); - // Get login item status of app v8::Local GetLoginItemStatus(mate::Arguments* args); diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 0bc2187a9cd4..6207a221e644 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -150,19 +150,15 @@ bool Browser::ContinueUserActivity(const std::string& type, return prevent_default; } -v8::Local Browser::GetLoginItemLaunchStatus(mate::Arguments* args) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); - dict.Set("loginItem", base::mac::WasLaunchedAsLoginOrResumeItem()); - dict.Set("hidden", base::mac::WasLaunchedAsHiddenLoginItem()); - dict.Set("restoreState", base::mac::WasLaunchedAsLoginItemRestoreState()); - return dict.GetHandle(); -} - v8::Local Browser::GetLoginItemStatus(mate::Arguments* args) { bool hidden = false; mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); - dict.Set("loginItem", base::mac::CheckLoginItemStatus(&hidden)); - dict.Set("hidden", hidden); + dict.Set("openAtLogin", base::mac::CheckLoginItemStatus(&hidden)); + dict.Set("openAsHidden", hidden); + dict.Set("restoreState", base::mac::WasLaunchedAsLoginItemRestoreState()); + dict.Set("openedAtLogin", base::mac::WasLaunchedAsLoginOrResumeItem()); + dict.Set("openedAsHidden", base::mac::WasLaunchedAsHiddenLoginItem()); + return dict.GetHandle(); } diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index fdb71548401d..af6a7c7e6887 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -302,29 +302,25 @@ describe('app module', function () { describe('app.getLoginItemStatus API', function () { if (process.platform !== 'darwin') return + beforeEach(function () { + assert.equal(app.getLoginItemStatus().openedAtLogin, false) + assert.equal(app.getLoginItemStatus().openedAsHidden, false) + assert.equal(app.getLoginItemStatus().restoreState, false) + }) + afterEach(function () { app.removeAsLoginItem() - assert.equal(app.getLoginItemStatus().loginItem, false) + assert.equal(app.getLoginItemStatus().openAtLogin, false) }) it('returns the login item status of the app', function () { app.setAsLoginItem(true) - assert.equal(app.getLoginItemStatus().loginItem, true) - assert.equal(app.getLoginItemStatus().hidden, true) + assert.equal(app.getLoginItemStatus().openAtLogin, true) + assert.equal(app.getLoginItemStatus().openAsHidden, true) app.setAsLoginItem(false) - assert.equal(app.getLoginItemStatus().loginItem, true) - assert.equal(app.getLoginItemStatus().hidden, false) - }) - }) - - describe('app.getLoginItemLaunchStatus API', function () { - if (process.platform !== 'darwin') return - - it('returns the login item status launch of the app', function () { - assert.equal(app.getLoginItemLaunchStatus().loginItem, false) - assert.equal(app.getLoginItemLaunchStatus().hidden, false) - assert.equal(app.getLoginItemLaunchStatus().restoreState, false) + assert.equal(app.getLoginItemStatus().openAtLogin, true) + assert.equal(app.getLoginItemStatus().openAsHidden, false) }) }) }) From 667b6d63709c1fb03ee19d433bd10699a415a557 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 14:06:38 -0700 Subject: [PATCH 06/13] Doc login item APIs --- docs/api/app.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/api/app.md b/docs/api/app.md index cfda6b574be1..71e47c8a7a16 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -598,6 +598,33 @@ Returns the current value displayed in the counter badge. Returns whether current desktop environment is Unity launcher. +### `app.getLoginItemStatus()` _macOS_ + +Return an Object with the login item status the app. + +* `openAtLogin` Boolean - `true` if the app is set to open at login. +* `openAsHidden` Boolean - `true` if the app is set to open as hidden at login. +* `openedAtLogin` Boolean - `true` if the app was opened at login automatically. +* `openedAsHidden` Boolean - `true` if the app was opened as a hidden login + item. This indicates that the app should not open any windows at startup. +* `restoreState` Boolean - `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. + +### `app.setAsLoginItem([openAsHidden])` _macOS_ + +Set the app as a login item. This will cause the app to be opened automatically +on login. + +* `openAsHidden` Boolean - `true` to hide the app when opened. Defaults to + `false`. + +### `app.removeAsLoginItem()` _macOS_ + +Removes the app as a login item. The app will no longer be opened automatically +on login. + ### `app.commandLine.appendSwitch(switch[, value])` Append a switch (with optional `value`) to Chromium's command line. From 49b32b8380a9aae4f98a4d40baa09295ea69a151 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Jul 2016 14:17:19 -0700 Subject: [PATCH 07/13] Mention open as hidden is manually configurable --- docs/api/app.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 71e47c8a7a16..7816f7fe986f 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -600,7 +600,7 @@ Returns whether current desktop environment is Unity launcher. ### `app.getLoginItemStatus()` _macOS_ -Return an Object with the login item status the app. +Return an Object with the login item status of the app. * `openAtLogin` Boolean - `true` if the app is set to open at login. * `openAsHidden` Boolean - `true` if the app is set to open as hidden at login. @@ -615,15 +615,17 @@ Return an Object with the login item status the app. ### `app.setAsLoginItem([openAsHidden])` _macOS_ Set the app as a login item. This will cause the app to be opened automatically -on login. +at login. -* `openAsHidden` Boolean - `true` to hide the app when opened. Defaults to - `false`. +* `openAsHidden` Boolean - `true` to open the app as hidden. Defaults to + `false`. The user can edit this setting from the System Preferences so + `app.getLoginItemStatus().openedAsHidden` should be checked when the app + is opened to know the current value. ### `app.removeAsLoginItem()` _macOS_ Removes the app as a login item. The app will no longer be opened automatically -on login. +at login. ### `app.commandLine.appendSwitch(switch[, value])` From e4906f2d8729836f1be3e4e07c878d71fffb05bc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 14:29:43 -0700 Subject: [PATCH 08/13] Add back getCurrentActivityType --- atom/browser/api/atom_api_app.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 4eb026549a33..f8a7077a1268 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -527,6 +527,8 @@ void App::BuildPrototype( .SetMethod("show", base::Bind(&Browser::Show, browser)) .SetMethod("setUserActivity", base::Bind(&Browser::SetUserActivity, browser)) + .SetMethod("getCurrentActivityType", + base::Bind(&Browser::GetCurrentActivityType, browser)) .SetMethod("getLoginItemStatus", base::Bind(&Browser::GetLoginItemStatus, browser)) .SetMethod("setAsLoginItem", From c1003007641bb5cb2438e47a5da5ef71f5b47357 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 16:29:09 -0700 Subject: [PATCH 09/13] Update API to get/setLoginItemSettings --- atom/browser/api/atom_api_app.cc | 37 ++++++++++++++++++++++++----- atom/browser/browser.h | 19 +++++++++------ atom/browser/browser_mac.mm | 33 +++++++++++--------------- spec/api-app-spec.js | 40 ++++++++++++++++++++++---------- 4 files changed, 85 insertions(+), 44 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index f8a7077a1268..b0a842d4ca18 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -71,6 +71,33 @@ struct Converter { }; #endif +#if defined(OS_MACOSX) +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, v8::Local val, + Browser::LoginItemSettings* out) { + mate::Dictionary dict; + if (!ConvertFromV8(isolate, val, &dict)) + return false; + + dict.Get("openAtLogin", &(out->open_at_login)); + dict.Get("openAsHidden", &(out->open_as_hidden)); + return true; + } + + static v8::Local ToV8(v8::Isolate* isolate, + Browser::LoginItemSettings val) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + dict.Set("openAtLogin", val.open_at_login); + dict.Set("openAsHidden", val.open_as_hidden); + dict.Set("restoreState", val.restore_state); + dict.Set("openedAtLogin", val.opened_at_login); + dict.Set("openedAsHidden", val.opened_as_hidden); + return dict.GetHandle(); + } +}; +#endif + } // namespace mate @@ -529,12 +556,10 @@ void App::BuildPrototype( base::Bind(&Browser::SetUserActivity, browser)) .SetMethod("getCurrentActivityType", base::Bind(&Browser::GetCurrentActivityType, browser)) - .SetMethod("getLoginItemStatus", - base::Bind(&Browser::GetLoginItemStatus, browser)) - .SetMethod("setAsLoginItem", - base::Bind(&Browser::SetAsLoginItem, browser)) - .SetMethod("removeAsLoginItem", - base::Bind(&Browser::RemoveAsLoginItem, browser)) + .SetMethod("getLoginItemSettings", + base::Bind(&Browser::GetLoginItemSettings, browser)) + .SetMethod("setLoginItemSettings", + base::Bind(&Browser::SetLoginItemSettings, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 6aeb6ed0923e..be51d7ec006d 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -92,6 +92,14 @@ class Browser : public WindowListObserver { int GetBadgeCount(); #if defined(OS_MACOSX) + struct LoginItemSettings { + bool open_at_login = false; + bool open_as_hidden = false; + bool restore_state = false; + bool opened_at_login = false; + bool opened_as_hidden = false; + }; + // Hide the application. void Hide(); @@ -135,14 +143,11 @@ class Browser : public WindowListObserver { // Set docks' icon. void DockSetIcon(const gfx::Image& image); - // Get login item status of app - v8::Local GetLoginItemStatus(mate::Arguments* args); + // Get login item settings of app + LoginItemSettings GetLoginItemSettings(); - // Set app as a login item - void SetAsLoginItem(mate::Arguments* args); - - // Remove app as a login item - void RemoveAsLoginItem(); + // Set login item settings of app + void SetLoginItemSettings(LoginItemSettings settings); #endif // defined(OS_MACOSX) #if defined(OS_WIN) diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 6207a221e644..4dfa3aa96308 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -15,7 +15,6 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/sys_string_conversions.h" #include "brightray/common/application_info.h" -#include "native_mate/dictionary.h" #include "net/base/mac/url_conversions.h" #include "url/gurl.h" @@ -150,26 +149,22 @@ bool Browser::ContinueUserActivity(const std::string& type, return prevent_default; } -v8::Local Browser::GetLoginItemStatus(mate::Arguments* args) { - bool hidden = false; - mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); - dict.Set("openAtLogin", base::mac::CheckLoginItemStatus(&hidden)); - dict.Set("openAsHidden", hidden); - dict.Set("restoreState", base::mac::WasLaunchedAsLoginItemRestoreState()); - dict.Set("openedAtLogin", base::mac::WasLaunchedAsLoginOrResumeItem()); - dict.Set("openedAsHidden", base::mac::WasLaunchedAsHiddenLoginItem()); - - return dict.GetHandle(); +Browser::LoginItemSettings Browser::GetLoginItemSettings() { + LoginItemSettings settings; + settings.open_at_login = base::mac::CheckLoginItemStatus( + &settings.open_as_hidden); + settings.restore_state = base::mac::WasLaunchedAsLoginItemRestoreState(); + settings.opened_at_login = base::mac::WasLaunchedAsLoginOrResumeItem(); + settings.opened_as_hidden = base::mac::WasLaunchedAsHiddenLoginItem(); + return settings; } -void Browser::SetAsLoginItem(mate::Arguments* args) { - bool hidden = false; - args->GetNext(&hidden); - base::mac::AddToLoginItems(hidden); -} - -void Browser::RemoveAsLoginItem() { - base::mac::RemoveFromLoginItems(); +void Browser::SetLoginItemSettings(LoginItemSettings settings) { + if (settings.open_at_login) { + base::mac::AddToLoginItems(settings.open_as_hidden); + } else { + base::mac::RemoveFromLoginItems(); + } } std::string Browser::GetExecutableFileVersion() const { diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index af6a7c7e6887..de582358553d 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -299,28 +299,44 @@ describe('app module', function () { }) }) - describe('app.getLoginItemStatus API', function () { + describe('app.get/setLoginItemSettings API', function () { if (process.platform !== 'darwin') return beforeEach(function () { - assert.equal(app.getLoginItemStatus().openedAtLogin, false) - assert.equal(app.getLoginItemStatus().openedAsHidden, false) - assert.equal(app.getLoginItemStatus().restoreState, false) + app.setLoginItemSettings({openAtLogin: false}) }) afterEach(function () { - app.removeAsLoginItem() - assert.equal(app.getLoginItemStatus().openAtLogin, false) + app.setLoginItemSettings({openAtLogin: false}) }) it('returns the login item status of the app', function () { - app.setAsLoginItem(true) - assert.equal(app.getLoginItemStatus().openAtLogin, true) - assert.equal(app.getLoginItemStatus().openAsHidden, true) + app.setLoginItemSettings({openAtLogin: true}) + assert.deepEqual(app.getLoginItemSettings(), { + openAtLogin: true, + openAsHidden: false, + openedAtLogin: false, + openedAsHidden: false, + restoreState: false + }) - app.setAsLoginItem(false) - assert.equal(app.getLoginItemStatus().openAtLogin, true) - assert.equal(app.getLoginItemStatus().openAsHidden, false) + app.setLoginItemSettings({openAtLogin: true, openAsHidden: true}) + assert.deepEqual(app.getLoginItemSettings(), { + openAtLogin: true, + openAsHidden: true, + openedAtLogin: false, + openedAsHidden: false, + restoreState: false + }) + + app.setLoginItemSettings({}) + assert.deepEqual(app.getLoginItemSettings(), { + openAtLogin: false, + openAsHidden: false, + openedAtLogin: false, + openedAsHidden: false, + restoreState: false + }) }) }) }) From 2633c2f735780bd9423328c4462600211c218af3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 16:29:58 -0700 Subject: [PATCH 10/13] Add was prefix to current launch settings --- atom/browser/api/atom_api_app.cc | 4 ++-- spec/api-app-spec.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index b0a842d4ca18..9d799f115007 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -91,8 +91,8 @@ struct Converter { dict.Set("openAtLogin", val.open_at_login); dict.Set("openAsHidden", val.open_as_hidden); dict.Set("restoreState", val.restore_state); - dict.Set("openedAtLogin", val.opened_at_login); - dict.Set("openedAsHidden", val.opened_as_hidden); + dict.Set("wasOpenedAtLogin", val.opened_at_login); + dict.Set("wasOpenedAsHidden", val.opened_as_hidden); return dict.GetHandle(); } }; diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index de582358553d..8ceb44f19d33 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -315,8 +315,8 @@ describe('app module', function () { assert.deepEqual(app.getLoginItemSettings(), { openAtLogin: true, openAsHidden: false, - openedAtLogin: false, - openedAsHidden: false, + wasOpenedAtLogin: false, + wasOpenedAsHidden: false, restoreState: false }) @@ -324,8 +324,8 @@ describe('app module', function () { assert.deepEqual(app.getLoginItemSettings(), { openAtLogin: true, openAsHidden: true, - openedAtLogin: false, - openedAsHidden: false, + wasOpenedAtLogin: false, + wasOpenedAsHidden: false, restoreState: false }) @@ -333,8 +333,8 @@ describe('app module', function () { assert.deepEqual(app.getLoginItemSettings(), { openAtLogin: false, openAsHidden: false, - openedAtLogin: false, - openedAsHidden: false, + wasOpenedAtLogin: false, + wasOpenedAsHidden: false, restoreState: false }) }) From 10bb8df09a203fdf8ab54f662df6a3a3b1182119 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 16:33:26 -0700 Subject: [PATCH 11/13] Update login item API docs --- docs/api/app.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 7816f7fe986f..e0b13ef5c7a6 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -598,29 +598,32 @@ Returns the current value displayed in the counter badge. Returns whether current desktop environment is Unity launcher. -### `app.getLoginItemStatus()` _macOS_ +### `app.getLoginItemSettings()` _macOS_ Return an Object with the login item status of the app. * `openAtLogin` Boolean - `true` if the app is set to open at login. * `openAsHidden` Boolean - `true` if the app is set to open as hidden at login. -* `openedAtLogin` Boolean - `true` if the app was opened at login automatically. -* `openedAsHidden` Boolean - `true` if the app was opened as a hidden login +* `wasOpenedAtLogin` Boolean - `true` if the app was opened at login + automatically. +* `wasOpenedAsHidden` Boolean - `true` if the app was opened as a hidden login item. This indicates that the app should not open any windows at startup. * `restoreState` Boolean - `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. -### `app.setAsLoginItem([openAsHidden])` _macOS_ +### `app.setLoginItemSettings(settings)` _macOS_ -Set the app as a login item. This will cause the app to be opened automatically -at login. +* `settings` Object + * `openAtLogin` Boolean - `true` to open the app at login, `false` to remove + the app as a login item. Defaults to `false`. + * `openAsHidden` Boolean - `true` to open the app as hidden. Defaults to + `false`. The user can edit this setting from the System Preferences so + `app.getLoginItemStatus().wasOpenedAsHidden` should be checked when the app + is opened to know the current value. -* `openAsHidden` Boolean - `true` to open the app as hidden. Defaults to - `false`. The user can edit this setting from the System Preferences so - `app.getLoginItemStatus().openedAsHidden` should be checked when the app - is opened to know the current value. +Set the app's as a login item settings. ### `app.removeAsLoginItem()` _macOS_ From 7326d3d3d537dcb1d3d80e7228d8d62d82fc58b6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 16:38:12 -0700 Subject: [PATCH 12/13] :art: --- atom/browser/browser_mac.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 4dfa3aa96308..4328dcba4820 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -160,11 +160,10 @@ Browser::LoginItemSettings Browser::GetLoginItemSettings() { } void Browser::SetLoginItemSettings(LoginItemSettings settings) { - if (settings.open_at_login) { + if (settings.open_at_login) base::mac::AddToLoginItems(settings.open_as_hidden); - } else { + else base::mac::RemoveFromLoginItems(); - } } std::string Browser::GetExecutableFileVersion() const { From cde594775d12c422921fced43948b067014e5add Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Jul 2016 16:40:53 -0700 Subject: [PATCH 13/13] Remove API that is no longer available --- docs/api/app.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index e0b13ef5c7a6..c7e0998b6cc3 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -600,7 +600,7 @@ Returns whether current desktop environment is Unity launcher. ### `app.getLoginItemSettings()` _macOS_ -Return an Object with the login item status of the app. +Return an Object with the login item settings of the app. * `openAtLogin` Boolean - `true` if the app is set to open at login. * `openAsHidden` Boolean - `true` if the app is set to open as hidden at login. @@ -623,12 +623,7 @@ Return an Object with the login item status of the app. `app.getLoginItemStatus().wasOpenedAsHidden` should be checked when the app is opened to know the current value. -Set the app's as a login item settings. - -### `app.removeAsLoginItem()` _macOS_ - -Removes the app as a login item. The app will no longer be opened automatically -at login. +Set the app's login item settings. ### `app.commandLine.appendSwitch(switch[, value])`