From 5670ee7693dc4f3cb6bb95131752852693b71eec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 5 Dec 2013 10:32:58 +0800 Subject: [PATCH] Add API to get and override application name. --- browser/api/atom_api_app.cc | 24 ++++++++++++++++++++++++ browser/api/atom_api_app.h | 2 ++ browser/browser.cc | 8 ++++++++ browser/browser.h | 7 +++++++ 4 files changed, 41 insertions(+) diff --git a/browser/api/atom_api_app.cc b/browser/api/atom_api_app.cc index 23c84a5b3038..3bb7fd60a53c 100644 --- a/browser/api/atom_api_app.cc +++ b/browser/api/atom_api_app.cc @@ -121,6 +121,28 @@ v8::Handle App::SetVersion(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle App::GetName(const v8::Arguments &args) { + v8::HandleScope scope; + + std::string name(Browser::Get()->GetName()); + + return v8::String::New(name.data(), version.size()); +} + +// static +v8::Handle App::SetName(const v8::Arguments &args) { + v8::HandleScope scope; + + std::string name; + if (!FromV8Arguments(args, &name)) + return node::ThrowError("Bad argument"); + + Browser::Get()->SetName(name); + + return v8::Undefined(); +} + // static v8::Handle App::AppendSwitch(const v8::Arguments &args) { v8::HandleScope scope; @@ -204,6 +226,8 @@ void App::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "focus", Focus); NODE_SET_PROTOTYPE_METHOD(t, "getVersion", GetVersion); NODE_SET_PROTOTYPE_METHOD(t, "setVersion", SetVersion); + NODE_SET_PROTOTYPE_METHOD(t, "getName", GetName); + NODE_SET_PROTOTYPE_METHOD(t, "setName", SetName); target->Set(v8::String::NewSymbol("Application"), t->GetFunction()); diff --git a/browser/api/atom_api_app.h b/browser/api/atom_api_app.h index f5685a77fc55..ab701d9369f3 100644 --- a/browser/api/atom_api_app.h +++ b/browser/api/atom_api_app.h @@ -41,6 +41,8 @@ class App : public EventEmitter, static v8::Handle Focus(const v8::Arguments &args); static v8::Handle GetVersion(const v8::Arguments &args); static v8::Handle SetVersion(const v8::Arguments &args); + static v8::Handle GetName(const v8::Arguments &args); + static v8::Handle SetName(const v8::Arguments &args); static v8::Handle AppendSwitch(const v8::Arguments &args); static v8::Handle AppendArgument(const v8::Arguments &args); diff --git a/browser/browser.cc b/browser/browser.cc index 1bb7e66e3dd8..bb4b27f8f9c2 100644 --- a/browser/browser.cc +++ b/browser/browser.cc @@ -47,6 +47,14 @@ void Browser::SetVersion(const std::string& version) { version_override_ = version; } +std::string Browser::GetName() const { + return name_override_.empty() ? "Atom-Shell" : name_override_; +} + +void Browser::SetName(const std::string& name) { + name_override_ = name; +} + bool Browser::OpenFile(const std::string& file_path) { bool prevent_default = false; FOR_EACH_OBSERVER(BrowserObserver, diff --git a/browser/browser.h b/browser/browser.h index e66076b227c3..0139ee0c64ce 100644 --- a/browser/browser.h +++ b/browser/browser.h @@ -36,6 +36,12 @@ class Browser : public WindowListObserver { // Overrides the application version. void SetVersion(const std::string& version); + // Returns the application's name, default is just Atom-Shell. + std::string GetName() const; + + // Overrides the application name. + void SetName(const std::string& name); + #if defined(OS_MACOSX) // Bounce the dock icon. enum BounceType { @@ -91,6 +97,7 @@ class Browser : public WindowListObserver { ObserverList observers_; std::string version_override_; + std::string name_override_; DISALLOW_COPY_AND_ASSIGN(Browser); };