small fixes in widgets for laptops;

This commit is contained in:
Serhiy Mytrovtsiy
2020-01-20 10:50:08 +01:00
parent 3bd9974ad9
commit 9f487e6964
8 changed files with 27 additions and 30 deletions

View File

@@ -53,7 +53,7 @@ class MenuBar {
self.menuBarButton.addSubview(stackView)
if self.stackView.subviews.count == 0 {
if self.stackView.subviews.count == 0 || WIDTH == 0 {
self.menuBarButton.image = NSImage(named:NSImage.Name("tray_icon"))
self.stackView.frame.size.width = widgetSize.width
self.menuBarItem.length = widgetSize.width

View File

@@ -11,7 +11,7 @@ import IOKit.ps
class Battery: Module {
public var name: String = "Battery"
public var updateInterval: Double = 1
public var updateInterval: Double = 15
public var enabled: Bool = true
public var available: Bool {

View File

@@ -103,9 +103,9 @@ extension Module {
widget.name = self.name
widget.start()
// self.readers.forEach { reader in
// reader.read()
// }
self.readers.forEach { reader in
reader.read()
}
self.widget.view = widget as! NSView
}

View File

@@ -40,7 +40,7 @@ class MainViewController: NSViewController {
}
override func viewWillAppear() {
if self.segmentsControl == nil { return }
if self.segmentsControl == nil || self.segmentsControl.selectedSegment == -1 { return }
menuBar?.modules[self.segmentsControl.selectedSegment].popup.setActive(true)
DispatchQueue.global(qos: .background).async {
@@ -55,7 +55,7 @@ class MainViewController: NSViewController {
}
override func viewWillDisappear() {
if self.segmentsControl == nil { return }
if self.segmentsControl == nil || self.segmentsControl.selectedSegment == -1 { return }
menuBar?.modules[self.segmentsControl.selectedSegment].popup.setActive(false)
DispatchQueue.global(qos: .background).async {

View File

@@ -11,11 +11,13 @@ import Cocoa
class BatteryTimeWidget: BatteryWidget {
private var timeValue: NSTextField = NSTextField()
private let timeWidth: CGFloat = 62
private let timeHourWidth: CGFloat = 42
override init(frame: NSRect) {
super.init(frame: CGRect(x: 0, y: 0, width: widgetSize.width, height: widgetSize.height))
self.drawTime()
self.changeWidth(width: self.timeWidth)
self.update()
}
required init?(coder decoder: NSCoder) {
@@ -23,7 +25,7 @@ class BatteryTimeWidget: BatteryWidget {
}
private func drawTime() {
self.timeValue = NSTextField(frame: NSMakeRect(0, 0, timeWidth, self.frame.size.height - 4))
self.timeValue = NSTextField(frame: NSMakeRect(0, 0, timeHourWidth, self.frame.size.height - 4))
timeValue.isEditable = false
timeValue.isSelectable = false
timeValue.isBezeled = false
@@ -34,7 +36,7 @@ class BatteryTimeWidget: BatteryWidget {
timeValue.alignment = .right
timeValue.font = NSFont.systemFont(ofSize: 11, weight: .regular)
timeValue.stringValue = (self.time*60).printSecondsToHoursMinutesSeconds()
if self.time == 0 {
if self.time <= 0 {
timeValue.isHidden = true
}
@@ -49,10 +51,15 @@ class BatteryTimeWidget: BatteryWidget {
}
self.timeValue.stringValue = (self.time*60).printSecondsToHoursMinutesSeconds()
if self.time == 0 && self.size == self.batterySize + timeWidth {
if self.time <= 0 && self.size == self.batterySize + timeWidth {
self.changeWidth(width: 0)
} else if self.time > 0 && self.size != self.batterySize + timeWidth {
self.timeValue.frame.size.width = 0
} else if self.time <= 59 && self.size != self.batterySize + timeHourWidth {
self.changeWidth(width: timeHourWidth)
self.timeValue.frame.size.width = timeHourWidth
} else if self.time > 59 && self.size != self.batterySize + timeWidth {
self.changeWidth(width: timeWidth)
self.timeValue.frame.size.width = timeWidth
}
}
}

View File

@@ -92,8 +92,7 @@ class BatteryWidget: NSView, Widget {
}
func redraw() {
self.needsDisplay = true
setNeedsDisplay(self.frame)
self.display()
}
func setValue(data: [Double]) {
@@ -112,6 +111,7 @@ class BatteryWidget: NSView, Widget {
if changed {
self.redraw()
self.update()
}
}

View File

@@ -85,8 +85,7 @@ class Mini: NSView, Widget {
func redraw() {
self.valueView.textColor = self.value.usageColor(color: self.color)
self.needsDisplay = true
setNeedsDisplay(self.frame)
self.display()
}
func setValue(data: [Double]) {

View File

@@ -16,10 +16,6 @@ class NetworkDotsTextView: NSView, Widget {
private var download: Int64 = 0
private var upload: Int64 = 0
override var intrinsicContentSize: CGSize {
return CGSize(width: self.frame.size.width, height: self.frame.size.height)
}
var downloadValue: NSTextField = NSTextField()
var uploadValue: NSTextField = NSTextField()
@@ -39,10 +35,10 @@ class NetworkDotsTextView: NSView, Widget {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
let workingHeight: CGFloat = (self.frame.size.height - (widgetSize.margin * 2))
let height: CGFloat = ((workingHeight - widgetSize.margin) / 2) - 1
var uploadCircle = NSBezierPath()
uploadCircle = NSBezierPath(ovalIn: CGRect(x: widgetSize.margin, y: height + (widgetSize.margin * 2) + 1, width: height, height: height))
if self.upload >= 1_024 {
@@ -51,7 +47,7 @@ class NetworkDotsTextView: NSView, Widget {
NSColor.labelColor.setFill()
}
uploadCircle.fill()
var downloadCircle = NSBezierPath()
downloadCircle = NSBezierPath(ovalIn: CGRect(x: widgetSize.margin, y: widgetSize.margin, width: height, height: height))
if self.download >= 1_024 {
@@ -62,10 +58,7 @@ class NetworkDotsTextView: NSView, Widget {
downloadCircle.fill()
}
func redraw() {
self.needsDisplay = true
setNeedsDisplay(self.frame)
}
func redraw() {}
func setValue(data: [Double]) {
let download: Int64 = Int64(data[0])
@@ -79,8 +72,6 @@ class NetworkDotsTextView: NSView, Widget {
self.upload = upload
uploadValue.stringValue = Units(bytes: self.upload).getReadableSpeed()
}
self.redraw()
}
func valueView() {
@@ -94,7 +85,7 @@ class NetworkDotsTextView: NSView, Widget {
downloadValue.canDrawSubviewsIntoLayer = true
downloadValue.alignment = .right
downloadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
downloadValue.stringValue = "0 KB/s"
downloadValue.stringValue = Units(bytes: self.download).getReadableSpeed()
uploadValue = NSTextField(frame: NSMakeRect(widgetSize.margin, self.frame.size.height - 10, self.frame.size.width - widgetSize.margin, 9))
uploadValue.isEditable = false
@@ -106,7 +97,7 @@ class NetworkDotsTextView: NSView, Widget {
uploadValue.canDrawSubviewsIntoLayer = true
uploadValue.alignment = .right
uploadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
uploadValue.stringValue = "0 KB/s"
uploadValue.stringValue = Units(bytes: self.upload).getReadableSpeed()
self.addSubview(downloadValue)
self.addSubview(uploadValue)