]> khamidou — GitHub mirrors - electron.git/commitdiff
Add app.focus API.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 30 May 2013 11:24:47 +0000 (19:24 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 30 May 2013 11:24:47 +0000 (19:24 +0800)
browser/api/atom_api_app.cc
browser/api/atom_api_app.h
browser/browser.h
browser/browser_mac.mm

index 81a96a69824837621ff814e650f43868cf3c22be..ca49b6212a36d157c8cd05d4dced09362e34e3ba 100644 (file)
@@ -79,6 +79,15 @@ v8::Handle<v8::Value> App::Terminate(const v8::Arguments &args) {
   return v8::Undefined();
 }
 
+// static
+v8::Handle<v8::Value> App::Focus(const v8::Arguments &args) {
+  v8::HandleScope scope;
+
+  Browser::Get()->Focus();
+
+  return v8::Undefined();
+}
+
 // static
 v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments &args) {
   v8::HandleScope scope;
@@ -122,6 +131,7 @@ void App::Initialize(v8::Handle<v8::Object> target) {
   NODE_SET_PROTOTYPE_METHOD(t, "quit", Quit);
   NODE_SET_PROTOTYPE_METHOD(t, "exit", Exit);
   NODE_SET_PROTOTYPE_METHOD(t, "terminate", Terminate);
+  NODE_SET_PROTOTYPE_METHOD(t, "focus", Focus);
 
   target->Set(v8::String::NewSymbol("Application"), t->GetFunction());
 
index 3c174b465c644fcba2cdaac59b493fe18b2e3f13..f718b6678b8db64f7cb19ff32538962daa0df1af 100644 (file)
@@ -36,6 +36,7 @@ class App : public EventEmitter,
   static v8::Handle<v8::Value> Quit(const v8::Arguments &args);
   static v8::Handle<v8::Value> Exit(const v8::Arguments &args);
   static v8::Handle<v8::Value> Terminate(const v8::Arguments &args);
+  static v8::Handle<v8::Value> Focus(const v8::Arguments &args);
   static v8::Handle<v8::Value> AppendSwitch(const v8::Arguments &args);
   static v8::Handle<v8::Value> AppendArgument(const v8::Arguments &args);
 
index 4f766325689fbd7676145cb897220a1c0f9fa592..6f700b4b5a8aadbefc6ff7e2ae32685c3da4c4b2 100644 (file)
@@ -27,6 +27,9 @@ class Browser : public WindowListObserver {
   // Quit the application immediately without cleanup work.
   void Terminate();
 
+  // Focus the application.
+  void Focus();
+
   // Tell the application to open a file.
   bool OpenFile(const std::string& file_path);
 
index 6738416425e9caec417ccee51878eaecf14b9b07..f328a17621a74874468dc34077aeb0496ad62db7 100644 (file)
@@ -12,4 +12,8 @@ void Browser::Terminate() {
   [[AtomApplication sharedApplication] terminate:nil];
 }
 
+void Browser::Focus() {
+  [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+}
+
 }  // namespace atom