-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add login item API #6375
Add login item API #6375
Changes from 7 commits
98a97a5
b55f55c
c5610b2
2406c82
60ab71a
667b6d6
49b32b8
e4906f2
c100300
2633c2f
10bb8df
7326d3d
cde5947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,15 @@ class Browser : public WindowListObserver { | |
|
||
// Set docks' icon. | ||
void DockSetIcon(const gfx::Image& image); | ||
|
||
// Get login item status of app | ||
v8::Local<v8::Value> GetLoginItemStatus(mate::Arguments* args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
// 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,28 @@ | |
return prevent_default; | ||
} | ||
|
||
v8::Local<v8::Value> 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was a little confused by the different tenses here—I wonder if calling the keys There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍 I really like both suggestions, so how about these:
|
||
dict.Set("openedAsHidden", base::mac::WasLaunchedAsHiddenLoginItem()); | ||
|
||
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(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -598,6 +598,35 @@ 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 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 | ||
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 | ||
at login. | ||
|
||
* `openAsHidden` Boolean - `true` to open the app as hidden. Defaults to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameters should be placed above the description. |
||
`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 | ||
at login. | ||
|
||
### `app.commandLine.appendSwitch(switch[, value])` | ||
|
||
Append a switch (with optional `value`) to Chromium's command line. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong lines removed.