feat: moved network base setting to module from widget (#1635)

Co-authored-by: Justin Harrell <justin@harrell.io>
This commit is contained in:
justinharrell
2023-10-21 12:28:58 -04:00
committed by GitHub
parent 021123968d
commit 24b29ccbfe
2 changed files with 21 additions and 18 deletions

View File

@@ -21,6 +21,7 @@ internal class Settings: NSStackView, Settings_v, NSTextFieldDelegate {
private var widgetActivationThreshold: Int = 0
private var ICMPHost: String = "1.1.1.1"
private var publicIPRefreshInterval: String = "never"
private var baseValue: String = "byte"
public var callback: (() -> Void) = {}
public var callbackWhenUpdateNumberOfProcesses: (() -> Void) = {}
@@ -50,6 +51,7 @@ internal class Settings: NSStackView, Settings_v, NSTextFieldDelegate {
self.widgetActivationThreshold = Store.shared.int(key: "\(self.title)_widgetActivationThreshold", defaultValue: self.widgetActivationThreshold)
self.ICMPHost = Store.shared.string(key: "\(self.title)_ICMPHost", defaultValue: self.ICMPHost)
self.publicIPRefreshInterval = Store.shared.string(key: "\(self.title)_publicIPRefreshInterval", defaultValue: self.publicIPRefreshInterval)
self.baseValue = Store.shared.string(key: "\(self.title)_base", defaultValue: self.baseValue)
super.init(frame: NSRect(x: 0, y: 0, width: 0, height: 0))
@@ -78,6 +80,13 @@ internal class Settings: NSStackView, Settings_v, NSTextFieldDelegate {
public func load(widgets: [widget_t]) {
self.subviews.forEach{ $0.removeFromSuperview() }
self.addArrangedSubview(selectSettingsRow(
title: localizedString("Base"),
action: #selector(toggleBase),
items: SpeedBase,
selected: self.baseValue
))
self.addArrangedSubview(self.activationSlider())
self.addArrangedSubview(selectSettingsRowV1(
@@ -124,6 +133,7 @@ internal class Settings: NSStackView, Settings_v, NSTextFieldDelegate {
placeholder: localizedString("Leave empty to disable the check"),
width: 220
))
}
private func interfaceSelector() -> NSView {
@@ -297,4 +307,10 @@ internal class Settings: NSStackView, Settings_v, NSTextFieldDelegate {
Store.shared.set(key: "\(self.title)_publicIPRefreshInterval", value: self.publicIPRefreshInterval)
self.publicIPRefreshIntervalCallback()
}
@objc private func toggleBase(_ sender: NSMenuItem) {
guard let key = sender.representedObject as? String else { return }
self.baseValue = key
Store.shared.set(key: "\(self.title)_base", value: self.baseValue)
}
}