feat: adjusted battery notifications

This commit is contained in:
Serhiy Mytrovtsiy
2023-12-20 13:37:06 +01:00
parent cedb16e2d6
commit 119bc5b067
2 changed files with 16 additions and 2 deletions

View File

@@ -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

View File

@@ -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 {