diff --git a/Kit/module/notifications.swift b/Kit/module/notifications.swift index 0d9add09..2e174e62 100644 --- a/Kit/module/notifications.swift +++ b/Kit/module/notifications.swift @@ -68,6 +68,14 @@ open class NotificationsWrapper: NSStackView { } } + public func hideNotification(_ rid: String) { + let id = "Stats_\(self.module)_\(rid)" + if self.ids[id] != nil { + removeNotification(id) + self.ids[id] = nil + } + } + private func showNotification(id: String, title: String, subtitle: String? = nil) { let content = UNMutableNotificationContent() content.title = title diff --git a/Modules/Battery/notifications.swift b/Modules/Battery/notifications.swift index b3a27e97..56174a86 100644 --- a/Modules/Battery/notifications.swift +++ b/Modules/Battery/notifications.swift @@ -54,7 +54,10 @@ class Notifications: NotificationsWrapper { } internal func usageCallback(_ value: Battery_Usage) { - if let threshold = Double(self.lowLevel) { + if value.isCharging || !value.isBatteryPowered { + self.hideNotification(self.lowID) + } + if let threshold = Double(self.lowLevel), !value.isCharging { let title = localizedString("Low battery") var subtitle = localizedString("Battery remaining", "\(Int(value.level*100))") if value.timeToEmpty > 0 { @@ -63,7 +66,10 @@ class Notifications: NotificationsWrapper { self.checkDouble(id: self.lowID, value: value.level, threshold: threshold, title: title, subtitle: subtitle, less: true) } - if let threshold = Double(self.highLevel) { + if value.isBatteryPowered { + self.hideNotification(self.highID) + } + if let threshold = Double(self.highLevel), value.isCharging { let title = localizedString("High battery") var subtitle = localizedString("Battery remaining to full charge", "\(Int((1-value.level)*100))") if value.timeToCharge > 0 {