From 08965cf1e50dc334f80b636385272a2bcc262eaf Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Tue, 16 Jul 2024 15:30:01 -0400 Subject: [PATCH 1/3] GUI: Update activation policy for binary blocks --- Source/gui/SNTBinaryMessageWindowController.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/gui/SNTBinaryMessageWindowController.m b/Source/gui/SNTBinaryMessageWindowController.m index a88b75698..9ece002bf 100644 --- a/Source/gui/SNTBinaryMessageWindowController.m +++ b/Source/gui/SNTBinaryMessageWindowController.m @@ -116,6 +116,18 @@ - (void)loadWindow { } } +- (void)showWindow:(id)sender { + // 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]; +} + - (NSString *)messageHash { return self.event.fileSHA256; } From fdfc3297bb143bbbb86a0cc244c9ea71082d6302 Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Tue, 16 Jul 2024 16:23:53 -0400 Subject: [PATCH 2/3] Change activation policy in notification manager --- Source/gui/SNTBinaryMessageWindowController.m | 12 ------------ Source/gui/SNTDeviceMessageWindowController.m | 9 --------- Source/gui/SNTFileAccessMessageWindowController.m | 9 --------- Source/gui/SNTNotificationManager.m | 4 ++++ 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/Source/gui/SNTBinaryMessageWindowController.m b/Source/gui/SNTBinaryMessageWindowController.m index 9ece002bf..a88b75698 100644 --- a/Source/gui/SNTBinaryMessageWindowController.m +++ b/Source/gui/SNTBinaryMessageWindowController.m @@ -116,18 +116,6 @@ - (void)loadWindow { } } -- (void)showWindow:(id)sender { - // 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]; -} - - (NSString *)messageHash { return self.event.fileSHA256; } 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..5f1b796be 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]; } } @@ -125,6 +127,8 @@ - (void)queueMessage:(SNTMessageWindowController *)pendingMsg { [self.pendingNotifications addObject:pendingMsg]; if (!self.currentWindowController) { + // Add app to Cmd+Tab and Dock. + NSApp.activationPolicy = NSApplicationActivationPolicyRegular; [self showQueuedWindow]; } } From 173f47ccf7fcd5633d6364b538c36a77a257e0fd Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Tue, 16 Jul 2024 21:05:58 -0400 Subject: [PATCH 3/3] Move bulk of queueMessage: onto main queue --- Source/gui/SNTNotificationManager.m | 51 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/Source/gui/SNTNotificationManager.m b/Source/gui/SNTNotificationManager.m index 5f1b796be..017f9ae82 100644 --- a/Source/gui/SNTNotificationManager.m +++ b/Source/gui/SNTNotificationManager.m @@ -103,34 +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) { - // Add app to Cmd+Tab and Dock. - NSApp.activationPolicy = NSApplicationActivationPolicyRegular; - [self showQueuedWindow]; - } + if (!self.currentWindowController) { + // Add app to Cmd+Tab and Dock. + NSApp.activationPolicy = NSApplicationActivationPolicyRegular; + [self showQueuedWindow]; + } + }); } // For blocked execution notifications, post an NSDistributedNotificationCenter