Skip to content

Commit

Permalink
add some features to better support web search
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 10, 2014
1 parent 8aff87a commit 668ef45
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions FlashlightApp/EasySIMBL/Flashlight-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.22</string>
<string>0.31</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>5</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@

@interface _SS_InlineWebViewContainer ()

@property (nonatomic) BOOL linksOpenInBrowser;

@end

@implementation _SS_InlineWebViewContainer

#pragma mark Navigation interception

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
NSLog(@"POLICY");
if (self.linksOpenInBrowser && [actionInformation[WebActionNavigationTypeKey] integerValue] == WebNavigationTypeLinkClicked) {
[listener ignore];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSWorkspace sharedWorkspace] openURL:request.URL];
});
}
[listener use];
}

Expand Down Expand Up @@ -59,6 +66,12 @@ - (void)setResult:(SPResult *)result {
[self ensureWebview];
NSString *pluginPath = [[_SS_PluginRunner pathForPlugin:sourcePlugin] stringByAppendingPathComponent:@"index.html"];
[_webView.mainFrame loadHTMLString:json[@"html"] baseURL:[NSURL fileURLWithPath:pluginPath]];
if (json[@"webview_user_agent"]) {
[_webView setCustomUserAgent:json[@"webview_user_agent"]];
}
if ([json[@"webview_links_open_in_browser"] boolValue]) {
self.linksOpenInBrowser = YES;
}
} else {
for (NSView *v in self.subviews) {
v.hidden = YES;
Expand Down
14 changes: 12 additions & 2 deletions PluginDirectory/websearch.bundle/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib
import urllib, json

def results(parsed, original_query):
search_specs = [
Expand All @@ -8,9 +8,19 @@ def results(parsed, original_query):
]
for name, key, url in search_specs:
if key in parsed:
search_url = url + urllib.quote_plus(parsed[key])
return {
"title": "Search {0} for '{1}'".format(name, parsed[key]),
"run_args": [url + urllib.quote_plus(parsed[key])]
"run_args": [search_url],
"html": """
<script>
setTimeout(function() {
window.location = %s
}, 500);
</script>
"""%(json.dumps(search_url)),
"webview_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53",
"webview_links_open_in_browser": True
}

def run(url):
Expand Down
Binary file modified PluginDirectory/websearch.bundle/plugin.pyc
Binary file not shown.
Binary file modified PluginDirectory/websearch.zip
Binary file not shown.

0 comments on commit 668ef45

Please sign in to comment.