Open no longer blocks until page is loaded

This commit is contained in:
Corey Johnson
2012-03-21 11:13:10 -07:00
parent a91c8098a3
commit 7631ae986e
6 changed files with 7 additions and 32 deletions

View File

@@ -12,7 +12,7 @@ class ClientHandler;
CefRefPtr<ClientHandler> _clientHandler;
}
- (AtomController *)open:(NSString *)path;
- (void)open:(NSString *)path;
- (IBAction)runSpecs:(id)sender;
- (IBAction)runBenchmarks:(id)sender;

View File

@@ -60,8 +60,8 @@
CefBrowser::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings);
}
- (AtomController *)open:(NSString *)path {
return [[AtomController alloc] initWithPath:path atomContext:[self atomContext]];
- (void)open:(NSString *)path {
[[AtomController alloc] initWithPath:path atomContext:[self atomContext]];
}
- (IBAction)runSpecs:(id)sender {

View File

@@ -10,8 +10,6 @@ class ClientHandler;
NSString *_bootstrapScript;
NSString *_pathToOpen;
BOOL _loaded;
CefRefPtr<CefV8Context> _atomContext;
CefRefPtr<ClientHandler> _clientHandler;
}
@@ -22,10 +20,8 @@ class ClientHandler;
- (id)initBenchmarksWithAtomContext:(CefRefPtr<CefV8Context>)atomContext;
- (void)createBrowser;
- (void)blockUntilBrowserLoaded;
@property (nonatomic, retain) IBOutlet NSView *webView;
@property (nonatomic, readonly) CefRefPtr<ClientHandler> clientHandler;
@end

View File

@@ -7,7 +7,6 @@
@implementation AtomController
@synthesize webView=_webView;
@synthesize clientHandler=_clientHandler;
- (void)dealloc {
[_bootstrapScript release];
@@ -21,7 +20,6 @@
self = [super initWithWindowNibName:@"ClientWindow"];
_bootstrapScript = [bootstrapScript retain];
_atomContext = atomContext;
_loaded = false;
[self.window makeKeyAndOrderFront:nil];
[self createBrowser];
@@ -62,16 +60,8 @@
CefBrowser::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings);
}
- (void)blockUntilBrowserLoaded {
NSRunLoop *runLoop = [NSRunLoop mainRunLoop];
while (!_loaded) {
[runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0]];
}
}
#pragma mark BrowserDelegate
- (void)loadStart {
_loaded = false;
CefRefPtr<CefV8Context> context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
CefRefPtr<CefV8Value> global = context->GetGlobal();
@@ -91,10 +81,6 @@
context->Exit();
}
- (void)loadEnd {
_loaded = true;
}
- (bool)keyEventOfType:(cef_handler_keyevent_type_t)type
code:(int)code
modifiers:(int)modifiers

View File

@@ -235,11 +235,7 @@ bool NativeHandler::Execute(const CefString& name,
}
else if (name == "open") {
NSString *path = stringFromCefV8Value(arguments[0]);
AtomController *atomController = [(Atom *)NSApp open:path];
[atomController blockUntilBrowserLoaded];
CefRefPtr<ClientHandler> clientHandler = [atomController clientHandler];
retval = clientHandler->GetBrowser()->GetMainFrame()->GetV8Context()->GetGlobal();
[NSApp open:path];
return true;
}

View File

@@ -14,21 +14,18 @@ class Keymap
bindDefaultKeys: ->
@bindKeys "*",
'meta-n': 'new-window'
'meta-o': 'open'
'meta-,': 'open-user-configuration'
'meta-o': 'open'
@_newWindow = => $native.newWindow()
@_openUserConfiguration = => atom.open(atom.userConfigurationPath)
@_open = =>
url = $native.openDialog()
atom.open(url) if url
@_openUserConfiguration = =>
openedWindow = atom.open(atom.userConfigurationPath)
defaultConfiguration = "# This is run when a window is loaded!\nconsole.log('see!')"
openedWindow.rootView.editor.buffer.setText defaultConfiguration unless fs.exists(atom.userConfigurationPath)
$(document).on 'new-window', @_newWindow
$(document).on 'open', @_open
$(document).on 'open-user-configuration', @_openUserConfiguration
$(document).on 'open', @_open
unbindDefaultKeys: ->
$(document).unbind 'new-window', @_newWindow