mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: small codebase refactoring (mostly removed unused code and changes in access control)
This commit is contained in:
@@ -13,7 +13,7 @@ import Cocoa
|
||||
import Kit
|
||||
import IOKit.ps
|
||||
|
||||
struct Battery_Usage: value_t, Codable {
|
||||
struct Battery_Usage: Codable {
|
||||
var powerSource: String = ""
|
||||
var state: String? = nil
|
||||
var isCharged: Bool = false
|
||||
@@ -37,12 +37,6 @@ struct Battery_Usage: value_t, Codable {
|
||||
var timeToEmpty: Int = 0
|
||||
var timeToCharge: Int = 0
|
||||
var timeOnACPower: Date? = nil
|
||||
|
||||
public var widgetValue: Double {
|
||||
get {
|
||||
return self.level
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Battery: Module {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Cocoa
|
||||
import Kit
|
||||
|
||||
public struct CPU_Load: value_t, Codable {
|
||||
public struct CPU_Load: Codable {
|
||||
var totalUsage: Double = 0
|
||||
var usagePerCore: [Double] = []
|
||||
var usageECores: Double? = nil
|
||||
@@ -18,12 +18,6 @@ public struct CPU_Load: value_t, Codable {
|
||||
var systemLoad: Double = 0
|
||||
var userLoad: Double = 0
|
||||
var idleLoad: Double = 0
|
||||
|
||||
public var widgetValue: Double {
|
||||
get {
|
||||
return self.totalUsage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct CPU_Limit: Codable {
|
||||
|
||||
@@ -173,14 +173,7 @@ internal class Settings: NSStackView, Settings_v {
|
||||
}
|
||||
|
||||
@objc func toggleUsagePerCore(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.usagePerCoreState = state! == .on ? true : false
|
||||
self.usagePerCoreState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_usagePerCore", value: self.usagePerCoreState)
|
||||
self.callback()
|
||||
|
||||
@@ -205,53 +198,25 @@ internal class Settings: NSStackView, Settings_v {
|
||||
}
|
||||
|
||||
@objc func toggleMultithreading(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.hyperthreadState = state! == .on ? true : false
|
||||
self.hyperthreadState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_hyperhreading", value: self.hyperthreadState)
|
||||
self.callback()
|
||||
}
|
||||
|
||||
@objc func toggleIPG(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.IPGState = state! == .on ? true : false
|
||||
self.IPGState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_IPG", value: self.IPGState)
|
||||
self.IPGCallback(self.IPGState)
|
||||
}
|
||||
|
||||
@objc func toggleSplitValue(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.splitValueState = state! == .on ? true : false
|
||||
self.splitValueState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_splitValue", value: self.splitValueState)
|
||||
self.callback()
|
||||
}
|
||||
|
||||
@objc func toggleClustersGroup(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.clustersGroupState = state! == .on ? true : false
|
||||
self.clustersGroupState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_clustersGroup", value: self.clustersGroupState)
|
||||
|
||||
self.splitValueView?.isEnabled = !(self.usagePerCoreState || self.clustersGroupState)
|
||||
|
||||
@@ -238,12 +238,6 @@ public class Disk: Module {
|
||||
self.setReaders([self.capacityReader, self.activityReader, self.processReader])
|
||||
}
|
||||
|
||||
public override func widgetDidSet(_ type: widget_t) {
|
||||
if type == .speed && self.capacityReader?.interval != 1 {
|
||||
self.settingsView.setUpdateInterval(value: 1)
|
||||
}
|
||||
}
|
||||
|
||||
private func capacityCallback(_ value: Disks) {
|
||||
guard self.enabled else { return }
|
||||
|
||||
@@ -289,8 +283,16 @@ public class Disk: Module {
|
||||
|
||||
self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in
|
||||
switch w.item {
|
||||
case let widget as SpeedWidget: widget.setValue(upload: d.activity.write, download: d.activity.read)
|
||||
case let widget as NetworkChart: widget.setValue(upload: Double(d.activity.write), download: Double(d.activity.read))
|
||||
case let widget as SpeedWidget:
|
||||
widget.setValue(upload: d.activity.write, download: d.activity.read)
|
||||
if self.capacityReader?.interval != 1 {
|
||||
self.settingsView.setUpdateInterval(value: 1)
|
||||
}
|
||||
case let widget as NetworkChart:
|
||||
widget.setValue(upload: Double(d.activity.write), download: Double(d.activity.read))
|
||||
if self.capacityReader?.interval != 1 {
|
||||
self.settingsView.setUpdateInterval(value: 1)
|
||||
}
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,18 +50,12 @@ public struct GPU_Info: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct GPUs: value_t, Codable {
|
||||
public struct GPUs: Codable {
|
||||
public var list: [GPU_Info] = []
|
||||
|
||||
internal func active() -> [GPU_Info] {
|
||||
return self.list.filter{ $0.state && $0.utilization != nil }.sorted{ $0.utilization ?? 0 > $1.utilization ?? 0 }
|
||||
}
|
||||
|
||||
public var widgetValue: Double {
|
||||
get {
|
||||
return list.isEmpty ? 0 : (list[0].utilization ?? 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GPU: Module {
|
||||
|
||||
@@ -66,7 +66,7 @@ public struct Bandwidth: Codable {
|
||||
var download: Int64 = 0
|
||||
}
|
||||
|
||||
public struct Network_Usage: value_t, Codable {
|
||||
public struct Network_Usage: Codable {
|
||||
var bandwidth: Bandwidth = Bandwidth()
|
||||
var total: Bandwidth = Bandwidth()
|
||||
|
||||
@@ -90,8 +90,6 @@ public struct Network_Usage: value_t, Codable {
|
||||
|
||||
self.wifiDetails.reset()
|
||||
}
|
||||
|
||||
public var widgetValue: Double = 0
|
||||
}
|
||||
|
||||
public struct Network_Connectivity: Codable {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import Cocoa
|
||||
import Kit
|
||||
|
||||
public struct RAM_Usage: value_t, Codable {
|
||||
public struct RAM_Usage: Codable {
|
||||
var total: Double
|
||||
var used: Double
|
||||
var free: Double
|
||||
@@ -29,12 +29,6 @@ public struct RAM_Usage: value_t, Codable {
|
||||
var rawPressureLevel: UInt
|
||||
var swap: Swap
|
||||
|
||||
public var widgetValue: Double {
|
||||
get {
|
||||
return self.usage
|
||||
}
|
||||
}
|
||||
|
||||
public var usage: Double {
|
||||
get {
|
||||
return Double((self.total - self.free) / self.total)
|
||||
|
||||
@@ -112,7 +112,7 @@ public class Sensors: Module {
|
||||
value = "\(f.percentage)%"
|
||||
}
|
||||
}
|
||||
list.append(Stack_t(key: s.key, value: value, additional: s.name))
|
||||
list.append(Stack_t(key: s.key, value: value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user