mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added a low power mode colorizing to the Battery widget (#1024)
This commit is contained in:
@@ -22,6 +22,7 @@ public class BatterykWidget: WidgetWrapper {
|
||||
private var time: Int = 0
|
||||
private var charging: Bool = false
|
||||
private var ACStatus: Bool = false
|
||||
private var lowPowerMode: Bool = false
|
||||
|
||||
public init(title: String, config: NSDictionary?, preview: Bool = false) {
|
||||
let widgetTitle: String = title
|
||||
@@ -152,7 +153,7 @@ public class BatterykWidget: WidgetWrapper {
|
||||
width: innerWidth,
|
||||
height: batterySize.height - offset*2 - borderWidth*2 - 1
|
||||
), xRadius: 1, yRadius: 1)
|
||||
percentage.batteryColor(color: self.colorState).set()
|
||||
percentage.batteryColor(color: self.colorState, lowPowerMode: self.lowPowerMode).set()
|
||||
inner.fill()
|
||||
} else {
|
||||
let attributes = [
|
||||
@@ -292,7 +293,7 @@ public class BatterykWidget: WidgetWrapper {
|
||||
return rowWidth
|
||||
}
|
||||
|
||||
public func setValue(percentage: Double? = nil, ACStatus: Bool? = nil, isCharging: Bool? = nil, time: Int? = nil) {
|
||||
public func setValue(percentage: Double? = nil, ACStatus: Bool? = nil, isCharging: Bool? = nil, lowPowerMode: Bool? = nil, time: Int? = nil) {
|
||||
var updated: Bool = false
|
||||
let timeFormat: String = Store.shared.string(key: "\(self.title)_timeFormat", defaultValue: self.timeFormat)
|
||||
|
||||
@@ -316,6 +317,10 @@ public class BatterykWidget: WidgetWrapper {
|
||||
self.timeFormat = timeFormat
|
||||
updated = true
|
||||
}
|
||||
if let state = lowPowerMode, self.lowPowerMode != state {
|
||||
self.lowPowerMode = state
|
||||
updated = true
|
||||
}
|
||||
|
||||
if updated {
|
||||
DispatchQueue.main.async(execute: {
|
||||
|
||||
@@ -173,7 +173,11 @@ public extension Double {
|
||||
}
|
||||
}
|
||||
|
||||
func batteryColor(color: Bool = false) -> NSColor {
|
||||
func batteryColor(color: Bool = false, lowPowerMode: Bool = false) -> NSColor {
|
||||
if lowPowerMode {
|
||||
return NSColor.systemOrange
|
||||
}
|
||||
|
||||
switch self {
|
||||
case 0.2...0.4:
|
||||
if !color {
|
||||
|
||||
Reference in New Issue
Block a user