Add path and args to LoginItemSettings struct
This commit is contained in:
parent
29d0a30d63
commit
e2501a80e4
8 changed files with 67 additions and 51 deletions
|
@ -12,7 +12,6 @@
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/browser.h"
|
|
||||||
#include "atom/browser/login_handler.h"
|
#include "atom/browser/login_handler.h"
|
||||||
#include "atom/browser/relauncher.h"
|
#include "atom/browser/relauncher.h"
|
||||||
#include "atom/common/atom_command_line.h"
|
#include "atom/common/atom_command_line.h"
|
||||||
|
@ -298,6 +297,8 @@ struct Converter<Browser::LoginItemSettings> {
|
||||||
|
|
||||||
dict.Get("openAtLogin", &(out->open_at_login));
|
dict.Get("openAtLogin", &(out->open_at_login));
|
||||||
dict.Get("openAsHidden", &(out->open_as_hidden));
|
dict.Get("openAsHidden", &(out->open_as_hidden));
|
||||||
|
dict.Get("path", &(out->path));
|
||||||
|
dict.Get("args", &(out->args));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,6 +747,12 @@ bool App::IsAccessibilitySupportEnabled() {
|
||||||
return ax_state->IsAccessibleBrowser();
|
return ax_state->IsAccessibleBrowser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Browser::LoginItemSettings App::GetLoginItemSettings(mate::Arguments* args) {
|
||||||
|
Browser::LoginItemSettings options;
|
||||||
|
args->GetNext(&options);
|
||||||
|
return Browser::Get()->GetLoginItemSettings(options);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void App::ImportCertificate(
|
void App::ImportCertificate(
|
||||||
const base::DictionaryValue& options,
|
const base::DictionaryValue& options,
|
||||||
|
@ -867,8 +874,7 @@ void App::BuildPrototype(
|
||||||
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
|
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
|
||||||
.SetMethod("setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
|
.SetMethod("setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
|
||||||
.SetMethod("getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
|
.SetMethod("getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
|
||||||
.SetMethod("getLoginItemSettings",
|
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
||||||
base::Bind(&Browser::GetLoginItemSettings, browser))
|
|
||||||
.SetMethod("setLoginItemSettings",
|
.SetMethod("setLoginItemSettings",
|
||||||
base::Bind(&Browser::SetLoginItemSettings, browser))
|
base::Bind(&Browser::SetLoginItemSettings, browser))
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "atom/browser/api/event_emitter.h"
|
#include "atom/browser/api/event_emitter.h"
|
||||||
#include "atom/browser/atom_browser_client.h"
|
#include "atom/browser/atom_browser_client.h"
|
||||||
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/browser_observer.h"
|
#include "atom/browser/browser_observer.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "chrome/browser/process_singleton.h"
|
#include "chrome/browser/process_singleton.h"
|
||||||
|
@ -123,6 +124,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
bool Relaunch(mate::Arguments* args);
|
bool Relaunch(mate::Arguments* args);
|
||||||
void DisableHardwareAcceleration(mate::Arguments* args);
|
void DisableHardwareAcceleration(mate::Arguments* args);
|
||||||
bool IsAccessibilitySupportEnabled();
|
bool IsAccessibilitySupportEnabled();
|
||||||
|
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void ImportCertificate(const base::DictionaryValue& options,
|
void ImportCertificate(const base::DictionaryValue& options,
|
||||||
const net::CompletionCallback& callback);
|
const net::CompletionCallback& callback);
|
||||||
|
|
|
@ -98,9 +98,11 @@ class Browser : public WindowListObserver {
|
||||||
bool restore_state = false;
|
bool restore_state = false;
|
||||||
bool opened_at_login = false;
|
bool opened_at_login = false;
|
||||||
bool opened_as_hidden = false;
|
bool opened_as_hidden = false;
|
||||||
|
base::string16 path;
|
||||||
|
std::vector<base::string16> args;
|
||||||
};
|
};
|
||||||
void SetLoginItemSettings(LoginItemSettings settings, mate::Arguments* args);
|
void SetLoginItemSettings(LoginItemSettings settings);
|
||||||
LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
LoginItemSettings GetLoginItemSettings(LoginItemSettings options);
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
// Hide the application.
|
// Hide the application.
|
||||||
|
|
|
@ -60,12 +60,11 @@ bool Browser::SetBadgeCount(int count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetLoginItemSettings(LoginItemSettings settings,
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||||
mate::Arguments* args) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||||
mate::Arguments* args) {
|
LoginItemSettings options) {
|
||||||
return LoginItemSettings();
|
return LoginItemSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,8 @@ bool Browser::ContinueUserActivity(const std::string& type,
|
||||||
return prevent_default;
|
return prevent_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
Browser::LoginItemSettings Browser::GetLoginItemSettings(mate::Arguments* args) {
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||||
|
LoginItemSettings options) {
|
||||||
LoginItemSettings settings;
|
LoginItemSettings settings;
|
||||||
settings.open_at_login = base::mac::CheckLoginItemStatus(
|
settings.open_at_login = base::mac::CheckLoginItemStatus(
|
||||||
&settings.open_as_hidden);
|
&settings.open_as_hidden);
|
||||||
|
@ -162,8 +163,7 @@ Browser::LoginItemSettings Browser::GetLoginItemSettings(mate::Arguments* args)
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetLoginItemSettings(LoginItemSettings settings,
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||||
mate::Arguments* args) {
|
|
||||||
if (settings.open_at_login)
|
if (settings.open_at_login)
|
||||||
base::mac::AddToLoginItems(settings.open_as_hidden);
|
base::mac::AddToLoginItems(settings.open_as_hidden);
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,11 +43,11 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadAppCommandLine(mate::Arguments* args,
|
bool ReadAppCommandLine(base::string16* exe,
|
||||||
base::string16* exe,
|
const std::vector<base::string16>& launch_args,
|
||||||
bool includeOriginalArg) {
|
bool includeOriginalArg) {
|
||||||
// Executable Path
|
// Executable Path
|
||||||
if (!args->GetNext(exe)) {
|
if (exe->empty()) {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (!PathService::Get(base::FILE_EXE, &path)) {
|
if (!PathService::Get(base::FILE_EXE, &path)) {
|
||||||
LOG(ERROR) << "Error getting app exe path";
|
LOG(ERROR) << "Error getting app exe path";
|
||||||
|
@ -56,21 +56,20 @@ bool ReadAppCommandLine(mate::Arguments* args,
|
||||||
*exe = path.value();
|
*exe = path.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read in optional args arg
|
if (launch_args.empty()) {
|
||||||
std::vector<base::string16> launch_args;
|
base::string16 formatString = includeOriginalArg ?
|
||||||
if (args->GetNext(&launch_args) && !launch_args.empty()) {
|
L"\"%s\" \"%%1\"" :
|
||||||
|
L"\"%s\"";
|
||||||
|
*exe = base::StringPrintf(formatString.c_str(), exe->c_str());
|
||||||
|
} else {
|
||||||
base::string16 formatString = includeOriginalArg ?
|
base::string16 formatString = includeOriginalArg ?
|
||||||
L"\"%s\" %s \"%%1\"" :
|
L"\"%s\" %s \"%%1\"" :
|
||||||
L"\"%s\" %s";
|
L"\"%s\" %s";
|
||||||
*exe = base::StringPrintf(formatString.c_str(),
|
*exe = base::StringPrintf(formatString.c_str(),
|
||||||
exe->c_str(),
|
exe->c_str(),
|
||||||
base::JoinString(launch_args, L" ").c_str());
|
base::JoinString(launch_args, L" ").c_str());
|
||||||
} else {
|
|
||||||
base::string16 formatString = includeOriginalArg ?
|
|
||||||
L"\"%s\" \"%%1\"" :
|
|
||||||
L"\"%s\"";
|
|
||||||
*exe = base::StringPrintf(formatString.c_str(), exe->c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +163,10 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
base::string16 exe;
|
base::string16 exe;
|
||||||
if (!ReadAppCommandLine(args, &exe, true))
|
std::vector<base::string16> launch_args;
|
||||||
|
args->GetNext(&exe);
|
||||||
|
args->GetNext(&launch_args);
|
||||||
|
if (!ReadAppCommandLine(&exe, launch_args, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (keyVal == exe) {
|
if (keyVal == exe) {
|
||||||
|
@ -198,7 +200,10 @@ bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
base::string16 exe;
|
base::string16 exe;
|
||||||
if (!ReadAppCommandLine(args, &exe, true))
|
std::vector<base::string16> launch_args;
|
||||||
|
args->GetNext(&exe);
|
||||||
|
args->GetNext(&launch_args);
|
||||||
|
if (!ReadAppCommandLine(&exe, launch_args, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Main Registry Key
|
// Main Registry Key
|
||||||
|
@ -228,7 +233,10 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
base::string16 exe;
|
base::string16 exe;
|
||||||
if (!ReadAppCommandLine(args, &exe, true))
|
std::vector<base::string16> launch_args;
|
||||||
|
args->GetNext(&exe);
|
||||||
|
args->GetNext(&launch_args);
|
||||||
|
if (!ReadAppCommandLine(&exe, launch_args, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Main Registry Key
|
// Main Registry Key
|
||||||
|
@ -261,14 +269,13 @@ bool Browser::SetBadgeCount(int count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetLoginItemSettings(LoginItemSettings settings,
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||||
mate::Arguments* args) {
|
|
||||||
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||||
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
||||||
|
|
||||||
if (settings.open_at_login) {
|
if (settings.open_at_login) {
|
||||||
base::string16 exe;
|
base::string16 exe = settings.path;
|
||||||
if (!ReadAppCommandLine(args, &exe, false)) return;
|
if (!ReadAppCommandLine(&exe, settings.args, false)) return;
|
||||||
|
|
||||||
key.WriteValue(GetAppUserModelID(), exe.c_str());
|
key.WriteValue(GetAppUserModelID(), exe.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,15 +284,15 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||||
mate::Arguments* args) {
|
LoginItemSettings options) {
|
||||||
LoginItemSettings settings;
|
LoginItemSettings settings;
|
||||||
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||||
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
||||||
base::string16 keyVal;
|
base::string16 keyVal;
|
||||||
|
|
||||||
if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) {
|
if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) {
|
||||||
base::string16 exe;
|
base::string16 exe = options.path;
|
||||||
if (ReadAppCommandLine(args, &exe, false)) {
|
if (ReadAppCommandLine(&exe, options.args, false)) {
|
||||||
settings.open_at_login = keyVal == exe;
|
settings.open_at_login = keyVal == exe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -758,15 +758,16 @@ Returns `Integer` - The current value displayed in the counter badge.
|
||||||
|
|
||||||
Returns `Boolean` - Whether the current desktop environment is Unity launcher.
|
Returns `Boolean` - Whether the current desktop environment is Unity launcher.
|
||||||
|
|
||||||
### `app.getLoginItemSettings([path, args])` _macOS_ _Windows_
|
### `app.getLoginItemSettings([options])` _macOS_ _Windows_
|
||||||
|
|
||||||
* `path` String (optional) _Windows_ - The executable path to compare against.
|
* `options` Object (optional)
|
||||||
Defaults to `process.execPath`.
|
* `path` String (optional) _Windows_ - The executable path to compare against.
|
||||||
* `args` String[] (optional) _Windows_ - The command-line arguments to compare
|
Defaults to `process.execPath`.
|
||||||
against. Defaults to an empty array.
|
* `args` String[] (optional) _Windows_ - The command-line arguments to compare
|
||||||
|
against. Defaults to an empty array.
|
||||||
|
|
||||||
If you provided arguments to `app.setLoginItemSettings` you need to pass the
|
If you provided `path` and `argg` potions to `app.setLoginItemSettings` then you
|
||||||
same arguments here for `openAtLogin` to be set correctly.
|
need to pass the same arguments here for `openAtLogin` to be set correctly.
|
||||||
|
|
||||||
Returns `Object`:
|
Returns `Object`:
|
||||||
|
|
||||||
|
@ -783,8 +784,7 @@ Returns `Object`:
|
||||||
app should restore the windows that were open the last time the app was
|
app should restore the windows that were open the last time the app was
|
||||||
closed. This setting is only supported on macOS.
|
closed. This setting is only supported on macOS.
|
||||||
|
|
||||||
**Note:** This API has no effect on
|
**Note:** This API has no effect on [MAS builds][mas-builds].
|
||||||
[MAS builds][mas-builds].
|
|
||||||
|
|
||||||
### `app.setLoginItemSettings(settings[, path, args])` _macOS_ _Windows_
|
### `app.setLoginItemSettings(settings[, path, args])` _macOS_ _Windows_
|
||||||
|
|
||||||
|
@ -796,10 +796,11 @@ Returns `Object`:
|
||||||
`app.getLoginItemStatus().wasOpenedAsHidden` should be checked when the app
|
`app.getLoginItemStatus().wasOpenedAsHidden` should be checked when the app
|
||||||
is opened to know the current value. This setting is only supported on
|
is opened to know the current value. This setting is only supported on
|
||||||
macOS.
|
macOS.
|
||||||
* `path` String (optional) _Windows_ - The executable to launch at login.
|
* `path` String (optional) _Windows_ - The executable to launch at login.
|
||||||
Defaults to `process.execPath`.
|
Defaults to `process.execPath`.
|
||||||
* `args` String[] (optional) _Windows_ - The command-line arguments to pass to the
|
* `args` String[] (optional) _Windows_ - The command-line arguments to pass to
|
||||||
executable. Defaults to an empty array. Take care to wrap paths in quotes.
|
the executable. Defaults to an empty array. Take care to wrap paths in
|
||||||
|
quotes.
|
||||||
|
|
||||||
Set the app's login item settings.
|
Set the app's login item settings.
|
||||||
|
|
||||||
|
@ -818,8 +819,7 @@ app.setLoginItemSettings({openAtLogin: true}, updateExe, [
|
||||||
])
|
])
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** This API has no effect on
|
**Note:** This API has no effect on [MAS builds][mas-builds].
|
||||||
[MAS builds][mas-builds].
|
|
||||||
|
|
||||||
### `app.isAccessibilitySupportEnabled()` _macOS_ _Windows_
|
### `app.isAccessibilitySupportEnabled()` _macOS_ _Windows_
|
||||||
|
|
||||||
|
|
|
@ -362,10 +362,10 @@ describe('app module', function () {
|
||||||
'--process-start-args', `"--hidden"`
|
'--process-start-args', `"--hidden"`
|
||||||
]
|
]
|
||||||
|
|
||||||
app.setLoginItemSettings({openAtLogin: true}, updateExe, processStartArgs)
|
app.setLoginItemSettings({openAtLogin: true, path: updateExe, args: processStartArgs})
|
||||||
|
|
||||||
assert(!app.getLoginItemSettings().openAtLogin)
|
assert.equal(app.getLoginItemSettings().openAtLogin, false)
|
||||||
assert(app.getLoginItemSettings(updateExe, processStartArgs))
|
assert.equal(app.getLoginItemSettings({path: updateExe, args: processStartArgs}).openAtLogin, true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue