зеркало из https://github.com/electron/electron.git
Emit 'finish-launching' event when the application has finished launching.
This commit is contained in:
Родитель
7dd48e24d3
Коммит
4133fc28d9
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
// CrAppControlProtocol:
|
||||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
||||
|
||||
- (BOOL)openFile:(NSString*)file;
|
||||
|
||||
- (IBAction)closeAllWindows:(id)sender;
|
||||
|
||||
@end
|
||||
|
|
|
@ -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
|
||||
|
@ -27,11 +26,6 @@
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,7 +26,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
|||
}
|
||||
|
||||
void AtomBrowserMainParts::PostDestroyThreads() {
|
||||
[[[AtomApplication sharedApplication] delegate] release];
|
||||
[[AtomApplication sharedApplication] setDelegate:nil];
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче