mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: initialized popup settings (#565)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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, *) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -61,6 +61,12 @@ internal class Popup: NSStackView, Popup_p {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Settings
|
||||
|
||||
public func settings() -> NSView? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
internal class BLEView: NSStackView {
|
||||
|
||||
@@ -368,4 +368,10 @@ internal class Popup: NSView, Popup_p {
|
||||
self.initializedFrequency = false
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Settings
|
||||
|
||||
public func settings() -> NSView? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,12 @@ internal class Popup: NSStackView, Popup_p {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Settings
|
||||
|
||||
public func settings() -> NSView? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
internal class DiskView: NSStackView {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user