Skip to content

Commit 52de9fe

Browse files
committed
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.
1 parent 277dd0d commit 52de9fe

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

  • src/drive_backup/core/notifications

src/drive_backup/core/notifications/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def show_notification(title, body, image=None):
1414
subprocess.Popen([win_drive_notification, "--title", title, "--body", body, "--image", image])
1515
elif platform.system() == "Darwin":
1616
mac_drive_notification = notification_dir / "mac" / "build" / "Drive Backup Notifications.app" / "Contents" / "MacOS" / "Drive Backup Notifications"
17-
subprocess.Popen([mac_drive_notification, "--title", title, "--body", body])
17+
subprocess.Popen([mac_drive_notification, "--title", title, "--body", body, "--show"])
1818
except FileNotFoundError:
1919
logger = logging.getLogger(__name__)
2020
logger.info("Notification executable not found, unable to show notification.")

src/drive_backup/core/notifications/mac/Drive Backup Notifications/Drive Backup Notifications/Notify.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ struct Notify: AsyncParsableCommand {
1313
@Flag(name: .shortAndLong, help: "Request authorization to allow notifications and exit.")
1414
var authorization = false
1515

16+
@Flag(name: .shortAndLong, help: "Show the notification.")
17+
var show = false
18+
19+
@Flag(name: .shortAndLong, help: "Print out the notification.")
20+
var verbose = false
21+
1622
@Option(name: .shortAndLong, help: "The title to use for the notification.")
1723
var title = "Drive Backup Notifications"
1824

@@ -47,12 +53,16 @@ struct Notify: AsyncParsableCommand {
4753
content.body = self.body
4854
content.sound = UNNotificationSound.default
4955

50-
let request = UNNotificationRequest(identifier: "com.geoh2os8295.Drive-Backup-Notifications", content: content, trigger: nil)
51-
52-
try? await center.add(request)
56+
if self.verbose {
57+
print("Drive Backup Notification:\n\n\(self.title)\n\(self.body)\n")
58+
}
5359

54-
try? await Task.sleep(nanoseconds: 15_000_000_000)
60+
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
5561

56-
center.removeAllDeliveredNotifications()
62+
if self.show {
63+
try? await center.add(request)
64+
}else if self.verbose {
65+
print("Not showing notification (--show not present).")
66+
}
5767
}
5868
}

0 commit comments

Comments
 (0)