From 52de9fe200eb7290eed02563210d7b83e6727e4c Mon Sep 17 00:00:00 2001 From: George Waters Date: Thu, 5 Mar 2026 21:14:11 -0500 Subject: [PATCH] Improve macOS notifications I'm not sure why did the sleep and remove notifications thing. So this removes that. I also figured out why only the last notification showed in the notification center, gotta not use the same identifier...duh. --- .../core/notifications/__init__.py | 2 +- .../Drive Backup Notifications/Notify.swift | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/drive_backup/core/notifications/__init__.py b/src/drive_backup/core/notifications/__init__.py index 10785db4..11c7b56b 100644 --- a/src/drive_backup/core/notifications/__init__.py +++ b/src/drive_backup/core/notifications/__init__.py @@ -14,7 +14,7 @@ def show_notification(title, body, image=None): subprocess.Popen([win_drive_notification, "--title", title, "--body", body, "--image", image]) elif platform.system() == "Darwin": mac_drive_notification = notification_dir / "mac" / "build" / "Drive Backup Notifications.app" / "Contents" / "MacOS" / "Drive Backup Notifications" - subprocess.Popen([mac_drive_notification, "--title", title, "--body", body]) + subprocess.Popen([mac_drive_notification, "--title", title, "--body", body, "--show"]) except FileNotFoundError: logger = logging.getLogger(__name__) logger.info("Notification executable not found, unable to show notification.") diff --git a/src/drive_backup/core/notifications/mac/Drive Backup Notifications/Drive Backup Notifications/Notify.swift b/src/drive_backup/core/notifications/mac/Drive Backup Notifications/Drive Backup Notifications/Notify.swift index ffe72a2e..52b31db0 100644 --- a/src/drive_backup/core/notifications/mac/Drive Backup Notifications/Drive Backup Notifications/Notify.swift +++ b/src/drive_backup/core/notifications/mac/Drive Backup Notifications/Drive Backup Notifications/Notify.swift @@ -13,6 +13,12 @@ struct Notify: AsyncParsableCommand { @Flag(name: .shortAndLong, help: "Request authorization to allow notifications and exit.") var authorization = false + @Flag(name: .shortAndLong, help: "Show the notification.") + var show = false + + @Flag(name: .shortAndLong, help: "Print out the notification.") + var verbose = false + @Option(name: .shortAndLong, help: "The title to use for the notification.") var title = "Drive Backup Notifications" @@ -47,12 +53,16 @@ struct Notify: AsyncParsableCommand { content.body = self.body content.sound = UNNotificationSound.default - let request = UNNotificationRequest(identifier: "com.geoh2os8295.Drive-Backup-Notifications", content: content, trigger: nil) - - try? await center.add(request) + if self.verbose { + print("Drive Backup Notification:\n\n\(self.title)\n\(self.body)\n") + } - try? await Task.sleep(nanoseconds: 15_000_000_000) + let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) - center.removeAllDeliveredNotifications() + if self.show { + try? await center.add(request) + }else if self.verbose { + print("Not showing notification (--show not present).") + } } }