From 668ef4526e70715be69be09f705a1103d2f47cf0 Mon Sep 17 00:00:00 2001 From: nate-parrott Date: Mon, 10 Nov 2014 14:36:40 -0500 Subject: [PATCH] add some features to better support web search --- FlashlightApp/EasySIMBL/Flashlight-Info.plist | 4 ++-- .../_SS_InlineWebViewContainer.m | 15 ++++++++++++++- PluginDirectory/websearch.bundle/plugin.py | 14 ++++++++++++-- PluginDirectory/websearch.bundle/plugin.pyc | Bin 1124 -> 1542 bytes PluginDirectory/websearch.zip | Bin 9118 -> 9921 bytes 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/FlashlightApp/EasySIMBL/Flashlight-Info.plist b/FlashlightApp/EasySIMBL/Flashlight-Info.plist index 890c42b2..f5ff728d 100755 --- a/FlashlightApp/EasySIMBL/Flashlight-Info.plist +++ b/FlashlightApp/EasySIMBL/Flashlight-Info.plist @@ -32,11 +32,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.22 + 0.31 CFBundleSignature ???? CFBundleVersion - 3 + 5 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m index 26a72fcb..cef28f25 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m @@ -12,6 +12,8 @@ @interface _SS_InlineWebViewContainer () +@property (nonatomic) BOOL linksOpenInBrowser; + @end @implementation _SS_InlineWebViewContainer @@ -19,7 +21,12 @@ @implementation _SS_InlineWebViewContainer #pragma mark Navigation interception - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)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]; } @@ -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; diff --git a/PluginDirectory/websearch.bundle/plugin.py b/PluginDirectory/websearch.bundle/plugin.py index 3f8ec408..62a87f0f 100644 --- a/PluginDirectory/websearch.bundle/plugin.py +++ b/PluginDirectory/websearch.bundle/plugin.py @@ -1,4 +1,4 @@ -import urllib +import urllib, json def results(parsed, original_query): search_specs = [ @@ -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": """ + + """%(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): diff --git a/PluginDirectory/websearch.bundle/plugin.pyc b/PluginDirectory/websearch.bundle/plugin.pyc index 401a9b516999c03d65a92d8b2a947f7c1d6593c0..cf00ce97ae31a501fec9203d696697b8cb3229ac 100644 GIT binary patch delta 747 zcmYjP?`{%75TCoFP$(#^4b&Qw{bF*M=73Znrqf4IbcH#fg@x6y6EMy*D z4SaykxvW7)15bw!2 z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