From 90773a8930463c9ecdd9111c4ce1eeccb6bcbc04 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 26 Aug 2011 17:04:17 -0700 Subject: [PATCH] one JSContext to rule them all --- Classes/AtomWindowController.m | 25 ++++++++++++------------- Classes/AtomicityAppDelegate.m | 6 ++---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Classes/AtomWindowController.m b/Classes/AtomWindowController.m index 2efde4a19..c4c865fb8 100644 --- a/Classes/AtomWindowController.m +++ b/Classes/AtomWindowController.m @@ -4,7 +4,7 @@ // // Created by Chris Wanstrath on 8/22/11. // Copyright 2011 GitHub. All rights reserved. -// +//` #import "AtomWindowController.h" @@ -27,24 +27,23 @@ [self setShouldCascadeWindows:YES]; [self setWindowFrameAutosaveName:@"atomWindow"]; - [webView setFrameLoadDelegate:self]; - if (self.URL) { [webView setMainFrameURL:self.URL]; - } else { - NSURL *bundleURL = [[NSBundle mainBundle] resourceURL]; - NSURL *htmlURL = [bundleURL URLByAppendingPathComponent:@"HTML"]; + } + else { + NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; + NSString *bootstrapPath = [resourcePath stringByAppendingString:@"/HTML/lib/bootstrap.js"]; + JSCocoa* jsc = [[JSCocoa alloc] initWithGlobalContext:[[webView mainFrame] globalContext]]; + [jsc setObject:self withName:@"WindowController"]; + [jsc evalJSFile:bootstrapPath]; + + NSURL *resourceURL = [[NSBundle mainBundle] resourceURL]; + NSURL *htmlURL = [resourceURL URLByAppendingPathComponent:@"HTML"]; NSURL *indexURL = [htmlURL URLByAppendingPathComponent:@"index.html"]; NSString *html = [NSString stringWithContentsOfURL:indexURL encoding:NSUTF8StringEncoding error:nil]; - [[webView mainFrame] loadHTMLString:html baseURL:htmlURL]; + [[webView mainFrame] loadHTMLString:html baseURL:htmlURL]; } } -- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - // https://github.com/parmanoir/jscocoa#readme - JSCocoa* jsc = [[JSCocoa alloc] initWithGlobalContext:[frame globalContext]]; - [jsc setObject:self withName:@"WindowController"]; -} - @end diff --git a/Classes/AtomicityAppDelegate.m b/Classes/AtomicityAppDelegate.m index d29712dc5..e5c40100f 100644 --- a/Classes/AtomicityAppDelegate.m +++ b/Classes/AtomicityAppDelegate.m @@ -20,10 +20,8 @@ } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; - NSString *bootstrapPath = [resourcePath stringByAppendingString:@"/HTML/lib/bootstrap.js"]; - JSCocoa* jsc = [[JSCocoa alloc] init]; - [jsc evalJSFile:bootstrapPath]; + id c = [[AtomWindowController alloc] initWithWindowNibName:@"AtomWindow"]; + [c window]; } @end