Permalink
Browse files

Add auto-refresh and userscript options

  • Loading branch information...
tlrobinson committed Mar 5, 2013
1 parent cc5d7c7 commit 4b6ae085fceed8ffa553d805c47857d526c33d3d
Showing with 725 additions and 202 deletions.
  1. +598 −29 ConfigureSheet.nib/designable.nib
  2. BIN ConfigureSheet.nib/keyedobjects.nib
  3. +1 −1 Info.plist
  4. +1 −1 README.md
  5. +7 −11 WebSaver.xcodeproj/project.pbxproj
  6. +13 −2 WebSaverView.h
  7. +105 −18 WebSaverView.m
  8. +0 −140 index.html

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
View
@@ -11,7 +11,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
- <string>com.github.gaohao.WebSaver</string>
+ <string>com.github.tlrobinson.WebSaver</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
View
@@ -32,7 +32,7 @@ Notes
License
-------
-Copyright (c) 2009, Thomas Robinson <http://tlrobinson.net/>
+Copyright (c) 2013, Thomas Robinson <http://tlrobinson.net/>
Copyright (c) 2012, Senseg Ltd <http://www.senseg.com>
All rights reserved.
@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
4D856DCE10845D98006C781A /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D856DCD10845D98006C781A /* WebKit.framework */; };
- 4D856DF31084601E006C781A /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = 4D856DF21084601E006C781A /* index.html */; };
8D255AC70486D3F9007BF209 /* WebSaver_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 32DBCFA80370C50100C91783 /* WebSaver_Prefix.pch */; };
8D255AC80486D3F9007BF209 /* WebSaverView.h in Headers */ = {isa = PBXBuildFile; fileRef = F50079790118B23001CA0E54 /* WebSaverView.h */; };
8D255ACA0486D3F9007BF209 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
@@ -26,9 +25,8 @@
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
32DBCFA80370C50100C91783 /* WebSaver_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSaver_Prefix.pch; sourceTree = "<group>"; };
4D856DCD10845D98006C781A /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
- 4D856DF21084601E006C781A /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
8D255AD20486D3F9007BF209 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
- 8D255AD30486D3F9007BF209 /* GitWeb.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GitWeb.saver; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8D255AD30486D3F9007BF209 /* Web.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Web.saver; sourceTree = BUILT_PRODUCTS_DIR; };
EA4A502A1563C91F005E4CCA /* ConfigureSheet.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = ConfigureSheet.nib; sourceTree = "<group>"; };
F50079790118B23001CA0E54 /* WebSaverView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSaverView.h; sourceTree = "<group>"; };
F500797A0118B23001CA0E54 /* WebSaverView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebSaverView.m; sourceTree = "<group>"; };
@@ -73,7 +71,6 @@
isa = PBXGroup;
children = (
EA4A502A1563C91F005E4CCA /* ConfigureSheet.nib */,
- 4D856DF21084601E006C781A /* index.html */,
8D255AD20486D3F9007BF209 /* Info.plist */,
089C167DFE841241C02AAC07 /* InfoPlist.strings */,
);
@@ -111,7 +108,7 @@
19C28FB8FE9D52D311CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
- 8D255AD30486D3F9007BF209 /* GitWeb.saver */,
+ 8D255AD30486D3F9007BF209 /* Web.saver */,
);
name = Products;
sourceTree = "<group>";
@@ -156,7 +153,7 @@
name = Web;
productInstallPath = "$(HOME)/Library/Screen Savers";
productName = WebSaver;
- productReference = 8D255AD30486D3F9007BF209 /* GitWeb.saver */;
+ productReference = 8D255AD30486D3F9007BF209 /* Web.saver */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
@@ -189,7 +186,6 @@
buildActionMask = 2147483647;
files = (
8D255ACA0486D3F9007BF209 /* InfoPlist.strings in Resources */,
- 4D856DF31084601E006C781A /* index.html in Resources */,
EA4A502B1563C91F005E4CCA /* ConfigureSheet.nib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -240,7 +236,7 @@
GCC_PREFIX_HEADER = WebSaver_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
- PRODUCT_NAME = GitWeb;
+ PRODUCT_NAME = Web;
WRAPPER_EXTENSION = saver;
ZERO_LINK = YES;
};
@@ -256,7 +252,7 @@
GCC_PREFIX_HEADER = WebSaver_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
- PRODUCT_NAME = GitWeb;
+ PRODUCT_NAME = Web;
WRAPPER_EXTENSION = saver;
};
name = Release;
@@ -274,7 +270,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.8;
ONLY_ACTIVE_ARCH = NO;
PUBLIC_HEADERS_FOLDER_PATH = Info.plist;
- SDKROOT = macosx;
+ SDKROOT = macosx10.7;
};
name = Debug;
};
@@ -290,7 +286,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.8;
ONLY_ACTIVE_ARCH = NO;
PUBLIC_HEADERS_FOLDER_PATH = Info.plist;
- SDKROOT = macosx;
+ SDKROOT = macosx10.7;
};
name = Release;
};
View
@@ -4,7 +4,7 @@
//
// Created by Thomas Robinson on 10/13/09.
// Modified by Pekka Nikander in May 2012.
-// Copyright (c) 2009, 280 North. All rights reserved.
+// Copyright (c) 2013, Thomas Robinson. All rights reserved.
// Copyright (c) 2012, Senseg. All rights reserved.
//
@@ -15,8 +15,19 @@
@interface WebSaverView : ScreenSaverView
{
IBOutlet id configSheet;
- IBOutlet id url;
+
+ IBOutlet NSTextField *url;
+ IBOutlet NSTextView *userScript;
+ IBOutlet NSTextField *refreshInterval;
+ IBOutlet NSPopUpButton *refreshUnits;
+
+ ScreenSaverDefaults *defaults;
WebView *webView;
+ NSTimer *refreshTimer;
}
+- (void)loadWebView;
+
+- (IBAction)changeRefreshUnits:(id)sender;
+
@end
View
@@ -4,33 +4,53 @@
//
// Created by Thomas Robinson on 10/13/09.
// Modified by Pekka Nikander in May 2012.
-// Copyright (c) 2009, 280 North. All rights reserved.
+// Copyright (c) 2013, Thomas Robinson. All rights reserved.
// Copyright (c) 2012, Senseg. All rights reserved.
//
#import "WebSaverView.h"
#import <WebKit/WebKit.h>
+#define REFRESH_DISABLED 0
+#define REFRESH_SECONDS 1
+#define REFRESH_MINUTES 2
+#define REFRESH_HOURS 3
+
@implementation WebSaverView
-static NSString * const ModuleName = @"com.github.gaohao.WebSaver";
-static NSString * const DefaultURL = @"https://github.com/gaohao/";
+static NSString * const ModuleName = @"com.github.tlrobinson.WebSaver";
+
+static NSString * const URL_KEY = @"URL";
+static NSString * const USERSCRIPT_KEY = @"UserScript";
+static NSString * const REFRESH_INTERVAL_KEY = @"RefreshInterval";
+static NSString * const REFRESH_UNITS_KEY = @"RefreshUnits";
+
+static NSString * const DEFAULT_URL = @"https://github.com/tlrobinson/WebSaver";
+static NSString * const DEFAULT_USERSCRIPT = @"document.body.style.backgroundColor = 'green';";
+static double const DEFAULT_REFRESH_INTERVAL = 1.0;
+static long const DEFAULT_REFRESH_UNITS = REFRESH_MINUTES;
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
- ScreenSaverDefaults *defaults =
- [ScreenSaverDefaults defaultsForModuleWithName:ModuleName];
+ refreshTimer = nil;
+
+ defaults = [ScreenSaverDefaults defaultsForModuleWithName:ModuleName];
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
- DefaultURL, @"URL",
+ DEFAULT_URL, URL_KEY,
+ DEFAULT_USERSCRIPT, USERSCRIPT_KEY,
+ [NSNumber numberWithDouble:DEFAULT_REFRESH_INTERVAL], REFRESH_INTERVAL_KEY,
+ [NSNumber numberWithLong:DEFAULT_REFRESH_UNITS], REFRESH_UNITS_KEY,
nil]];
webView = [[WebView alloc] initWithFrame:[self bounds] frameName:nil groupName:nil];
- [webView setMainFrameURL: [defaults valueForKey: @"URL"]];
+ [webView setFrameLoadDelegate:self];
[self addSubview:webView];
+
+ [self loadWebView];
}
return self;
}
@@ -40,10 +60,25 @@ - (BOOL)hasConfigureSheet
return YES;
}
-- (NSWindow *)configureSheet
+- (NSString *)url
+{
+ return [defaults valueForKey: URL_KEY];
+}
+- (long)refreshUnits
+{
+ return [(NSNumber *)[defaults valueForKey:REFRESH_UNITS_KEY] longValue];
+}
+- (double)refreshInterval
{
- ScreenSaverDefaults *defaults = [ScreenSaverDefaults defaultsForModuleWithName:ModuleName];
+ return [(NSNumber *)[defaults valueForKey:REFRESH_INTERVAL_KEY] doubleValue];
+}
+- (NSString *)userScript
+{
+ return [defaults valueForKey:USERSCRIPT_KEY];
+}
+- (NSWindow *)configureSheet
+{
if (!configSheet)
{
if (![NSBundle loadNibNamed:@"ConfigureSheet" owner:self])
@@ -53,28 +88,80 @@ - (NSWindow *)configureSheet
}
}
- [url setStringValue: [defaults valueForKey: @"URL"]];
+ [url setStringValue:[self url]];
+ [refreshInterval setDoubleValue:[self refreshInterval]];
+ [refreshUnits selectItemWithTag:[self refreshUnits]];
+ [[userScript textStorage] setAttributedString:[[NSAttributedString alloc] initWithString:[self userScript]]];
+
+ [self updatePanel];
return configSheet;
}
-// Invoked when the user clicks "OK"
-- (IBAction) okClick: (id)sender
+- (void)updatePanel
{
- ScreenSaverDefaults *defaults = [ScreenSaverDefaults defaultsForModuleWithName:ModuleName];
+ [refreshInterval setEnabled:[[refreshUnits selectedItem] tag] > 0];
+}
- NSString *value = [url stringValue];
- [defaults setValue: value forKey: @"URL"];
- [defaults synchronize];
- [webView setMainFrameURL: value];
+- (void)refreshWebView:(NSTimer*)theTimer
+{
+ [webView reload:nil];
+}
- [[NSApplication sharedApplication] endSheet:configSheet];
+- (void)loadWebView
+{
+ [webView setMainFrameURL:[defaults valueForKey:URL_KEY]];
+
+ if (refreshTimer)
+ {
+ [refreshTimer invalidate];
+ [refreshTimer release];
+ refreshTimer = nil;
+ }
+
+ long units = [self refreshUnits];
+ NSTimeInterval interval = 0;
+
+ if (units == REFRESH_SECONDS)
+ interval = [self refreshInterval];
+ else if (units == REFRESH_MINUTES)
+ interval = 60 * [self refreshInterval];
+ else if (units == REFRESH_HOURS)
+ interval = 60 * 60 * [self refreshInterval];
+
+ if (interval > 0)
+ {
+ refreshTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(refreshWebView:) userInfo:nil repeats:YES];
+ }
+}
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+ [sender stringByEvaluatingJavaScriptFromString:[defaults valueForKey:USERSCRIPT_KEY]];
}
+// IBActions
+
+- (IBAction) okClick:(id)sender
+{
+ [defaults setValue:[url stringValue] forKey:URL_KEY];
+ [defaults setValue:[NSNumber numberWithDouble:[refreshInterval doubleValue]] forKey:REFRESH_INTERVAL_KEY];
+ [defaults setValue:[NSNumber numberWithLong:[[refreshUnits selectedItem] tag]] forKey:REFRESH_UNITS_KEY];
+ [defaults setValue:[[userScript textStorage] string] forKey:USERSCRIPT_KEY];
+ [defaults synchronize];
+
+ [[NSApplication sharedApplication] endSheet:configSheet];
+ [self loadWebView];
+}
- (IBAction)cancelClick:(id)sender
{
[[NSApplication sharedApplication] endSheet:configSheet];
}
+- (IBAction)changeRefreshUnits:(id)sender
+{
+ [self updatePanel];
+}
+
@end
Oops, something went wrong.

0 comments on commit 4b6ae08

Please sign in to comment.