Permalink
Browse files

Don’t play the happiness chime in the middle of the night when the sc…

…reensaver is on.
  • Loading branch information...
1 parent 5566d23 commit 58b32e3721aef209357be7de2a7948855b9153d7 @nwinter committed Dec 28, 2013
Showing with 24 additions and 4 deletions.
  1. +1 −1 Telepath/TPHUDWindowController.xib
  2. +1 −1 Telepath/TPTrackerGitHub.m
  3. +22 −2 Telepath/TPTrackerHappiness.m
@@ -256,7 +256,7 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
- <button translatesAutoresizingMaskIntoConstraints="NO" id="pVg-TK-Del">
+ <button hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pVg-TK-Del">
<rect key="frame" x="298" y="5" width="18" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="bevel" title="clear" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="GTX-NH-Dn7">
@@ -39,7 +39,7 @@ - (id)init
[[NSNotificationCenter defaultCenter] addObserverForName:TPActivityClearTotals object:nil queue:nil usingBlock:^(NSNotification *note) {
[[NSUserDefaults standardUserDefaults] setObject:@(self.totalCommits) forKey:@"previousGitHubCommits"];
[[NSUserDefaults standardUserDefaults] setObject:@(self.totalAdditions) forKey:@"previousGitHubAdditions"];
- [[NSUserDefaults standardUserDefaults] setObject:@(self.totalDeletions) forKey:@"previousGitHubCDeletions"];
+ [[NSUserDefaults standardUserDefaults] setObject:@(self.totalDeletions) forKey:@"previousGitHubDeletions"];
self.previousCommits = self.totalCommits;
self.previousAdditions = self.totalAdditions;
self.previousDeletions = self.totalDeletions;
@@ -13,6 +13,9 @@ @interface TPTrackerHappiness ()
@property NSTimer *pingTimer;
@property BOOL started;
+/// Whether we've in screensaver (and might not want to play a noise if it's late at night).
+@property BOOL screensaver;
+
@end
@implementation TPTrackerHappiness
@@ -22,6 +25,8 @@ - (id)initWithPingInterval:(NSTimeInterval)pingInterval {
if(self) {
srand48(time(0));
self.pingInterval = pingInterval; // Starts ping.
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(onScreensaverStart:) name:@"com.apple.screensaver.didstart" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(onScreensaverStop:) name:@"com.apple.screensaver.didstop" object:nil];
}
return self;
}
@@ -48,10 +53,25 @@ - (void)stop {
}
- (void)ping:(NSTimer *)timer {
- NSSound *chime = [NSSound soundNamed:@"fez-chime"];
- [chime play];
+ NSDateFormatter *timeOfDay = [[NSDateFormatter alloc] init];
+ [timeOfDay setDateFormat:@"HHmm"];
+ int currentTime = [[timeOfDay stringFromDate:[NSDate date]] intValue];
+ if(!self.screensaver || (830 < currentTime && currentTime < 2300)) {
+ NSSound *chime = [NSSound soundNamed:@"fez-chime"];
+ [chime play];
+ }
[[NSNotificationCenter defaultCenter] postNotificationName:TPActivityHappiness object:self userInfo:@{}];
[self start];
}
+- (void)onScreensaverStart:(NSNotification *)note {
+ NSLog(@"Screensaver Start");
+ self.screensaver = YES;
+}
+
+- (void)onScreensaverStop:(NSNotification *)note {
+ NSLog(@"Screensaver Stop");
+ self.screensaver = NO;
+}
+
@end

0 comments on commit 58b32e3

Please sign in to comment.