diff --git a/Source/gui/SNTDeviceMessageWindowController.m b/Source/gui/SNTDeviceMessageWindowController.m index 3af4cc66a..48a013702 100644 --- a/Source/gui/SNTDeviceMessageWindowController.m +++ b/Source/gui/SNTDeviceMessageWindowController.m @@ -50,18 +50,9 @@ - (void)showWindow:(id)sender { customMsg:self.attributedCustomMessage]; self.window.delegate = self; - // Add app to Cmd+Tab and Dock. - NSApp.activationPolicy = NSApplicationActivationPolicyRegular; - [super showWindow:sender]; } -- (void)windowWillClose:(NSNotification *)notification { - // Remove app from Cmd+Tab and Dock. - NSApp.activationPolicy = NSApplicationActivationPolicyAccessory; - [super windowWillClose:notification]; -} - - (NSAttributedString *)attributedCustomMessage { return [SNTBlockMessage formatMessage:self.customMessage]; } diff --git a/Source/gui/SNTFileAccessMessageWindowController.m b/Source/gui/SNTFileAccessMessageWindowController.m index af55265d3..8230808cc 100644 --- a/Source/gui/SNTFileAccessMessageWindowController.m +++ b/Source/gui/SNTFileAccessMessageWindowController.m @@ -66,18 +66,9 @@ - (void)showWindow:(id)sender { self.window.delegate = self; - // Make sure app doesn't appear in Cmd+Tab or Dock. - NSApp.activationPolicy = NSApplicationActivationPolicyAccessory; - [super showWindow:sender]; } -- (void)windowWillClose:(NSNotification *)notification { - // Remove app from Cmd+Tab and Dock. - NSApp.activationPolicy = NSApplicationActivationPolicyAccessory; - [super windowWillClose:notification]; -} - - (NSAttributedString *)attributedCustomMessage { return [SNTBlockMessage attributedBlockMessageForFileAccessEvent:self.event customMessage:self.customMessage]; diff --git a/Source/gui/SNTNotificationManager.m b/Source/gui/SNTNotificationManager.m index c54052c3b..017f9ae82 100644 --- a/Source/gui/SNTNotificationManager.m +++ b/Source/gui/SNTNotificationManager.m @@ -71,6 +71,8 @@ - (void)windowDidCloseSilenceHash:(NSString *)hash { [bc resume]; [[bc remoteObjectProxy] spindown]; [bc invalidate]; + // Remove app from Cmd+Tab and Dock. + NSApp.activationPolicy = NSApplicationActivationPolicyAccessory; [NSApp hide:self]; } } @@ -101,32 +103,37 @@ - (void)queueMessage:(SNTMessageWindowController *)pendingMsg { // If GUI is in silent mode or if there's already a notification queued for // this message, don't do anything else. if ([SNTConfigurator configurator].enableSilentMode) return; - if ([self notificationAlreadyQueued:pendingMsg]) return; - // See if this message has been user-silenced. - NSString *messageHash = [pendingMsg messageHash]; - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - NSDate *silenceDate = [ud objectForKey:silencedNotificationsKey][messageHash]; - if ([silenceDate isKindOfClass:[NSDate class]]) { - NSDate *oneDayAgo = [NSDate dateWithTimeIntervalSinceNow:-86400]; - if ([silenceDate compare:[NSDate date]] == NSOrderedDescending) { - LOGI(@"Notification silence: date is in the future, ignoring"); - [self updateSilenceDate:nil forHash:messageHash]; - } else if ([silenceDate compare:oneDayAgo] == NSOrderedAscending) { - LOGI(@"Notification silence: date is more than one day ago, ignoring"); - [self updateSilenceDate:nil forHash:messageHash]; - } else { - LOGI(@"Notification silence: dropping notification for %@", messageHash); - return; + dispatch_async(dispatch_get_main_queue(), ^{ + if ([self notificationAlreadyQueued:pendingMsg]) return; + + // See if this message has been user-silenced. + NSString *messageHash = [pendingMsg messageHash]; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NSDate *silenceDate = [ud objectForKey:silencedNotificationsKey][messageHash]; + if ([silenceDate isKindOfClass:[NSDate class]]) { + NSDate *oneDayAgo = [NSDate dateWithTimeIntervalSinceNow:-86400]; + if ([silenceDate compare:[NSDate date]] == NSOrderedDescending) { + LOGI(@"Notification silence: date is in the future, ignoring"); + [self updateSilenceDate:nil forHash:messageHash]; + } else if ([silenceDate compare:oneDayAgo] == NSOrderedAscending) { + LOGI(@"Notification silence: date is more than one day ago, ignoring"); + [self updateSilenceDate:nil forHash:messageHash]; + } else { + LOGI(@"Notification silence: dropping notification for %@", messageHash); + return; + } } - } - pendingMsg.delegate = self; - [self.pendingNotifications addObject:pendingMsg]; + pendingMsg.delegate = self; + [self.pendingNotifications addObject:pendingMsg]; - if (!self.currentWindowController) { - [self showQueuedWindow]; - } + if (!self.currentWindowController) { + // Add app to Cmd+Tab and Dock. + NSApp.activationPolicy = NSApplicationActivationPolicyRegular; + [self showQueuedWindow]; + } + }); } // For blocked execution notifications, post an NSDistributedNotificationCenter