feat: initialized popup settings (#565)

This commit is contained in:
Serhiy Mytrovtsiy
2022-10-04 21:44:27 +02:00
parent d83ce4e12f
commit 42515ca1b5
11 changed files with 82 additions and 2 deletions

View File

@@ -124,7 +124,13 @@ open class Module: Module_p {
debug("Module started without widget", log: self.log)
}
self.settings = Settings(config: &self.config, widgets: &self.menuBar.widgets, enabled: self.enabled, moduleSettings: self.settingsView)
self.settings = Settings(
config: &self.config,
widgets: &self.menuBar.widgets,
enabled: self.enabled,
moduleSettings: self.settingsView,
popupSettings: self.popupView
)
self.settings?.toggleCallback = { [weak self] in
self?.toggleEnabled()
if self?.pauseState == true {

View File

@@ -13,6 +13,7 @@ import Cocoa
public protocol Popup_p: NSView {
var sizeCallback: ((NSSize) -> Void)? { get set }
func settings() -> NSView?
}
internal class PopupWindow: NSWindow, NSWindowDelegate {

View File

@@ -27,9 +27,11 @@ open class Settings: NSStackView, Settings_p {
private var config: UnsafePointer<module_c>
private var widgets: [Widget]
private var moduleSettings: Settings_v?
private var popupSettings: Popup_p?
private var moduleSettingsContainer: NSStackView?
private var widgetSettingsContainer: NSStackView?
private var popupSettingsContainer: NSStackView?
private var enableControl: NSControl?
@@ -42,6 +44,7 @@ open class Settings: NSStackView, Settings_p {
return view
}()
private let noWidgetsView: EmptyView = EmptyView(msg: localizedString("No available widgets to configure"))
private let noPopupSettingsView: EmptyView = EmptyView(msg: localizedString("No options to configure for the popup in this module"))
private var oneViewState: Bool {
get {
@@ -52,10 +55,11 @@ open class Settings: NSStackView, Settings_p {
}
}
init(config: UnsafePointer<module_c>, widgets: UnsafeMutablePointer<[Widget]>, enabled: Bool, moduleSettings: Settings_v?) {
init(config: UnsafePointer<module_c>, widgets: UnsafeMutablePointer<[Widget]>, enabled: Bool, moduleSettings: Settings_v?, popupSettings: Popup_p?) {
self.config = config
self.widgets = widgets.pointee
self.moduleSettings = moduleSettings
self.popupSettings = popupSettings
super.init(frame: NSRect(x: 0, y: 0, width: Constants.Settings.width, height: Constants.Settings.height))
@@ -193,8 +197,19 @@ open class Settings: NSStackView, Settings_p {
return view
}()
let popupTab: NSTabViewItem = NSTabViewItem()
popupTab.label = localizedString("Popup settings")
popupTab.view = {
let view = ScrollableStackView(frame: view.frame)
view.stackView.spacing = 0
self.popupSettingsContainer = view.stackView
self.loadPopupSettings()
return view
}()
view.addTabViewItem(moduleTab)
view.addTabViewItem(widgetTab)
view.addTabViewItem(popupTab)
return view
}
@@ -275,6 +290,16 @@ open class Settings: NSStackView, Settings_p {
}
}
private func loadPopupSettings() {
self.popupSettingsContainer?.subviews.forEach{ $0.removeFromSuperview() }
if let settingsView = self.popupSettings, let view = settingsView.settings() {
self.popupSettingsContainer?.addArrangedSubview(view)
} else {
self.popupSettingsContainer?.addArrangedSubview(self.noPopupSettingsView)
}
}
@objc private func toggleOneView(_ sender: NSControl) {
var state: NSControl.StateValue? = nil
if #available(OSX 10.15, *) {

View File

@@ -342,6 +342,12 @@ internal class Popup: NSView, Popup_p {
self.processesInitialized = true
})
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
private class BatteryView: NSView {

View File

@@ -61,6 +61,12 @@ internal class Popup: NSStackView, Popup_p {
}
}
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
internal class BLEView: NSStackView {

View File

@@ -368,4 +368,10 @@ internal class Popup: NSView, Popup_p {
self.initializedFrequency = false
})
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}

View File

@@ -73,6 +73,12 @@ internal class Popup: NSStackView, Popup_p {
}
}
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
internal class DiskView: NSStackView {

View File

@@ -53,6 +53,12 @@ internal class Popup: NSStackView, Popup_p {
self.sizeCallback?(self.frame.size)
}
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
private class GPUView: NSStackView {

View File

@@ -414,6 +414,12 @@ internal class Popup: NSStackView, Popup_p {
self.connectivityField?.stringValue = localizedString("Unknown")
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
// MARK: - helpers
private func topValueView(_ view: NSView, title: String, color: NSColor) -> (NSView, NSTextField, NSTextField, ColorView) {

View File

@@ -255,6 +255,12 @@ internal class Popup: NSView, Popup_p {
self.processesInitialized = true
})
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
public class PressureView: NSView {

View File

@@ -132,6 +132,12 @@ internal class Popup: NSStackView, Popup_p {
self.sizeCallback?(self.frame.size)
}
}
// MARK: - Settings
public func settings() -> NSView? {
return nil
}
}
// MARK: - Sensor view