mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: adjusted battery notifications
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user