Skip to content

Commit

Permalink
wolfram loads faster
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 10, 2014
1 parent 61d347a commit 8c9a270
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14B17" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="6250"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SPPreviewController">
Expand All @@ -16,31 +15,16 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<webView translatesAutoresizingMaskIntoConstraints="NO" id="HDd-zA-9Ah">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12" plugInsEnabled="NO" javaEnabled="NO">
<nil key="identifier"/>
</webPreferences>
<connections>
<outlet property="frameLoadDelegate" destination="c22-O7-iKe" id="9DR-0q-C2C"/>
<outlet property="policyDelegate" destination="c22-O7-iKe" id="MUe-90-c4f"/>
</connections>
</webView>
<progressIndicator horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="4Wr-Z3-AVi">
<rect key="frame" x="444" y="20" width="16" height="16"/>
</progressIndicator>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="HDd-zA-9Ah" secondAttribute="trailing" id="AKE-A3-HIB"/>
<constraint firstAttribute="trailing" secondItem="4Wr-Z3-AVi" secondAttribute="trailing" constant="20" id="euj-QZ-QgC"/>
<constraint firstItem="HDd-zA-9Ah" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="ltS-69-uGQ"/>
<constraint firstAttribute="bottom" secondItem="HDd-zA-9Ah" secondAttribute="bottom" id="oHv-bK-AJC"/>
<constraint firstItem="HDd-zA-9Ah" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="tmk-OL-jcm"/>
<constraint firstAttribute="bottom" secondItem="4Wr-Z3-AVi" secondAttribute="bottom" constant="20" id="tvN-q2-YbJ"/>
</constraints>
<connections>
<outlet property="loader" destination="4Wr-Z3-AVi" id="xwL-z2-Fp4"/>
<outlet property="webView" destination="HDd-zA-9Ah" id="IKi-gO-fHb"/>
</connections>
</customView>
<userDefaultsController representsSharedInstance="YES" id="xiP-DD-W1h"/>
Expand Down
16 changes: 3 additions & 13 deletions FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "SPPreviewController.h"
#import <WebKit/WebKit.h>
#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]]) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
//

#import <WebKit/WebKit.h>
#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
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,75 @@
//

#import "_SS_InlineWebViewContainer.h"
#import <objc/runtime.h>
#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<WebPolicyDecisionListener>)listener {
NSLog(@"POLICY");
[listener use];
}

- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)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<WebPolicyDecisionListener>)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<WebPolicyDecisionListener>)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
2 changes: 1 addition & 1 deletion PluginDirectory/wolfram-alpha.bundle/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def results(parsed, original_query):
<script>
setTimeout(function() {
window.location = %s;
}, 150); // throttle a little
}, 500); // throttle a little
</script>
""" % (json.dumps(url))
return {
Expand Down
Binary file modified PluginDirectory/wolfram-alpha.bundle/plugin.pyc
Binary file not shown.
Binary file modified PluginDirectory/wolfram-alpha.zip
Binary file not shown.

0 comments on commit 8c9a270

Please sign in to comment.