mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: moved from UnsafePointer<Store> to sharable instance (Store.shared)
This commit is contained in:
@@ -18,17 +18,15 @@ internal class Settings: NSView, Settings_v {
|
||||
private var numberOfProcesses: Int = 8
|
||||
|
||||
private let title: String
|
||||
private let store: UnsafePointer<Store>
|
||||
|
||||
public var callback: (() -> Void) = {}
|
||||
public var callbackWhenUpdateNumberOfProcesses: (() -> Void) = {}
|
||||
public var setInterval: ((_ value: Int) -> Void) = {_ in }
|
||||
|
||||
public init(_ title: String, store: UnsafePointer<Store>) {
|
||||
public init(_ title: String) {
|
||||
self.title = title
|
||||
self.store = store
|
||||
self.updateIntervalValue = store.pointee.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
|
||||
self.numberOfProcesses = store.pointee.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
self.updateIntervalValue = Store.shared.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
|
||||
self.numberOfProcesses = Store.shared.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
|
||||
super.init(frame: CGRect(
|
||||
x: 0,
|
||||
@@ -73,7 +71,7 @@ internal class Settings: NSView, Settings_v {
|
||||
@objc private func changeUpdateInterval(_ sender: NSMenuItem) {
|
||||
if let value = Int(sender.title.replacingOccurrences(of: " sec", with: "")) {
|
||||
self.updateIntervalValue = value
|
||||
self.store.pointee.set(key: "\(self.title)_updateInterval", value: value)
|
||||
Store.shared.set(key: "\(self.title)_updateInterval", value: value)
|
||||
self.setInterval(value)
|
||||
}
|
||||
}
|
||||
@@ -81,7 +79,7 @@ internal class Settings: NSView, Settings_v {
|
||||
@objc private func changeNumberOfProcesses(_ sender: NSMenuItem) {
|
||||
if let value = Int(sender.title) {
|
||||
self.numberOfProcesses = value
|
||||
self.store.pointee.set(key: "\(self.title)_processes", value: value)
|
||||
Store.shared.set(key: "\(self.title)_processes", value: value)
|
||||
self.callbackWhenUpdateNumberOfProcesses()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user