diff --git a/ConfigureSheet.xib b/ConfigureSheet.xib
new file mode 100644
index 0000000..d161447
--- /dev/null
+++ b/ConfigureSheet.xib
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Epoch Flip Clock.xcodeproj/project.pbxproj b/Epoch Flip Clock.xcodeproj/project.pbxproj
index 20b6cdf..52fafa7 100755
--- a/Epoch Flip Clock.xcodeproj/project.pbxproj
+++ b/Epoch Flip Clock.xcodeproj/project.pbxproj
@@ -11,6 +11,9 @@
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A40068218B53129005F43A6 /* WebKit.framework */; };
77996CD91C94B825006B0FF7 /* EpochFlipClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 77996CD81C94B825006B0FF7 /* EpochFlipClock.m */; };
77AD4D2D2041D6A9001100EC /* Webview in Resources */ = {isa = PBXBuildFile; fileRef = 77AD4D2C2041D6A9001100EC /* Webview */; };
+ 77AD4D2F2041DBC6001100EC /* ConfigureSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */; };
+ 77AD4D312041E44A001100EC /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77AD4D302041E44A001100EC /* AppKit.framework */; };
+ 77AD4D332041F756001100EC /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77AD4D322041F756001100EC /* Cocoa.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -21,6 +24,9 @@
77996CD61C94B804006B0FF7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EpochFlipClock.m; sourceTree = SOURCE_ROOT; };
77AD4D2C2041D6A9001100EC /* Webview */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Webview; sourceTree = ""; };
+ 77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfigureSheet.xib; sourceTree = ""; };
+ 77AD4D302041E44A001100EC /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
+ 77AD4D322041F756001100EC /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -28,6 +34,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 77AD4D332041F756001100EC /* Cocoa.framework in Frameworks */,
+ 77AD4D312041E44A001100EC /* AppKit.framework in Frameworks */,
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */,
3A40066E18B53113005F43A6 /* ScreenSaver.framework in Frameworks */,
);
@@ -56,6 +64,8 @@
3A40066A18B53112005F43A6 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 77AD4D322041F756001100EC /* Cocoa.framework */,
+ 77AD4D302041E44A001100EC /* AppKit.framework */,
3A40068218B53129005F43A6 /* WebKit.framework */,
3A40066D18B53113005F43A6 /* ScreenSaver.framework */,
);
@@ -69,6 +79,7 @@
3A95A94B18EA12D30036779C /* EpochFlipClock.h */,
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */,
77996CD61C94B804006B0FF7 /* Info.plist */,
+ 77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */,
);
name = Source;
sourceTree = "";
@@ -142,6 +153,7 @@
buildActionMask = 2147483647;
files = (
77AD4D2D2041D6A9001100EC /* Webview in Resources */,
+ 77AD4D2F2041DBC6001100EC /* ConfigureSheet.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/EpochFlipClock.h b/EpochFlipClock.h
index 0a71357..758510f 100755
--- a/EpochFlipClock.h
+++ b/EpochFlipClock.h
@@ -1,4 +1,8 @@
#import
@interface EpochFlipClock : ScreenSaverView
+{
+ IBOutlet id configSheet;
+ IBOutlet id screenDisplayOption;
+}
@end
diff --git a/EpochFlipClock.m b/EpochFlipClock.m
index 7e08598..e77ea32 100755
--- a/EpochFlipClock.m
+++ b/EpochFlipClock.m
@@ -3,15 +3,53 @@
@implementation EpochFlipClock
+static NSString * const epochFlipClockModule = @"com.epochflipclock";
+
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
if (!(self = [super initWithFrame:frame isPreview:isPreview])) return nil;
-
+
+ // Preference Defaults
+ ScreenSaverDefaults *defaults;
+ defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
+
+ [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"0", @"screenDisplayOption", // Default to show only on primary display
+ nil]];
+
+ // Webview
NSURL* indexHTMLDocumentURL = [NSURL URLWithString:[[[NSURL fileURLWithPath:[[NSBundle bundleForClass:self.class].resourcePath stringByAppendingString:@"/Webview/index.html"] isDirectory:NO] description] stringByAppendingFormat:@"?screensaver=1%@", self.isPreview ? @"&is_preview=1" : @""]];
WebView* webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
webView.drawsBackground = NO; // Avoids a "white flash" just before the index.html file has loaded
[webView.mainFrame loadRequest:[NSURLRequest requestWithURL:indexHTMLDocumentURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]];
- [self addSubview:webView];
+
+ // Show on screens based on preferences
+ NSArray* screens = [NSScreen screens];
+ NSScreen* primaryScreen = [screens objectAtIndex:0];
+
+ switch ([defaults integerForKey:@"screenDisplayOption"]) {
+ // Primary screen (System Preferences > Displays).
+ // The screen the menubar is shown on under 'arrangement'
+ case 0:
+ if ((primaryScreen.frame.origin.x == frame.origin.x) || isPreview) {
+ [self addSubview:webView];
+ }
+ break;
+ // Last Focussed Screen
+ // This _sometimes_ results in nothing being shown when previewing in system prefs.
+ case 1:
+ if (([NSScreen mainScreen].frame.origin.x == frame.origin.x) || isPreview) {
+ [self addSubview:webView];
+ }
+ break;
+ // All Screens
+ case 2:
+ [self addSubview:webView];
+ break;
+ default:
+ [self addSubview:webView];
+ break;
+ }
return self;
}
@@ -19,7 +57,50 @@
#pragma mark - ScreenSaverView
- (void)animateOneFrame { [self stopAnimation]; }
-- (BOOL)hasConfigureSheet { return NO; }
+
+#pragma mark - Config
+// http://cocoadevcentral.com/articles/000088.php
+
+- (BOOL)hasConfigureSheet { return YES; }
+
+- (NSWindow *)configureSheet
+{
+ ScreenSaverDefaults *defaults;
+ defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
+
+ if (!configSheet)
+ {
+ if (![NSBundle loadNibNamed:@"ConfigureSheet" owner:self])
+ {
+ NSLog( @"Failed to load configure sheet." );
+ }
+ }
+
+ [screenDisplayOption selectItemAtIndex:[defaults integerForKey:@"screenDisplayOption"]];
+
+ return configSheet;
+}
+
+- (IBAction)cancelClick:(id)sender
+{
+ [[NSApplication sharedApplication] endSheet:configSheet];
+}
+
+- (IBAction) okClick: (id)sender
+{
+ ScreenSaverDefaults *defaults;
+ defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
+
+ // Update our defaults
+ [defaults setInteger:[screenDisplayOption indexOfSelectedItem]
+ forKey:@"screenDisplayOption"];
+
+ // Save the settings to disk
+ [defaults synchronize];
+
+ // Close the sheet
+ [[NSApplication sharedApplication] endSheet:configSheet];
+}
#pragma mark - WebFrameLoadDelegate