Skip to content

Commit 0aa876c

Browse files
committed
Make button and command optional
1 parent 65457b9 commit 0aa876c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

SupportCompanion/Services/NotificationService.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class NotificationService {
3636

3737
func sendNotification(
3838
message: String,
39-
buttonText: String,
40-
command: String,
39+
buttonText: String? = nil,
40+
command: String? = nil,
4141
notificationType: NotificationType
4242
) {
4343
guard appState.preferences.notificationInterval > 0 else {
@@ -47,10 +47,12 @@ class NotificationService {
4747

4848
let imagePath = appState.preferences.notificationImage.isEmpty ? nil : appState.preferences.notificationImage
4949

50-
if let lastDate = AppStorageHelper.shared.getLastNotificationDate(for: notificationType),
51-
Date().timeIntervalSince(lastDate) < TimeInterval(appState.preferences.notificationInterval * 3600) {
52-
Logger.shared.logDebug("Notification interval for \(notificationType) not reached, skipping notification")
53-
return
50+
if notificationType != .generic {
51+
if let lastDate = AppStorageHelper.shared.getLastNotificationDate(for: notificationType),
52+
Date().timeIntervalSince(lastDate) < TimeInterval(appState.preferences.notificationInterval * 3600) {
53+
Logger.shared.logDebug("Notification interval for \(notificationType) not reached, skipping notification")
54+
return
55+
}
5456
}
5557

5658
let content = UNMutableNotificationContent()
@@ -68,15 +70,20 @@ class NotificationService {
6870
Logger.shared.logError("Failed to attach image: \(error.localizedDescription)")
6971
}
7072
}
71-
// Define the notification category and actions
72-
let action = UNNotificationAction(
73-
identifier: "RUN_COMMAND",
74-
title: buttonText,
75-
options: [.foreground]
76-
)
73+
74+
var actions: [UNNotificationAction] = []
75+
if let buttonText = buttonText, let command = command {
76+
let action = UNNotificationAction(
77+
identifier: "RUN_COMMAND",
78+
title: buttonText,
79+
options: [.foreground]
80+
)
81+
actions.append(action)
82+
}
83+
7784
let category = UNNotificationCategory(
7885
identifier: "ACTIONABLE",
79-
actions: [action],
86+
actions: actions,
8087
intentIdentifiers: []
8188
)
8289
UNUserNotificationCenter.current().setNotificationCategories([category])
@@ -137,7 +144,6 @@ class BadgeManager {
137144
private func updateBadge() {
138145
DispatchQueue.main.async {
139146
if self.badgeCount > 0 {
140-
print("Setting badge count to \(self.badgeCount)")
141147
NSApplication.shared.dockTile.showsApplicationBadge = true
142148
NSApplication.shared.dockTile.badgeLabel = nil
143149
NSApplication.shared.dockTile.badgeLabel = String(self.badgeCount)

0 commit comments

Comments
 (0)