Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drive_backup/core/notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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).")
}
}
}