Add 'open-url' event for app API. Fixes #36.
This commit is contained in:
parent
ce569ebf78
commit
23dd5b4da8
7 changed files with 38 additions and 0 deletions
|
@ -36,6 +36,12 @@ void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
|||
*prevent_default = Emit("open-file", &args);
|
||||
}
|
||||
|
||||
void App::OnOpenURL(const std::string& url) {
|
||||
base::ListValue args;
|
||||
args.AppendString(url);
|
||||
Emit("open-url", &args);
|
||||
}
|
||||
|
||||
void App::OnWillFinishLaunching() {
|
||||
Emit("will-finish-launching");
|
||||
}
|
||||
|
|
|
@ -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 OnOpenURL(const std::string& url) OVERRIDE;
|
||||
virtual void OnWillFinishLaunching() OVERRIDE;
|
||||
virtual void OnFinishLaunching() OVERRIDE;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#import "browser/atom_application_mac.h"
|
||||
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "browser/browser.h"
|
||||
|
||||
@implementation AtomApplication
|
||||
|
@ -26,8 +27,23 @@
|
|||
handlingSendEvent_ = handlingSendEvent;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[[NSAppleEventManager sharedAppleEventManager]
|
||||
setEventHandler:self
|
||||
andSelector:@selector(handleURLEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass
|
||||
andEventID:kAEGetURL];
|
||||
}
|
||||
|
||||
- (IBAction)closeAllWindows:(id)sender {
|
||||
atom::Browser::Get()->Quit();
|
||||
}
|
||||
|
||||
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
|
||||
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
|
||||
NSString* url = [
|
||||
[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
||||
atom::Browser::Get()->OpenURL(base::SysNSStringToUTF8(url));
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -42,6 +42,10 @@ bool Browser::OpenFile(const std::string& file_path) {
|
|||
return prevent_default;
|
||||
}
|
||||
|
||||
void Browser::OpenURL(const std::string& url) {
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url));
|
||||
}
|
||||
|
||||
void Browser::WillFinishLaunching() {
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ class Browser : public WindowListObserver {
|
|||
// Tell the application to open a file.
|
||||
bool OpenFile(const std::string& file_path);
|
||||
|
||||
// Tell the application to open a url.
|
||||
void OpenURL(const std::string& url);
|
||||
|
||||
// Tell the application the loading has been done.
|
||||
void WillFinishLaunching();
|
||||
void DidFinishLaunching();
|
||||
|
|
|
@ -23,6 +23,9 @@ class BrowserObserver {
|
|||
virtual void OnOpenFile(bool* prevent_default,
|
||||
const std::string& file_path) {}
|
||||
|
||||
// Browser is used to open a url.
|
||||
virtual void OnOpenURL(const std::string& url) {}
|
||||
|
||||
// The browser has finished loading.
|
||||
virtual void OnWillFinishLaunching() {}
|
||||
virtual void OnFinishLaunching() {}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var app = require('app');
|
||||
var dialog = require('dialog');
|
||||
var delegate = require('atom-delegate');
|
||||
var ipc = require('ipc');
|
||||
var Menu = require('menu');
|
||||
|
@ -13,6 +14,10 @@ app.on('window-all-closed', function() {
|
|||
app.terminate();
|
||||
});
|
||||
|
||||
app.on('open-url', function(event, url) {
|
||||
dialog.showMessageBox({message: url, buttons: ['OK']});
|
||||
});
|
||||
|
||||
delegate.browserMainParts.preMainMessageLoopRun = function() {
|
||||
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue