diff --git a/src/drive_backup/core/notifications/__init__.py b/src/drive_backup/core/notifications/__init__.py index 10785db..11c7b56 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 ffe72a2..52b31db 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).") + } } }