diff --git a/VoiceInk/Notifications/AppNotificationView.swift b/VoiceInk/Notifications/AppNotificationView.swift index 2459973..e2daad8 100644 --- a/VoiceInk/Notifications/AppNotificationView.swift +++ b/VoiceInk/Notifications/AppNotificationView.swift @@ -90,7 +90,7 @@ struct AppNotificationView: View { GeometryReader { geometry in Rectangle() .fill(Color.accentColor.opacity(0.6)) - .frame(width: geometry.size.width * progress, height: 2) + .frame(width: geometry.size.width * max(0, progress), height: 2) .animation(.linear(duration: 0.1), value: progress) } .frame(height: 2) @@ -118,9 +118,10 @@ struct AppNotificationView: View { timer = Timer.scheduledTimer(withTimeInterval: updateInterval, repeats: true) { _ in if progress > 0 { - progress -= stepDecrement + progress = max(0, progress - stepDecrement) } else { timer?.invalidate() + timer = nil } } } diff --git a/VoiceInk/Notifications/NotificationManager.swift b/VoiceInk/Notifications/NotificationManager.swift index fa26562..e1fa493 100644 --- a/VoiceInk/Notifications/NotificationManager.swift +++ b/VoiceInk/Notifications/NotificationManager.swift @@ -19,11 +19,17 @@ class NotificationManager { ) { dismissTimer?.invalidate() dismissTimer = nil - + if let existingWindow = notificationWindow { existingWindow.close() notificationWindow = nil } + + // Play esc sound for error notifications + if type == .error { + SoundManager.shared.playEscSound() + } + let notificationView = AppNotificationView( title: title, message: message, @@ -65,7 +71,7 @@ class NotificationManager { panel.animator().alphaValue = 1 }) - dismissTimer?.invalidate() + // Schedule a new timer to dismiss the new notification. dismissTimer = Timer.scheduledTimer( withTimeInterval: duration, repeats: false @@ -90,6 +96,8 @@ class NotificationManager { func dismissNotification() { guard let window = notificationWindow else { return } + notificationWindow = nil + dismissTimer?.invalidate() dismissTimer = nil @@ -99,7 +107,7 @@ class NotificationManager { window.animator().alphaValue = 0 }, completionHandler: { window.close() - self.notificationWindow = nil + }) } } \ No newline at end of file