chore: refactor browser IPC into TS and app API into TS (#16921)

* chore: refactor browser IPC into typescript

* chore: refactor app.ts into Typescript

* Refactors app.dock into cpp
* Removes app.launcher which has not existed for 3 years
* Removes 2 deprecated APIs (that have been deprecated for more than one
major)
* Refactors deprecate.ts as well
This commit is contained in:
Samuel Attard 2019-02-14 14:29:20 -08:00 committed by GitHub
parent 4ccd6d5900
commit 5790869a3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 258 additions and 201 deletions

View file

@ -1259,6 +1259,46 @@ bool App::MoveToApplicationsFolder(mate::Arguments* args) {
bool App::IsInApplicationsFolder() {
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
}
int DockBounce(const std::string& type) {
int request_id = -1;
if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_CRITICAL);
else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
return request_id;
}
void DockSetMenu(atom::api::Menu* menu) {
Browser::Get()->DockSetMenu(menu->model());
}
v8::Local<v8::Value> App::GetDockAPI(v8::Isolate* isolate) {
if (dock_.IsEmpty()) {
// Initialize the Dock API, the methods are bound to "dock" which exists
// for the lifetime of "app"
auto browser = base::Unretained(Browser::Get());
mate::Dictionary dock_obj = mate::Dictionary::CreateEmpty(isolate);
dock_obj.SetMethod("bounce", &DockBounce);
dock_obj.SetMethod("cancelBounce",
base::Bind(&Browser::DockCancelBounce, browser));
dock_obj.SetMethod("downloadFinished",
base::Bind(&Browser::DockDownloadFinished, browser));
dock_obj.SetMethod("setBadge",
base::Bind(&Browser::DockSetBadgeText, browser));
dock_obj.SetMethod("getBadge",
base::Bind(&Browser::DockGetBadgeText, browser));
dock_obj.SetMethod("hide", base::Bind(&Browser::DockHide, browser));
dock_obj.SetMethod("show", base::Bind(&Browser::DockShow, browser));
dock_obj.SetMethod("isVisible",
base::Bind(&Browser::DockIsVisible, browser));
dock_obj.SetMethod("setMenu", &DockSetMenu);
dock_obj.SetMethod("setIcon", base::Bind(&Browser::DockSetIcon, browser));
dock_.Reset(isolate, dock_obj.GetHandle());
}
return v8::Local<v8::Value>::New(isolate, dock_);
}
#endif
// static
@ -1357,6 +1397,9 @@ void App::BuildPrototype(v8::Isolate* isolate,
#if defined(MAS_BUILD)
.SetMethod("startAccessingSecurityScopedResource",
&App::StartAccessingSecurityScopedResource)
#endif
#if defined(OS_MACOSX)
.SetProperty("dock", &App::GetDockAPI)
#endif
.SetMethod("enableSandbox", &App::EnableSandbox);
}
@ -1367,21 +1410,6 @@ void App::BuildPrototype(v8::Isolate* isolate,
namespace {
#if defined(OS_MACOSX)
int DockBounce(const std::string& type) {
int request_id = -1;
if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_CRITICAL);
else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
return request_id;
}
void DockSetMenu(atom::api::Menu* menu) {
Browser::Get()->DockSetMenu(menu->model());
}
#endif
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
@ -1392,23 +1420,6 @@ void Initialize(v8::Local<v8::Object> exports,
->GetFunction(context)
.ToLocalChecked());
dict.Set("app", atom::api::App::Create(isolate));
#if defined(OS_MACOSX)
auto browser = base::Unretained(Browser::Get());
dict.SetMethod("dockBounce", &DockBounce);
dict.SetMethod("dockCancelBounce",
base::Bind(&Browser::DockCancelBounce, browser));
dict.SetMethod("dockDownloadFinished",
base::Bind(&Browser::DockDownloadFinished, browser));
dict.SetMethod("dockSetBadgeText",
base::Bind(&Browser::DockSetBadgeText, browser));
dict.SetMethod("dockGetBadgeText",
base::Bind(&Browser::DockGetBadgeText, browser));
dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser));
dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser));
dict.SetMethod("dockIsVisible", base::Bind(&Browser::DockIsVisible, browser));
dict.SetMethod("dockSetMenu", &DockSetMenu);
dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser));
#endif
}
} // namespace