Fix notification dismissal and progress bar
This commit is contained in:
parent
96a3f35680
commit
3bd3b7b35a
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user