SPB Git

Repository Public

Notifier.swift 1.0 KB 20 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/Notifier.swift3// Description: System notifications for what deserves attention — a batch of transfers finished, a conflict to settle, a sync error that persists, storage running out, a deposit received — never one per small operation. macOS notification preferences are respected.4import Foundation5import UserNotifications67@MainActor final class Notifier {8    private let center = UNUserNotificationCenter.current()9    private var asked = false10    func requestAuthorization() {11        guard !asked else { return }; asked = true12        center.requestAuthorization(options: [.alert, .sound, .badge]) { _, _ in }13    }14    /// Posts a notification; `id` replaces an earlier one about the same thing instead of piling up.15    func post(id: String, title: String, body: String) {16        let c = UNMutableNotificationContent(); c.title = title; c.body = body17        center.add(UNNotificationRequest(identifier: id, content: c, trigger: nil)) { _ in }18    }19}20
Files main
Menu

Theme