- update readers update interval (moved to one list of intervals)

This commit is contained in:
Serhiy Mytrovtsiy
2020-10-23 15:12:05 +02:00
parent 86aaa57a21
commit e7a57ca64e
14 changed files with 130 additions and 75 deletions

View File

@@ -14,8 +14,7 @@ import StatsKit
import ModuleKit
internal class Settings: NSView, Settings_v {
private var updateIntervalValue: String = "1"
private let listOfUpdateIntervals: [String] = ["1", "2", "3", "5", "10", "15", "30"]
private var updateIntervalValue: Int = 1
private var selectedGPU: String
private let title: String
@@ -23,7 +22,7 @@ internal class Settings: NSView, Settings_v {
public var selectedGPUHandler: (String) -> Void = {_ in }
public var callback: (() -> Void) = {}
public var setInterval: ((_ value: Double) -> Void) = {_ in }
public var setInterval: ((_ value: Int) -> Void) = {_ in }
private var hyperthreadView: NSView? = nil
@@ -33,7 +32,7 @@ internal class Settings: NSView, Settings_v {
self.title = title
self.store = store
self.selectedGPU = store.pointee.string(key: "\(self.title)_gpu", defaultValue: "")
self.updateIntervalValue = store.pointee.string(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
self.updateIntervalValue = store.pointee.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
super.init(frame: CGRect(
x: 0,
@@ -60,7 +59,7 @@ internal class Settings: NSView, Settings_v {
frame: NSRect(x: Constants.Settings.margin, y: Constants.Settings.margin + (rowHeight + Constants.Settings.margin) * num, width: self.frame.width - (Constants.Settings.margin*2), height: rowHeight),
title: LocalizedString("Update interval"),
action: #selector(changeUpdateInterval),
items: self.listOfUpdateIntervals.map{ "\($0) sec" },
items: ReaderUpdateIntervals.map{ "\($0) sec" },
selected: "\(self.updateIntervalValue) sec"
))
@@ -108,11 +107,9 @@ internal class Settings: NSView, Settings_v {
}
@objc private func changeUpdateInterval(_ sender: NSMenuItem) {
let newUpdateInterval = sender.title.replacingOccurrences(of: " sec", with: "")
self.updateIntervalValue = newUpdateInterval
store.pointee.set(key: "\(self.title)_updateInterval", value: self.updateIntervalValue)
if let value = Double(self.updateIntervalValue) {
if let value = Int(sender.title.replacingOccurrences(of: " sec", with: "")) {
self.updateIntervalValue = value
self.store.pointee.set(key: "\(self.title)_updateInterval", value: value)
self.setInterval(value)
}
}