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
|
#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
|
} // namespace mate
|
||||||
|
|
||||||
|
|
||||||
|
@ -529,12 +556,10 @@ void App::BuildPrototype(
|
||||||
base::Bind(&Browser::SetUserActivity, browser))
|
base::Bind(&Browser::SetUserActivity, browser))
|
||||||
.SetMethod("getCurrentActivityType",
|
.SetMethod("getCurrentActivityType",
|
||||||
base::Bind(&Browser::GetCurrentActivityType, browser))
|
base::Bind(&Browser::GetCurrentActivityType, browser))
|
||||||
.SetMethod("getLoginItemStatus",
|
.SetMethod("getLoginItemSettings",
|
||||||
base::Bind(&Browser::GetLoginItemStatus, browser))
|
base::Bind(&Browser::GetLoginItemSettings, browser))
|
||||||
.SetMethod("setAsLoginItem",
|
.SetMethod("setLoginItemSettings",
|
||||||
base::Bind(&Browser::SetAsLoginItem, browser))
|
base::Bind(&Browser::SetLoginItemSettings, browser))
|
||||||
.SetMethod("removeAsLoginItem",
|
|
||||||
base::Bind(&Browser::RemoveAsLoginItem, browser))
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
|
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
|
||||||
|
|
|
@ -92,6 +92,14 @@ class Browser : public WindowListObserver {
|
||||||
int GetBadgeCount();
|
int GetBadgeCount();
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#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.
|
// Hide the application.
|
||||||
void Hide();
|
void Hide();
|
||||||
|
|
||||||
|
@ -135,14 +143,11 @@ class Browser : public WindowListObserver {
|
||||||
// Set docks' icon.
|
// Set docks' icon.
|
||||||
void DockSetIcon(const gfx::Image& image);
|
void DockSetIcon(const gfx::Image& image);
|
||||||
|
|
||||||
// Get login item status of app
|
// Get login item settings of app
|
||||||
v8::Local<v8::Value> GetLoginItemStatus(mate::Arguments* args);
|
LoginItemSettings GetLoginItemSettings();
|
||||||
|
|
||||||
// Set app as a login item
|
// Set login item settings of app
|
||||||
void SetAsLoginItem(mate::Arguments* args);
|
void SetLoginItemSettings(LoginItemSettings settings);
|
||||||
|
|
||||||
// Remove app as a login item
|
|
||||||
void RemoveAsLoginItem();
|
|
||||||
#endif // defined(OS_MACOSX)
|
#endif // defined(OS_MACOSX)
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "brightray/common/application_info.h"
|
#include "brightray/common/application_info.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "net/base/mac/url_conversions.h"
|
#include "net/base/mac/url_conversions.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
@ -150,26 +149,22 @@ bool Browser::ContinueUserActivity(const std::string& type,
|
||||||
return prevent_default;
|
return prevent_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> Browser::GetLoginItemStatus(mate::Arguments* args) {
|
Browser::LoginItemSettings Browser::GetLoginItemSettings() {
|
||||||
bool hidden = false;
|
LoginItemSettings settings;
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate());
|
settings.open_at_login = base::mac::CheckLoginItemStatus(
|
||||||
dict.Set("openAtLogin", base::mac::CheckLoginItemStatus(&hidden));
|
&settings.open_as_hidden);
|
||||||
dict.Set("openAsHidden", hidden);
|
settings.restore_state = base::mac::WasLaunchedAsLoginItemRestoreState();
|
||||||
dict.Set("restoreState", base::mac::WasLaunchedAsLoginItemRestoreState());
|
settings.opened_at_login = base::mac::WasLaunchedAsLoginOrResumeItem();
|
||||||
dict.Set("openedAtLogin", base::mac::WasLaunchedAsLoginOrResumeItem());
|
settings.opened_as_hidden = base::mac::WasLaunchedAsHiddenLoginItem();
|
||||||
dict.Set("openedAsHidden", base::mac::WasLaunchedAsHiddenLoginItem());
|
return settings;
|
||||||
|
|
||||||
return dict.GetHandle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetAsLoginItem(mate::Arguments* args) {
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||||
bool hidden = false;
|
if (settings.open_at_login) {
|
||||||
args->GetNext(&hidden);
|
base::mac::AddToLoginItems(settings.open_as_hidden);
|
||||||
base::mac::AddToLoginItems(hidden);
|
} else {
|
||||||
}
|
base::mac::RemoveFromLoginItems();
|
||||||
|
}
|
||||||
void Browser::RemoveAsLoginItem() {
|
|
||||||
base::mac::RemoveFromLoginItems();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Browser::GetExecutableFileVersion() const {
|
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
|
if (process.platform !== 'darwin') return
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
assert.equal(app.getLoginItemStatus().openedAtLogin, false)
|
app.setLoginItemSettings({openAtLogin: false})
|
||||||
assert.equal(app.getLoginItemStatus().openedAsHidden, false)
|
|
||||||
assert.equal(app.getLoginItemStatus().restoreState, false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
app.removeAsLoginItem()
|
app.setLoginItemSettings({openAtLogin: false})
|
||||||
assert.equal(app.getLoginItemStatus().openAtLogin, false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns the login item status of the app', function () {
|
it('returns the login item status of the app', function () {
|
||||||
app.setAsLoginItem(true)
|
app.setLoginItemSettings({openAtLogin: true})
|
||||||
assert.equal(app.getLoginItemStatus().openAtLogin, true)
|
assert.deepEqual(app.getLoginItemSettings(), {
|
||||||
assert.equal(app.getLoginItemStatus().openAsHidden, true)
|
openAtLogin: true,
|
||||||
|
openAsHidden: false,
|
||||||
|
openedAtLogin: false,
|
||||||
|
openedAsHidden: false,
|
||||||
|
restoreState: false
|
||||||
|
})
|
||||||
|
|
||||||
app.setAsLoginItem(false)
|
app.setLoginItemSettings({openAtLogin: true, openAsHidden: true})
|
||||||
assert.equal(app.getLoginItemStatus().openAtLogin, true)
|
assert.deepEqual(app.getLoginItemSettings(), {
|
||||||
assert.equal(app.getLoginItemStatus().openAsHidden, false)
|
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…
Add table
Add a link
Reference in a new issue