mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: moved all modules to the new way of reader mode with a small refactoring
This commit is contained in:
@@ -59,9 +59,9 @@ public class Battery: Module {
|
||||
private var notificationID: String? = nil
|
||||
|
||||
public init() {
|
||||
self.settingsView = Settings("Battery")
|
||||
self.popupView = Popup("Battery")
|
||||
self.portalView = Portal("Battery")
|
||||
self.settingsView = Settings(.battery)
|
||||
self.popupView = Popup(.battery)
|
||||
self.portalView = Portal(.battery)
|
||||
self.notificationsView = Notifications(.battery)
|
||||
|
||||
super.init(
|
||||
@@ -72,8 +72,14 @@ public class Battery: Module {
|
||||
)
|
||||
guard self.available else { return }
|
||||
|
||||
self.usageReader = UsageReader(.battery)
|
||||
self.processReader = ProcessReader(.battery)
|
||||
self.usageReader = UsageReader(.battery) { [weak self] value in
|
||||
self?.usageCallback(value)
|
||||
}
|
||||
self.processReader = ProcessReader(.battery) { [weak self] value in
|
||||
if let list = value {
|
||||
self?.popupView.processCallback(list)
|
||||
}
|
||||
}
|
||||
|
||||
self.settingsView.callback = { [weak self] in
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
@@ -87,25 +93,7 @@ public class Battery: Module {
|
||||
}
|
||||
}
|
||||
|
||||
self.usageReader?.callbackHandler = { [weak self] value in
|
||||
self?.usageCallback(value)
|
||||
}
|
||||
self.usageReader?.readyCallback = { [weak self] in
|
||||
self?.readyHandler()
|
||||
}
|
||||
|
||||
self.processReader?.callbackHandler = { [weak self] value in
|
||||
if let list = value {
|
||||
self?.popupView.processCallback(list)
|
||||
}
|
||||
}
|
||||
|
||||
if let reader = self.usageReader {
|
||||
self.addReader(reader)
|
||||
}
|
||||
if let reader = self.processReader {
|
||||
self.addReader(reader)
|
||||
}
|
||||
self.setReaders([self.usageReader, self.processReader])
|
||||
}
|
||||
|
||||
public override func willTerminate() {
|
||||
|
||||
@@ -64,8 +64,8 @@ internal class Popup: PopupWrapper {
|
||||
Store.shared.string(key: "\(self.title)_timeFormat", defaultValue: "short")
|
||||
}
|
||||
|
||||
public init(_ title: String) {
|
||||
self.title = title
|
||||
public init(_ module: ModuleType) {
|
||||
self.title = module.rawValue
|
||||
|
||||
super.init(frame: NSRect(
|
||||
x: 0,
|
||||
|
||||
@@ -25,8 +25,8 @@ internal class Portal: NSStackView, Portal_p {
|
||||
Store.shared.string(key: "\(self.name)_timeFormat", defaultValue: "short")
|
||||
}
|
||||
|
||||
init(_ name: String) {
|
||||
self.name = name
|
||||
public init(_ module: ModuleType) {
|
||||
self.name = module.rawValue
|
||||
|
||||
super.init(frame: NSRect.zero)
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ internal class Settings: NSStackView, Settings_v {
|
||||
private var numberOfProcesses: Int = 8
|
||||
private var timeFormat: String = "short"
|
||||
|
||||
public init(_ title: String) {
|
||||
self.title = title
|
||||
public init(_ module: ModuleType) {
|
||||
self.title = module.rawValue
|
||||
self.numberOfProcesses = Store.shared.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
self.timeFormat = Store.shared.string(key: "\(self.title)_timeFormat", defaultValue: self.timeFormat)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user