mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: moved all modules settings to the new design
This commit is contained in:
@@ -77,5 +77,12 @@
|
||||
<integer>4</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>Settings</key>
|
||||
<dict>
|
||||
<key>popup</key>
|
||||
<true/>
|
||||
<key>notifications</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -35,18 +35,18 @@ class Notifications: NotificationsWrapper {
|
||||
self.lowLevel = Store.shared.string(key: "\(self.module)_notifications_low", defaultValue: self.lowLevel)
|
||||
self.highLevel = Store.shared.string(key: "\(self.module)_notifications_high", defaultValue: self.highLevel)
|
||||
|
||||
self.addArrangedSubview(selectSettingsRow(
|
||||
title: localizedString("Low level notification"),
|
||||
action: #selector(self.changeLowLevel),
|
||||
items: notificationLevels,
|
||||
selected: self.lowLevel
|
||||
))
|
||||
self.addArrangedSubview(selectSettingsRow(
|
||||
title: localizedString("High level notification"),
|
||||
action: #selector(self.changeHighLevel),
|
||||
items: notificationLevels,
|
||||
selected: self.highLevel
|
||||
))
|
||||
self.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("Low level notification"), component: selectView(
|
||||
action: #selector(self.changeLowLevel),
|
||||
items: notificationLevels,
|
||||
selected: self.lowLevel
|
||||
)),
|
||||
PreferencesRow(localizedString("High level notification"), component: selectView(
|
||||
action: #selector(self.changeHighLevel),
|
||||
items: notificationLevels,
|
||||
selected: self.highLevel
|
||||
))
|
||||
]))
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -84,7 +84,6 @@ class Notifications: NotificationsWrapper {
|
||||
self.lowLevel = key.isEmpty ? "" : "\(Double(key) ?? 0)"
|
||||
Store.shared.set(key: "\(self.module)_notifications_low", value: self.lowLevel)
|
||||
}
|
||||
|
||||
@objc private func changeHighLevel(_ sender: NSMenuItem) {
|
||||
guard let key = sender.representedObject as? String else { return }
|
||||
self.highLevel = key.isEmpty ? "" : "\(Double(key) ?? 0)"
|
||||
|
||||
@@ -328,11 +328,12 @@ internal class Popup: PopupWrapper {
|
||||
public override func settings() -> NSView? {
|
||||
let view = SettingsContainerView()
|
||||
|
||||
view.addArrangedSubview(toggleSettingRow(
|
||||
title: localizedString("Colorize battery"),
|
||||
action: #selector(toggleColor),
|
||||
state: self.colorState
|
||||
))
|
||||
view.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("Colorize battery"), component: switchView(
|
||||
action: #selector(self.toggleColor),
|
||||
state: self.colorState
|
||||
))
|
||||
]))
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -28,16 +28,8 @@ internal class Settings: NSStackView, Settings_v {
|
||||
self.numberOfProcesses = Store.shared.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
self.timeFormat = Store.shared.string(key: "\(self.title)_timeFormat", defaultValue: self.timeFormat)
|
||||
|
||||
super.init(frame: NSRect(x: 0, y: 0, width: 0, height: 0))
|
||||
|
||||
super.init(frame: NSRect.zero)
|
||||
self.orientation = .vertical
|
||||
self.distribution = .gravityAreas
|
||||
self.edgeInsets = NSEdgeInsets(
|
||||
top: Constants.Settings.margin,
|
||||
left: Constants.Settings.margin,
|
||||
bottom: Constants.Settings.margin,
|
||||
right: Constants.Settings.margin
|
||||
)
|
||||
self.spacing = Constants.Settings.margin
|
||||
}
|
||||
|
||||
@@ -48,20 +40,22 @@ internal class Settings: NSStackView, Settings_v {
|
||||
public func load(widgets: [widget_t]) {
|
||||
self.subviews.forEach{ $0.removeFromSuperview() }
|
||||
|
||||
self.addArrangedSubview(selectSettingsRowV1(
|
||||
title: localizedString("Number of top processes"),
|
||||
action: #selector(changeNumberOfProcesses),
|
||||
items: NumbersOfProcesses.map{ "\($0)" },
|
||||
selected: "\(self.numberOfProcesses)"
|
||||
))
|
||||
self.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("Number of top processes"), component: selectView(
|
||||
action: #selector(self.changeNumberOfProcesses),
|
||||
items: NumbersOfProcesses.map{ KeyValue_t(key: "\($0)", value: "\($0)") },
|
||||
selected: "\(self.numberOfProcesses)"
|
||||
))
|
||||
]))
|
||||
|
||||
if !widgets.filter({ $0 == .battery }).isEmpty {
|
||||
self.addArrangedSubview(selectSettingsRow(
|
||||
title: localizedString("Time format"),
|
||||
action: #selector(toggleTimeFormat),
|
||||
items: ShortLong,
|
||||
selected: self.timeFormat
|
||||
))
|
||||
self.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("Time format"), component: selectView(
|
||||
action: #selector(toggleTimeFormat),
|
||||
items: ShortLong,
|
||||
selected: self.timeFormat
|
||||
))
|
||||
]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +66,8 @@ internal class Settings: NSStackView, Settings_v {
|
||||
self.callbackWhenUpdateNumberOfProcesses()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func toggleTimeFormat(_ sender: NSMenuItem) {
|
||||
guard let key = sender.representedObject as? String else {
|
||||
return
|
||||
}
|
||||
guard let key = sender.representedObject as? String else { return }
|
||||
self.timeFormat = key
|
||||
Store.shared.set(key: "\(self.title)_timeFormat", value: key)
|
||||
self.callback()
|
||||
|
||||
Reference in New Issue
Block a user