From ef2c24b59fced6c3906bf757ad3d20dd3e0f0c7b Mon Sep 17 00:00:00 2001 From: Mudit200408 Date: Fri, 27 Mar 2026 18:32:59 +0530 Subject: [PATCH] feat: Add a notification silence button in menu bar --- airsync-mac/Core/AppState.swift | 19 +++++++++++++++++++ .../Screens/MenubarView/MenubarView.swift | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/airsync-mac/Core/AppState.swift b/airsync-mac/Core/AppState.swift index 7341114..4910a2f 100644 --- a/airsync-mac/Core/AppState.swift +++ b/airsync-mac/Core/AppState.swift @@ -52,6 +52,7 @@ class AppState: ObservableObject { self.alwaysOpenWindow = UserDefaults.standard.bool(forKey: "alwaysOpenWindow") self.notificationSound = UserDefaults.standard.string(forKey: "notificationSound") ?? "default" self.dismissNotif = UserDefaults.standard.bool(forKey: "dismissNotif") + self.silenceAllNotifications = UserDefaults.standard.bool(forKey: "silenceAllNotifications") self.autoAcceptQuickShare = UserDefaults.standard.bool(forKey: "autoAcceptQuickShare") self.quickShareEnabled = UserDefaults.standard.object(forKey: "quickShareEnabled") == nil ? true : UserDefaults.standard.bool(forKey: "quickShareEnabled") @@ -308,6 +309,16 @@ class AppState: ObservableObject { } } + @Published var silenceAllNotifications: Bool { + didSet { + UserDefaults.standard.set(silenceAllNotifications, forKey: "silenceAllNotifications") + if silenceAllNotifications { + UNUserNotificationCenter.current().removeAllDeliveredNotifications() + UNUserNotificationCenter.current().removeAllPendingNotificationRequests() + } + } + } + @Published var callNotificationMode: CallNotificationMode = .popup { didSet { UserDefaults.standard.set(callNotificationMode.rawValue, forKey: "callNotificationMode") @@ -571,6 +582,10 @@ class AppState: ObservableObject { } private func postCallSystemNotification(_ callEvent: CallEvent) { + if silenceAllNotifications { + return + } + let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent() @@ -786,6 +801,10 @@ class AppState: ObservableObject { extraActions: [UNNotificationAction] = [], extraUserInfo: [String: Any] = [:] ) { + if silenceAllNotifications { + return + } + let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent() content.title = "\(appName) - \(title)" diff --git a/airsync-mac/Screens/MenubarView/MenubarView.swift b/airsync-mac/Screens/MenubarView/MenubarView.swift index f3838e8..37673c2 100644 --- a/airsync-mac/Screens/MenubarView/MenubarView.swift +++ b/airsync-mac/Screens/MenubarView/MenubarView.swift @@ -164,6 +164,16 @@ struct MenubarView: View { ) } + GlassButtonView( + label: appState.silenceAllNotifications ? "Disable DND" : "Enable DND", + systemImage: appState.silenceAllNotifications ? "bell.slash.fill" : "bell.badge", + iconOnly: true, + circleSize: toolButtonSize + ) { + appState.silenceAllNotifications.toggle() + } + .help(appState.silenceAllNotifications ? "Do Not Disturb is ON" : "Turn on Do Not Disturb") + GlassButtonView( label: "Quit", systemImage: "power",