Emit 'finish-launching' event when the application has finished launching.
This commit is contained in:
parent
7dd48e24d3
commit
4133fc28d9
10 changed files with 28 additions and 10 deletions
|
@ -36,6 +36,10 @@ void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
||||||
*prevent_default = Emit("open-file", &args);
|
*prevent_default = Emit("open-file", &args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::OnFinishLaunching() {
|
||||||
|
Emit("finish-launching");
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
|
v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
|
@ -28,6 +28,7 @@ class App : public EventEmitter,
|
||||||
virtual void OnWindowAllClosed() OVERRIDE;
|
virtual void OnWindowAllClosed() OVERRIDE;
|
||||||
virtual void OnOpenFile(bool* prevent_default,
|
virtual void OnOpenFile(bool* prevent_default,
|
||||||
const std::string& file_path) OVERRIDE;
|
const std::string& file_path) OVERRIDE;
|
||||||
|
virtual void OnFinishLaunching() OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
||||||
|
|
|
@ -4,21 +4,27 @@
|
||||||
|
|
||||||
#import "browser/atom_application_delegate_mac.h"
|
#import "browser/atom_application_delegate_mac.h"
|
||||||
|
|
||||||
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#import "browser/atom_application_mac.h"
|
#import "browser/atom_application_mac.h"
|
||||||
|
#include "browser/browser.h"
|
||||||
|
|
||||||
@implementation AtomApplicationDelegate
|
@implementation AtomApplicationDelegate
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification*)notify {
|
- (void)applicationDidFinishLaunching:(NSNotification*)notify {
|
||||||
|
// Trap the quit message to handleQuitEvent.
|
||||||
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
|
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
|
||||||
[em setEventHandler:self
|
[em setEventHandler:self
|
||||||
andSelector:@selector(handleQuitEvent:withReplyEvent:)
|
andSelector:@selector(handleQuitEvent:withReplyEvent:)
|
||||||
forEventClass:kCoreEventClass
|
forEventClass:kCoreEventClass
|
||||||
andEventID:kAEQuitApplication];
|
andEventID:kAEQuitApplication];
|
||||||
|
|
||||||
|
atom::Browser::Get()->DidFinishLaunching();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication*)sender
|
- (BOOL)application:(NSApplication*)sender
|
||||||
openFile:(NSString*)filename {
|
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
|
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
// CrAppControlProtocol:
|
// CrAppControlProtocol:
|
||||||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
||||||
|
|
||||||
- (BOOL)openFile:(NSString*)file;
|
|
||||||
|
|
||||||
- (IBAction)closeAllWindows:(id)sender;
|
- (IBAction)closeAllWindows:(id)sender;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#import "browser/atom_application_mac.h"
|
#import "browser/atom_application_mac.h"
|
||||||
|
|
||||||
#include "base/auto_reset.h"
|
#include "base/auto_reset.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
|
||||||
#include "browser/browser.h"
|
#include "browser/browser.h"
|
||||||
|
|
||||||
@implementation AtomApplication
|
@implementation AtomApplication
|
||||||
|
@ -27,11 +26,6 @@
|
||||||
handlingSendEvent_ = handlingSendEvent;
|
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 {
|
- (IBAction)closeAllWindows:(id)sender {
|
||||||
atom::Browser::Get()->Quit();
|
atom::Browser::Get()->Quit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
node_bindings_->RunMessageLoop();
|
node_bindings_->RunMessageLoop();
|
||||||
|
|
||||||
|
#if !defined(OS_MACOSX)
|
||||||
|
// The corresponding call in OS X is in AtomApplicationDelegate.
|
||||||
|
Browser::Get()->DidFinishLaunching();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -26,7 +26,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserMainParts::PostDestroyThreads() {
|
void AtomBrowserMainParts::PostDestroyThreads() {
|
||||||
[[[AtomApplication sharedApplication] delegate] release];
|
[[AtomApplication sharedApplication] setDelegate:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -41,6 +41,10 @@ bool Browser::OpenFile(const std::string& file_path) {
|
||||||
return prevent_default;
|
return prevent_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Browser::DidFinishLaunching() {
|
||||||
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
|
||||||
|
}
|
||||||
|
|
||||||
void Browser::NotifyAndTerminate() {
|
void Browser::NotifyAndTerminate() {
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
|
||||||
|
|
|
@ -30,6 +30,9 @@ class Browser : public WindowListObserver {
|
||||||
// Tell the application to open a file.
|
// Tell the application to open a file.
|
||||||
bool OpenFile(const std::string& file_path);
|
bool OpenFile(const std::string& file_path);
|
||||||
|
|
||||||
|
// Tell the application the loading has been done.
|
||||||
|
void DidFinishLaunching();
|
||||||
|
|
||||||
void AddObserver(BrowserObserver* obs) {
|
void AddObserver(BrowserObserver* obs) {
|
||||||
observers_.AddObserver(obs);
|
observers_.AddObserver(obs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ class BrowserObserver {
|
||||||
virtual void OnOpenFile(bool* prevent_default,
|
virtual void OnOpenFile(bool* prevent_default,
|
||||||
const std::string& file_path) {}
|
const std::string& file_path) {}
|
||||||
|
|
||||||
|
// The browser has finished loading.
|
||||||
|
virtual void OnFinishLaunching() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~BrowserObserver() {}
|
virtual ~BrowserObserver() {}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue