]> khamidou — GitHub mirrors - electron.git/commitdiff
Emit 'finish-launching' event when the application has finished launching.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 30 May 2013 11:12:14 +0000 (19:12 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 30 May 2013 11:12:14 +0000 (19:12 +0800)
browser/api/atom_api_app.cc
browser/api/atom_api_app.h
browser/atom_application_delegate_mac.mm
browser/atom_application_mac.h
browser/atom_application_mac.mm
browser/atom_browser_main_parts.cc
browser/atom_browser_main_parts_mac.mm
browser/browser.cc
browser/browser.h
browser/browser_observer.h

index 6770dcc4a5a15021e0c405812d0e43fe2d80291e..81a96a69824837621ff814e650f43868cf3c22be 100644 (file)
@@ -36,6 +36,10 @@ void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
   *prevent_default = Emit("open-file", &args);
 }
 
+void App::OnFinishLaunching() {
+  Emit("finish-launching");
+}
+
 // static
 v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
   v8::HandleScope scope;
index 0ee6d68c4564f06893371984da5999249335c0f0..3c174b465c644fcba2cdaac59b493fe18b2e3f13 100644 (file)
@@ -28,6 +28,7 @@ class App : public EventEmitter,
   virtual void OnWindowAllClosed() OVERRIDE;
   virtual void OnOpenFile(bool* prevent_default,
                           const std::string& file_path) OVERRIDE;
+  virtual void OnFinishLaunching() OVERRIDE;
 
  private:
   static v8::Handle<v8::Value> New(const v8::Arguments &args);
index 2a18400898e0f9d46a8eb1453f7985c21f2b50b6..16b8da72bed5bf54e820ede452894b4632e546db 100644 (file)
@@ -4,21 +4,27 @@
 
 #import "browser/atom_application_delegate_mac.h"
 
+#include "base/strings/sys_string_conversions.h"
 #import "browser/atom_application_mac.h"
+#include "browser/browser.h"
 
 @implementation AtomApplicationDelegate
 
 - (void)applicationDidFinishLaunching:(NSNotification*)notify {
+  // Trap the quit message to handleQuitEvent.
   NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
   [em setEventHandler:self
           andSelector:@selector(handleQuitEvent:withReplyEvent:)
         forEventClass:kCoreEventClass
            andEventID:kAEQuitApplication];
+
+  atom::Browser::Get()->DidFinishLaunching();
 }
 
 - (BOOL)application:(NSApplication*)sender
            openFile:(NSString*)filename {
-  return [[AtomApplication sharedApplication] openFile:filename];
+  std::string filename_str(base::SysNSStringToUTF8(filename));
+  return atom::Browser::Get()->OpenFile(filename_str) ? YES : NO;
 }
 
 - (void)handleQuitEvent:(NSAppleEventDescriptor*)event
index 521ac9ef64f24eb7c190c17bfc55b5371dc094ec..ce57df510cea68140cd9200510c9bcb634421f78 100644 (file)
@@ -18,8 +18,6 @@
 // CrAppControlProtocol:
 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
 
-- (BOOL)openFile:(NSString*)file;
-
 - (IBAction)closeAllWindows:(id)sender;
 
 @end
index 204f8d822e511dce07c1e6be6e2b32c5bd6fae53..3fc91c810245a34d87f1ffd4ea0e40ac7d5fa12d 100644 (file)
@@ -5,7 +5,6 @@
 #import "browser/atom_application_mac.h"
 
 #include "base/auto_reset.h"
-#include "base/strings/sys_string_conversions.h"
 #include "browser/browser.h"
 
 @implementation AtomApplication
   handlingSendEvent_ = handlingSendEvent;
 }
 
-- (BOOL)openFile:(NSString*)filename {
-  std::string filename_str(base::SysNSStringToUTF8(filename));
-  return atom::Browser::Get()->OpenFile(filename_str) ? YES : NO;
-}
-
 - (IBAction)closeAllWindows:(id)sender {
   atom::Browser::Get()->Quit();
 }
index 58d47bc72cf01a0f02ffafaeb4d269734f5eeed8..f2fdfc20773a057160ce07fdad740a9802d86f4f 100644 (file)
@@ -69,6 +69,11 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
   }
 
   node_bindings_->RunMessageLoop();
+
+#if !defined(OS_MACOSX)
+  // The corresponding call in OS X is in AtomApplicationDelegate.
+  Browser::Get()->DidFinishLaunching();
+#endif
 }
 
 }  // namespace atom
index 50eb14cd6d2bf525f896d0357310728c43ea06e9..1d4a1891870e203d1363529e45dfa9316cdd0a29 100644 (file)
@@ -26,7 +26,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
 }
 
 void AtomBrowserMainParts::PostDestroyThreads() {
-  [[[AtomApplication sharedApplication] delegate] release];
+  [[AtomApplication sharedApplication] setDelegate:nil];
 }
 
 }  // namespace atom
index 4df65b07dd3a5285abbf61617aff113ee780a065..e2327effadc2092ef2c662e6343da2520477cc6c 100644 (file)
@@ -41,6 +41,10 @@ bool Browser::OpenFile(const std::string& file_path) {
   return prevent_default;
 }
 
+void Browser::DidFinishLaunching() {
+  FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
+}
+
 void Browser::NotifyAndTerminate() {
   bool prevent_default = false;
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
index f0bc48744eb4b219714b7e2bde0cb49978ea654b..4f766325689fbd7676145cb897220a1c0f9fa592 100644 (file)
@@ -30,6 +30,9 @@ class Browser : public WindowListObserver {
   // Tell the application to open a file.
   bool OpenFile(const std::string& file_path);
 
+  // Tell the application the loading has been done.
+  void DidFinishLaunching();
+
   void AddObserver(BrowserObserver* obs) {
     observers_.AddObserver(obs);
   }
index 49c3ea8f6e1a84d00cf5375bd7e14b7fdea1a656..690d5463bbbf4edd2092750d577d9b5d503d7ddc 100644 (file)
@@ -23,6 +23,9 @@ class BrowserObserver {
   virtual void OnOpenFile(bool* prevent_default,
                           const std::string& file_path) {}
 
+  // The browser has finished loading.
+  virtual void OnFinishLaunching() {}
+
  protected:
   virtual ~BrowserObserver() {}
 };