From 5933820ba5d28f5f363e141b7d9fec0c93bbcb34 Mon Sep 17 00:00:00 2001 From: David Estes Date: Wed, 7 Jan 2026 17:12:11 -0800 Subject: [PATCH] Fix duplicate registration --- UTCMenuClock/UTCMenuClockAppDelegate.m | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/UTCMenuClock/UTCMenuClockAppDelegate.m b/UTCMenuClock/UTCMenuClockAppDelegate.m index 1f85578..cd13819 100644 --- a/UTCMenuClock/UTCMenuClockAppDelegate.m +++ b/UTCMenuClock/UTCMenuClockAppDelegate.m @@ -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]; @@ -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; @@ -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 {