Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions UTCMenuClock/UTCMenuClockAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,18 @@ - (void)awakeFromNib
[_mainMenu addItem:cp3Item];

[theItem setMenu:_mainMenu];

[self setupWakeNotifications];
[self scheduleTimer];
}

- (void)setupWakeNotifications
{
// https://developer.apple.com/library/archive/qa/qa1340/_index.html
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: nil];
}

- (void)scheduleTimer {
// Invalidate and dealloc old timer
[_timer invalidate];
Expand Down Expand Up @@ -516,9 +524,6 @@ - (void)scheduleTimer {
tolerance = 0.5;
}

// Set up wake notifications to reset the timer after sleep
[self fileNotifications];

NSDate *startDateTime = [[NSCalendar currentCalendar] dateFromComponents:startUnits];
_timer = [[NSTimer alloc] initWithFireDate:startDateTime interval:interval target:self selector:@selector(fireTimer:) userInfo:nil repeats:YES];
_timer.tolerance = tolerance;
Expand All @@ -532,14 +537,6 @@ - (void)receiveWakeNote: (NSNotification*) note
// When the machine wakes from sleep, reset our timer to make sure we're still running on the second/minute
[self scheduleTimer];
}

- (void)fileNotifications
{
// https://developer.apple.com/library/archive/qa/qa1340/_index.html
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: nil];
}

- (void)dealloc
{
Expand Down