mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fixes in battery widget
This commit is contained in:
@@ -10,7 +10,7 @@ import Cocoa
|
||||
|
||||
class Battery: Module {
|
||||
public let name: String = "Battery"
|
||||
public let shortName: String = ""
|
||||
public let shortName: String = "BAT"
|
||||
public var view: NSView = NSView()
|
||||
public var menu: NSMenuItem = NSMenuItem()
|
||||
public var active: Observable<Bool>
|
||||
@@ -53,7 +53,8 @@ class Battery: Module {
|
||||
|
||||
func initWidget() {
|
||||
self.view = BatteryWidget(frame: NSMakeRect(0, 0, widgetSize.width, widgetSize.height))
|
||||
(self.view as! BatteryWidget).setPercentage(value: (self.reader as! BatteryReader).usage.value.ACstatus)
|
||||
(self.view as! BatteryWidget).setCharging(value: (self.reader as! BatteryReader).usage.value.ACstatus)
|
||||
(self.view as! BatteryWidget).setPercentage(value: self.percentageView.value)
|
||||
}
|
||||
|
||||
func initMenu(active: Bool) {
|
||||
|
||||
@@ -42,11 +42,11 @@ class MainViewController: NSViewController {
|
||||
module.active.subscribe(observer: self) { (value, _) in
|
||||
for tab in self.tabView.tabViewItems {
|
||||
self.tabView.removeTabViewItem(tab)
|
||||
self.segmentsControl = NSSegmentedControl(labels: [], trackingMode: NSSegmentedControl.SwitchTracking.selectOne, target: self, action: #selector(self.switchTabs))
|
||||
}
|
||||
for view in self.topStackView.subviews {
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
self.segmentsControl = NSSegmentedControl(labels: [], trackingMode: .selectOne, target: self, action: #selector(self.switchTabs))
|
||||
self.makeHeader()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import Cocoa
|
||||
class BatteryWidget: NSView, Widget {
|
||||
var activeModule: Observable<Bool> = Observable(false)
|
||||
var size: CGFloat = widgetSize.width
|
||||
var name: String = ""
|
||||
var shortName: String = ""
|
||||
var name: String = "Battery"
|
||||
var shortName: String = "BAT"
|
||||
var menus: [NSMenuItem] = []
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
@@ -80,7 +80,11 @@ class BatteryWidget: NSView, Widget {
|
||||
let r: CGFloat = 1.0
|
||||
if self.percentage {
|
||||
w = batteryWidth - (x * 2)
|
||||
x = percentageWidth + x
|
||||
if self.percentage && self.value == 1 {
|
||||
x = percentageWidthFull + x
|
||||
} else {
|
||||
x = percentageWidth + x
|
||||
}
|
||||
}
|
||||
|
||||
let battery = NSBezierPath(roundedRect: NSRect(x: x-1, y: y, width: w-1, height: h), xRadius: r, yRadius: r)
|
||||
@@ -154,20 +158,19 @@ class BatteryWidget: NSView, Widget {
|
||||
if self.value != value {
|
||||
self.value = value
|
||||
|
||||
if self.value == 1 && self.frame.size.width != batteryWidth + percentageWidthFull {
|
||||
self.percentage = false
|
||||
self.percentageView()
|
||||
self.percentage = true
|
||||
self.percentageView()
|
||||
} else if self.value != 1 && self.frame.size.width != batteryWidth + percentageWidth {
|
||||
self.percentage = false
|
||||
self.percentageView()
|
||||
self.percentage = true
|
||||
self.percentageView()
|
||||
}
|
||||
|
||||
if percentage {
|
||||
self.percentageValue.stringValue = "\(Int(self.value * 100))%"
|
||||
if self.value == 1 && self.frame.size.width != batteryWidth + percentageWidthFull {
|
||||
self.percentageValue.removeFromSuperview()
|
||||
self.percentageView()
|
||||
self.redraw()
|
||||
menuBar?.updateWidget(name: self.name)
|
||||
} else if self.value != 1 && self.frame.size.width != batteryWidth + percentageWidth {
|
||||
self.percentageValue.removeFromSuperview()
|
||||
self.percentageView()
|
||||
self.redraw()
|
||||
menuBar?.updateWidget(name: self.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user