mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fixed view update
This commit is contained in:
@@ -28,7 +28,9 @@ class MenuBar {
|
||||
module.initWidget()
|
||||
}
|
||||
module.initMenu(active: value)
|
||||
module.initTab()
|
||||
if !module.tabInitialized {
|
||||
module.initTab()
|
||||
}
|
||||
self.updateWidget(name: module.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ class Battery: Module {
|
||||
public var active: Observable<Bool>
|
||||
public var available: Observable<Bool>
|
||||
public var reader: Reader = BatteryReader()
|
||||
public var viewAvailable: Bool = true
|
||||
public var tabAvailable: Bool = true
|
||||
public var tabInitialized: Bool = false
|
||||
public var tabView: NSTabViewItem = NSTabViewItem()
|
||||
|
||||
public var widgetType: WidgetType = Widgets.Mini
|
||||
|
||||
@@ -18,6 +18,8 @@ extension Battery {
|
||||
makeOverview()
|
||||
makeBattery()
|
||||
makePowerAdapter()
|
||||
|
||||
self.tabInitialized = true
|
||||
}
|
||||
|
||||
func makeMain() {
|
||||
|
||||
@@ -19,13 +19,13 @@ class CPU: Module {
|
||||
public var hyperthreading: Observable<Bool>
|
||||
public var reader: Reader = CPUReader()
|
||||
public var tabView: NSTabViewItem = NSTabViewItem()
|
||||
public var viewAvailable: Bool = true
|
||||
public var tabAvailable: Bool = true
|
||||
public var tabInitialized: Bool = false
|
||||
public var widgetType: WidgetType
|
||||
public var chart: LineChartView = LineChartView()
|
||||
|
||||
private let defaults = UserDefaults.standard
|
||||
private var submenu: NSMenu = NSMenu()
|
||||
private var initialized: Bool = false
|
||||
|
||||
init() {
|
||||
self.available = Observable(true)
|
||||
|
||||
@@ -19,6 +19,8 @@ extension CPU {
|
||||
makeOverview()
|
||||
makeProcesses()
|
||||
|
||||
self.tabInitialized = true
|
||||
|
||||
(self.reader as! CPUReader).usage.subscribe(observer: self) { (value, _) in
|
||||
let v: Double = Double((value.value * 100).roundTo(decimalPlaces: 2))!
|
||||
self.updateChart(value: v)
|
||||
|
||||
@@ -17,7 +17,8 @@ class Disk: Module {
|
||||
|
||||
public var active: Observable<Bool>
|
||||
public var available: Observable<Bool>
|
||||
public var viewAvailable: Bool = false
|
||||
public var tabAvailable: Bool = false
|
||||
public var tabInitialized: Bool = false
|
||||
public var tabView: NSTabViewItem = NSTabViewItem()
|
||||
|
||||
public var reader: Reader = DiskReader()
|
||||
@@ -32,6 +33,7 @@ class Disk: Module {
|
||||
}
|
||||
|
||||
func initTab() {
|
||||
self.tabInitialized = true
|
||||
self.tabView.view?.frame = NSRect(x: 0, y: 0, width: TabWidth, height: TabHeight)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ class Memory: Module {
|
||||
public var available: Observable<Bool>
|
||||
public var reader: Reader = MemoryReader()
|
||||
public var widgetType: WidgetType
|
||||
public var viewAvailable: Bool = true
|
||||
public var tabAvailable: Bool = true
|
||||
public var tabInitialized: Bool = false
|
||||
public var tabView: NSTabViewItem = NSTabViewItem()
|
||||
public var chart: LineChartView = LineChartView()
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ extension Memory {
|
||||
makeOverview()
|
||||
makeProcesses()
|
||||
|
||||
self.tabInitialized = true
|
||||
|
||||
(self.reader as! MemoryReader).usage.subscribe(observer: self) { (value, _) in
|
||||
self.updateChart(value: Units(bytes: Int64(value.used)).getReadableTuple().0)
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ protocol Module: class {
|
||||
var active: Observable<Bool> { get }
|
||||
var available: Observable<Bool> { get }
|
||||
|
||||
var viewAvailable: Bool { get }
|
||||
var tabView: NSTabViewItem { get }
|
||||
var tabAvailable: Bool { get }
|
||||
var tabInitialized: Bool { get }
|
||||
|
||||
var reader: Reader { get }
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ class Network: Module {
|
||||
public var available: Observable<Bool>
|
||||
public var reader: Reader = NetworkReader()
|
||||
public var widgetType: WidgetType = 2.0
|
||||
public var viewAvailable: Bool = false
|
||||
public var tabAvailable: Bool = false
|
||||
public var tabInitialized: Bool = false
|
||||
public var tabView: NSTabViewItem = NSTabViewItem()
|
||||
|
||||
private let defaults = UserDefaults.standard
|
||||
@@ -45,6 +46,8 @@ class Network: Module {
|
||||
text.frame.origin.y = ((self.tabView.view?.frame.size.height)! - 22) / 2
|
||||
|
||||
self.tabView.view?.addSubview(text)
|
||||
|
||||
self.tabInitialized = true
|
||||
}
|
||||
|
||||
func start() {
|
||||
|
||||
@@ -55,7 +55,7 @@ class MainViewController: NSViewController {
|
||||
func makeHeader() {
|
||||
var list: [String] = []
|
||||
for module in modules.value {
|
||||
if module.viewAvailable && module.available.value && module.active.value {
|
||||
if module.tabAvailable && module.available.value && module.active.value {
|
||||
list.append(module.name)
|
||||
|
||||
let tab = module.tabView
|
||||
|
||||
Reference in New Issue
Block a user