feat: added a low power mode colorizing to the Battery widget (#1024)

This commit is contained in:
Serhiy Mytrovtsiy
2022-08-20 13:27:44 +02:00
parent a28a3b8ef6
commit c23375309b
2 changed files with 12 additions and 3 deletions

View File

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

View File

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