Update API to get/setLoginItemSettings
This commit is contained in:
parent
e4906f2d87
commit
c100300764
4 changed files with 85 additions and 44 deletions
|
@ -71,6 +71,33 @@ struct Converter<Browser::UserTask> {
|
|||
};
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
template<>
|
||||
struct Converter<Browser::LoginItemSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> 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<v8::Value> 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))
|
||||
|
|
|
@ -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<v8::Value> 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)
|
||||
|
|
|
@ -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<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());
|
||||
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() {
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue