Skip to content

Commit

Permalink
dark mode support for weather plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 12, 2014
1 parent 0a13186 commit ff28be0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 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.41</string>
<string>0.42</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>7</string>
<string>8</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
9 changes: 6 additions & 3 deletions FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ id __SS_SSOpenAPIResult_iconImage(SPResult *self, SEL cmd) {
NSString *sourcePlugin = objc_getAssociatedObject(self, @selector(sourcePluginAssociatedObject));
NSString *iconPath = [[_SS_PluginRunner pathForPlugin:sourcePlugin] stringByAppendingPathComponent:@"icon.png"];
if (![[NSFileManager defaultManager] fileExistsAtPath:iconPath]) {
NSData *infoJsonData = [NSData dataWithContentsOfFile:[[_SS_PluginRunner pathForPlugin:sourcePlugin]]
if (appBundle.infoDictionary[@"IconPath"]) {
iconPath = appBundle.infoDictionary[@"IconPath"];
NSData *infoJsonData = [NSData dataWithContentsOfFile:[[_SS_PluginRunner pathForPlugin:sourcePlugin] stringByAppendingPathComponent:@"info.json"]];
if (infoJsonData) {
NSDictionary *info = [NSJSONSerialization JSONObjectWithData:infoJsonData options:0 error:nil];
if (info[@"iconPath"]) {
iconPath = info[@"iconPath"];
}
}
}
return [[NSImage alloc] initByReferencingFile:iconPath];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ - (void)setResult:(SPResult *)result {
if ([json[@"webview_links_open_in_browser"] boolValue]) {
self.linksOpenInBrowser = YES;
}
if ([json[@"webview_transparent_background"] boolValue]) {
_webView.drawsBackground = NO;
}
} else {
for (NSView *v in self.subviews) {
v.hidden = YES;
Expand All @@ -83,7 +86,6 @@ - (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;
Expand Down
Binary file modified PluginDirectories/1/imdb.zip
Binary file not shown.
7 changes: 6 additions & 1 deletion PluginDirectories/1/weather.bundle/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import sys, urllib, os
import AppKit

def dark_mode():
import Foundation
return Foundation.NSUserDefaults.standardUserDefaults().persistentDomainForName_(Foundation.NSGlobalDomain).objectForKey_("AppleInterfaceStyle") == "Dark"

def use_metric():
return AppKit.NSLocale.currentLocale().objectForKey_(AppKit.NSLocaleUsesMetricSystem)

def results(parsed, original_query):
location = parsed['location']
html = open("weather.html").read().replace("<!--LOCATION-->", location).replace("<!--UNITS-->", "metric" if use_metric() else "imperial")
html = open("weather.html").read().replace("<!--LOCATION-->", location).replace("<!--UNITS-->", "metric" if use_metric() else "imperial").replace("<!--APPEARANCE-->", "dark" if dark_mode() else "light")
return {
"title": '"{0}" weather'.format(location),
"html": html,
"webview_transparent_background": True,
"run_args": location
}

Expand Down
Binary file modified PluginDirectories/1/weather.bundle/plugin.pyc
Binary file not shown.
12 changes: 8 additions & 4 deletions PluginDirectories/1/weather.bundle/weather.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

var locationName = "<!--LOCATION-->";
var units = "<!--UNITS-->";
var appearance = "<!--APPEARANCE-->";

function load() {
var url = "http://api.openweathermap.org/data/2.5/forecast/daily?mode=json&cnt=4&units="+units+"&q=" + encodeURIComponent(locationName);
Expand All @@ -52,7 +53,7 @@

function iconElementForWeatherCode(code, nighttime, size) {
// CLEAR_DAY, CLEAR_NIGHT, PARTLY_CLOUDY, PARTLY_CLOUDY_NIGHT, CLOUDY, RAIN, SLEET
var skycons = new Skycons({color: "black"});
var skycons = new Skycons({color: appearance=='dark' ? 'white' : 'black'});
var hundred = Math.floor(code / 100);
var codes = [
Skycons.CLEAR_DAY,
Expand Down Expand Up @@ -100,6 +101,9 @@
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial;
line-height: 1.2;
}
body.dark {
color: white;
}
body > div {
display: table;
}
Expand Down Expand Up @@ -131,15 +135,15 @@
margin: 5px;
}
.condition {
color: gray;
opacity: 0.6;
}
#location {
font-size: small;
color: gray;
opacity: 0.6;
}
</style>
</head>
<body>
<body class='<!--APPEARANCE-->'>
<div>
<div>
<div id='loading'>
Expand Down
Binary file modified PluginDirectories/1/weather.zip
Binary file not shown.

0 comments on commit ff28be0

Please sign in to comment.