From 8c9a270c97d8d9f6a7ee938a8c81681c10e67da0 Mon Sep 17 00:00:00 2001 From: nate-parrott Date: Mon, 10 Nov 2014 11:16:20 -0500 Subject: [PATCH] wolfram loads faster --- .../SPOpenAPIPreviewViewController.xib | 16 ---- .../SpotlightSIMBL/SPOpenAPIResult.m | 16 +--- .../_SS_InlineWebViewContainer.h | 5 +- .../_SS_InlineWebViewContainer.m | 88 +++++++++++------- .../wolfram-alpha.bundle/plugin.py | 2 +- .../wolfram-alpha.bundle/plugin.pyc | Bin 1146 -> 1146 bytes PluginDirectory/wolfram-alpha.zip | Bin 74000 -> 74000 bytes 7 files changed, 63 insertions(+), 64 deletions(-) diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib index 9396f161..ff1f702b 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib @@ -2,7 +2,6 @@ - @@ -16,31 +15,16 @@ - - - - - - - - - - - - - - - diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m index 69f0ac99..9b080b82 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m @@ -18,6 +18,7 @@ #import "SPPreviewController.h" #import #import "_SS_PluginRunner.h" +#import "_SS_InlineWebViewContainer.h" id __SS_SSOpenAPIResult_initWithQuery_json_sourcePlugin(SPResult *self, SEL cmd, NSString *query, id json, NSString *sourcePlugin) { if (![json isKindOfClass:[NSDictionary class]]) { @@ -43,20 +44,9 @@ id __SS_SSOpenAPIResult_category(SPResult *self, SEL cmd) { } id __SS_SSOpenAPIResult_customPreviewController(SPResult *self, SEL cmd) { - id json = objc_getAssociatedObject(self, @selector(jsonAssociatedObject)); SPPreviewController *vc = [[NSClassFromString(@"SPPreviewController") alloc] initWithNibName:@"SPOpenAPIPreviewViewController" bundle:[NSBundle bundleWithIdentifier:@"com.nateparrott.SpotlightSIMBL"]]; - WebView *webView = vc.view.subviews.firstObject; - NSString *sourcePlugin = objc_getAssociatedObject(self, @selector(sourcePluginAssociatedObject)); - if ([webView isKindOfClass:[WebView class]]) { - if (json[@"html"]) { - NSString *pluginPath = [[_SS_PluginRunner pathForPlugin:sourcePlugin] stringByAppendingPathComponent:@"index.html"]; - [[webView mainFrame] loadHTMLString:json[@"html"] baseURL:[NSURL fileURLWithPath:pluginPath]]; - } else { - webView.hidden = YES; - } - } else { - // TODO: log it - } + _SS_InlineWebViewContainer *container = (id)vc.view; + container.result = self; vc.internalPreviewResult = self; return vc; } diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h index 5403483a..59deab82 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h @@ -7,10 +7,13 @@ // #import +#import "SPResult.h" @interface _SS_InlineWebViewContainer : NSView @property (nonatomic) IBOutlet NSProgressIndicator *loader; -@property (nonatomic) IBOutlet WebView *webView; +@property (nonatomic) WebView *webView; + +@property (nonatomic) SPResult *result; @end diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m index 89a8f264..26a72fcb 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m @@ -7,53 +7,75 @@ // #import "_SS_InlineWebViewContainer.h" +#import +#import "_SS_PluginRunner.h" + +@interface _SS_InlineWebViewContainer () + +@end @implementation _SS_InlineWebViewContainer -- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - dispatch_async(dispatch_get_main_queue(), ^{ - if (frame == sender.mainFrame) { - [self.loader startAnimation:nil]; - } - }); -} +#pragma mark Navigation interception -- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - dispatch_async(dispatch_get_main_queue(), ^{ - if (frame == sender.mainFrame) { - [self.loader stopAnimation:nil]; - } - }); +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { + NSLog(@"POLICY"); + [listener use]; } -- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id)listener { - NSLog(@"Decide window policy: %@", actionInformation); - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSWorkspace sharedWorkspace] openURL:request.URL]; - }); - [listener ignore]; +#pragma mark Loading indicator +- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { + if (frame == sender.mainFrame) { + [_loader startAnimation:nil]; + } } - -- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id)listener { - NSLog(@"Decide policy: %@", actionInformation); - if ([actionInformation[WebActionNavigationTypeKey] isEqualToString:WebNavigationTypeLinkClicked]) { - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSWorkspace sharedWorkspace] openURL:request.URL]; - }); - [listener ignore]; - } else { - [listener use]; +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { + if (frame == sender.mainFrame) { + [_loader stopAnimation:nil]; } } - -- (void)webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { - [listener use]; +- (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { + if (frame == sender.mainFrame) { + [_loader stopAnimation:nil]; + } } +#pragma mark Lifecycle - (void)dealloc { - self.webView.policyDelegate = nil; self.webView.frameLoadDelegate = nil; + self.webView.policyDelegate = nil; + [self.webView.mainFrame loadHTMLString:@"" baseURL:nil]; [self.webView stopLoading:nil]; } +#pragma mark Result +- (void)setResult:(SPResult *)result { + _result = result; + + id json = objc_getAssociatedObject(result, @selector(jsonAssociatedObject)); + NSString *sourcePlugin = objc_getAssociatedObject(result, @selector(sourcePluginAssociatedObject)); + + if (json[@"html"]) { + [self ensureWebview]; + NSString *pluginPath = [[_SS_PluginRunner pathForPlugin:sourcePlugin] stringByAppendingPathComponent:@"index.html"]; + [_webView.mainFrame loadHTMLString:json[@"html"] baseURL:[NSURL fileURLWithPath:pluginPath]]; + } else { + for (NSView *v in self.subviews) { + v.hidden = YES; + } + } +} + +- (void)ensureWebview { + if (!_webView) { + _webView = [WebView new]; + [self addSubview:_webView positioned:NSWindowBelow relativeTo:_loader]; + // [_webView setCustomUserAgent:@"Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25"]; + _webView.frameLoadDelegate = self; + _webView.policyDelegate = self; + _webView.frame = self.bounds; + _webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + } +} + @end diff --git a/PluginDirectory/wolfram-alpha.bundle/plugin.py b/PluginDirectory/wolfram-alpha.bundle/plugin.py index 6c362648..66156b06 100644 --- a/PluginDirectory/wolfram-alpha.bundle/plugin.py +++ b/PluginDirectory/wolfram-alpha.bundle/plugin.py @@ -6,7 +6,7 @@ def results(parsed, original_query): """ % (json.dumps(url)) return { diff --git a/PluginDirectory/wolfram-alpha.bundle/plugin.pyc b/PluginDirectory/wolfram-alpha.bundle/plugin.pyc index 68627e70a3d63b63140d62fa28fa12e814e6750e..7cccff534ec44bcc62b70935b96c29c0aa0b34cd 100644 GIT binary patch delta 24 fcmeyx@r#3<`74r~m)} diff --git a/PluginDirectory/wolfram-alpha.zip b/PluginDirectory/wolfram-alpha.zip index 517efa84a20bd27a99d72b4d3b33d8b1dd4fc704..f064d5f824c9b128853188e02dfd8082659e458f 100644 GIT binary patch delta 194 zcmbPmh-Jbd7Ty4FW)=|!5I7x~wUO6Wf*D9}_LWFs1T(fsp8mrJ6mi|kIk!2Ok%1wY zaeBWLqxAL_VvOmG98ZBVuQnZ!+%7J`D9FfUYA~HohEa99za*m(Bgb=~q?fgO;`B}_ zMt$bKCkfkkOECt5RBZ>U(qRT!Fx^(3(G$$*lxOq-Gj7N;dVm?q3XEQG8>W{kFuEX& JJgC6v4*)DWJ|+MF delta 194 zcmbPmh-Jbd7Ty4FW)=|!5SX+zbtA8>1T&D{>?@JN2xe@NJpG4n?bcM+t(*_6hTV}hs1fw7$lcDK!J{d;U?f#OCMvNTc+frS1HfB3a z@04QHXI}CyYWr>}#z2s&?LbvJ%peP<+sZR~f*GCij6Pt-4S7ZnW}ubRl@%Dh;5JMz ORbX^M7