v2.0.9 — limit notifications using custom floating window (same style as update notifications)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import SwiftUI
|
||||
import WebKit
|
||||
import Combine
|
||||
import UserNotifications
|
||||
|
||||
@main
|
||||
struct ClaudeCheckerApp: App {
|
||||
@@ -12,7 +11,7 @@ struct ClaudeCheckerApp: App {
|
||||
}
|
||||
|
||||
@MainActor
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
var statusItem: NSStatusItem?
|
||||
var popover: NSPopover?
|
||||
var usageViewModel = UsageViewModel()
|
||||
@@ -24,10 +23,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
|
||||
let center = UNUserNotificationCenter.current()
|
||||
center.delegate = self
|
||||
center.requestAuthorization(options: [.alert, .sound]) { _, _ in }
|
||||
|
||||
// Hidden WKWebView to prime the shared cookie store
|
||||
let config = WKWebViewConfiguration()
|
||||
config.websiteDataStore = WKWebsiteDataStore.default()
|
||||
@@ -85,6 +80,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(forName: .limitWarning, object: nil, queue: .main) { [weak self] note in
|
||||
Task { @MainActor [weak self] in
|
||||
guard let self, let info = note.userInfo,
|
||||
let windowName = info["windowName"] as? String,
|
||||
let percent = info["percent"] as? Int else { return }
|
||||
UpdateNotificationWindowController.showLimitWarning(windowName: windowName, percent: percent, near: self.statusItem)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(forName: .limitReset, object: nil, queue: .main) { [weak self] note in
|
||||
Task { @MainActor [weak self] in
|
||||
guard let self, let windowName = note.userInfo?["windowName"] as? String else { return }
|
||||
UpdateNotificationWindowController.showLimitReset(windowName: windowName, near: self.statusItem)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(forName: .closePopover, object: nil, queue: .main) { [weak self] _ in
|
||||
Task { @MainActor [weak self] in
|
||||
self?.popover?.performClose(nil)
|
||||
@@ -211,9 +222,4 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
refreshTimer?.invalidate()
|
||||
}
|
||||
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
||||
willPresent notification: UNNotification,
|
||||
withCompletionHandler handler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
||||
handler([.banner, .sound])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user