feat: moved from UnsafePointer<Store> to sharable instance (Store.shared)

This commit is contained in:
Serhiy Mytrovtsiy
2021-03-20 16:33:14 +01:00
parent 5d0dc75b2f
commit cd689999ac
39 changed files with 233 additions and 339 deletions

View File

@@ -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()
}
}