diff --git a/Kit/Widgets/BarChart.swift b/Kit/Widgets/BarChart.swift index 99421f68..a631b582 100644 --- a/Kit/Widgets/BarChart.swift +++ b/Kit/Widgets/BarChart.swift @@ -15,8 +15,8 @@ public class BarChart: WidgetWrapper { private var labelState: Bool = false private var boxState: Bool = true private var frameState: Bool = false - public var colorState: Color = .systemAccent - private var colors: [Color] = Color.allCases + public var colorState: SColor = .systemAccent + private var colors: [SColor] = SColor.allCases private var _value: [[ColorValue]] = [[]] private var _pressureLevel: DispatchSource.MemoryPressureEvent = .normal @@ -72,7 +72,7 @@ public class BarChart: WidgetWrapper { self.boxState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_box", defaultValue: self.boxState) self.frameState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_frame", defaultValue: self.frameState) self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState) - self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) + self.colorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) } if preview { diff --git a/Kit/Widgets/LineChart.swift b/Kit/Widgets/LineChart.swift index 06d7a857..aab03fda 100644 --- a/Kit/Widgets/LineChart.swift +++ b/Kit/Widgets/LineChart.swift @@ -17,7 +17,7 @@ public class LineChart: WidgetWrapper { private var frameState: Bool = false private var valueState: Bool = false private var valueColorState: Bool = false - private var colorState: Color = .systemAccent + private var colorState: SColor = .systemAccent private var historyCount: Int = 60 private var scaleState: Scale = .none @@ -27,7 +27,7 @@ public class LineChart: WidgetWrapper { width: 32, height: Constants.Widget.height - (2*Constants.Widget.margin.y) ), num: 60) - private var colors: [Color] = Color.allCases.filter({ $0 != Color.cluster }) + private var colors: [SColor] = SColor.allCases.filter({ $0 != SColor.cluster }) private var _value: Double = 0 private var _pressureLevel: DispatchSource.MemoryPressureEvent = .normal @@ -97,7 +97,7 @@ public class LineChart: WidgetWrapper { self.valueState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_value", defaultValue: self.valueState) self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState) self.valueColorState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_valueColor", defaultValue: self.valueColorState) - self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) + self.colorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) self.historyCount = Store.shared.int(key: "\(self.title)_\(self.type.rawValue)_historyCount", defaultValue: self.historyCount) self.scaleState = Scale.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_scale", defaultValue: self.scaleState.key)) @@ -348,7 +348,7 @@ public class LineChart: WidgetWrapper { @objc private func toggleColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.colorState = newColor } Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key) diff --git a/Kit/Widgets/Memory.swift b/Kit/Widgets/Memory.swift index 8d3151d9..cd14512e 100644 --- a/Kit/Widgets/Memory.swift +++ b/Kit/Widgets/Memory.swift @@ -17,7 +17,7 @@ public class MemoryWidget: WidgetWrapper { private var percentage: Double = 0 private var pressureLevel: DispatchSource.MemoryPressureEvent = .normal private var symbolsState: Bool = true - private var colorState: Color = .monochrome + private var colorState: SColor = .monochrome private let width: CGFloat = 50 @@ -51,7 +51,7 @@ public class MemoryWidget: WidgetWrapper { if !preview { self.orderReversedState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_orderReversed", defaultValue: self.orderReversedState) self.symbolsState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_symbols", defaultValue: self.symbolsState) - self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) + self.colorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) } if preview { @@ -151,7 +151,7 @@ public class MemoryWidget: WidgetWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("Color"), component: selectView( action: #selector(self.toggleColor), - items: Color.allCases.filter({ $0 != .cluster }), + items: SColor.allCases.filter({ $0 != .cluster }), selected: self.colorState.key )), PreferencesRow(localizedString("Show symbols"), component: switchView( @@ -181,7 +181,7 @@ public class MemoryWidget: WidgetWrapper { @objc private func toggleColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.colorState = newColor } Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key) diff --git a/Kit/Widgets/Mini.swift b/Kit/Widgets/Mini.swift index 3c36b9e3..2e911375 100644 --- a/Kit/Widgets/Mini.swift +++ b/Kit/Widgets/Mini.swift @@ -13,10 +13,10 @@ import Cocoa public class Mini: WidgetWrapper { private var labelState: Bool = true - private var colorState: Color = .monochrome + private var colorState: SColor = .monochrome private var alignmentState: String = "left" - private var colors: [Color] = Color.allCases + private var colors: [SColor] = SColor.allCases private var _value: Double = 0 private var _pressureLevel: DispatchSource.MemoryPressureEvent = .normal @@ -78,7 +78,7 @@ public class Mini: WidgetWrapper { self.canDrawConcurrently = true if !preview { - self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) + self.colorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key)) self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState) self.alignmentState = Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_alignment", defaultValue: self.alignmentState) } @@ -207,7 +207,7 @@ public class Mini: WidgetWrapper { @objc private func toggleColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.colorState = newColor } Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key) diff --git a/Kit/Widgets/NetworkChart.swift b/Kit/Widgets/NetworkChart.swift index cf982ef8..34da4247 100644 --- a/Kit/Widgets/NetworkChart.swift +++ b/Kit/Widgets/NetworkChart.swift @@ -16,8 +16,8 @@ public class NetworkChart: WidgetWrapper { private var frameState: Bool = false private var labelState: Bool = false private var historyCount: Int = 60 - private var downloadColor: Color = .secondBlue - private var uploadColor: Color = .secondRed + private var downloadColor: SColor = .secondBlue + private var uploadColor: SColor = .secondRed private var scaleState: Scale = .linear private var reverseOrderState: Bool = false @@ -46,7 +46,7 @@ public class NetworkChart: WidgetWrapper { KeyValue_t(key: "90", value: "90"), KeyValue_t(key: "120", value: "120") ] - private var colors: [Color] = Color.allCases + private var colors: [SColor] = SColor.allCases private var boxSettingsView: NSSwitch? = nil private var frameSettingsView: NSSwitch? = nil @@ -78,8 +78,8 @@ public class NetworkChart: WidgetWrapper { self.frameState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_frame", defaultValue: self.frameState) self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState) self.historyCount = Store.shared.int(key: "\(self.title)_\(self.type.rawValue)_historyCount", defaultValue: self.historyCount) - self.downloadColor = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_downloadColor", defaultValue: self.downloadColor.key)) - self.uploadColor = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_uploadColor", defaultValue: self.uploadColor.key)) + self.downloadColor = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_downloadColor", defaultValue: self.downloadColor.key)) + self.uploadColor = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_uploadColor", defaultValue: self.uploadColor.key)) self.scaleState = Scale.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_scale", defaultValue: self.scaleState.key)) self.reverseOrderState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_reverseOrder", defaultValue: self.reverseOrderState) } @@ -350,7 +350,7 @@ public class NetworkChart: WidgetWrapper { @objc private func toggleDownloadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.downloadColor = newColor Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_downloadColor", value: newColor.key) } @@ -359,7 +359,7 @@ public class NetworkChart: WidgetWrapper { @objc private func toggleUploadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.uploadColor = newColor Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_uploadColor", value: newColor.key) } diff --git a/Kit/Widgets/Speed.swift b/Kit/Widgets/Speed.swift index 2ea1cdbd..bbe6bdb6 100644 --- a/Kit/Widgets/Speed.swift +++ b/Kit/Widgets/Speed.swift @@ -22,8 +22,8 @@ public class SpeedWidget: WidgetWrapper { private var modeState: String = "twoRows" private var reverseOrderState: Bool = false - private var downloadColorState: Color = .secondBlue - private var uploadColorState: Color = .secondRed + private var downloadColorState: SColor = .secondBlue + private var uploadColorState: SColor = .secondRed private var symbols: [String] = ["U", "D"] @@ -79,8 +79,8 @@ public class SpeedWidget: WidgetWrapper { self.unitsState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_units", defaultValue: self.unitsState) self.monochromeState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_monochrome", defaultValue: self.monochromeState) self.valueColorState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_valueColor", defaultValue: self.valueColorState) - self.downloadColorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_downloadColor", defaultValue: self.downloadColorState.key)) - self.uploadColorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_uploadColor", defaultValue: self.uploadColorState.key)) + self.downloadColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_downloadColor", defaultValue: self.downloadColorState.key)) + self.uploadColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_uploadColor", defaultValue: self.uploadColorState.key)) self.transparentIconsState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_transparentIcons", defaultValue: self.transparentIconsState) self.valueAlignmentState = Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_valueAlignment", defaultValue: self.valueAlignmentState) self.modeState = Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_mode", defaultValue: self.modeState) @@ -473,12 +473,12 @@ public class SpeedWidget: WidgetWrapper { )), PreferencesRow(localizedString("Color of download"), component: selectView( action: #selector(self.toggleDownloadColor), - items: Color.allColors, + items: SColor.allColors, selected: self.downloadColorState.key )), PreferencesRow(localizedString("Color of upload"), component: selectView( action: #selector(self.toggleUploadColor), - items: Color.allColors, + items: SColor.allColors, selected: self.uploadColorState.key )) ])) @@ -536,7 +536,7 @@ public class SpeedWidget: WidgetWrapper { @objc private func toggleUploadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.uploadColorState = newValue @@ -544,7 +544,7 @@ public class SpeedWidget: WidgetWrapper { } @objc private func toggleDownloadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.downloadColorState = newValue diff --git a/Kit/Widgets/State.swift b/Kit/Widgets/State.swift index e06e6e5c..7858c52e 100644 --- a/Kit/Widgets/State.swift +++ b/Kit/Widgets/State.swift @@ -12,12 +12,12 @@ import Cocoa public class StateWidget: WidgetWrapper { - private var activeColorState: Color = .secondGreen - private var nonactiveColorState: Color = .secondRed + private var activeColorState: SColor = .secondGreen + private var nonactiveColorState: SColor = .secondRed private var value: Bool = false - private var colors: [Color] = Color.allColors + private var colors: [SColor] = SColor.allColors public init(title: String, config: NSDictionary?, preview: Bool = false) { if config != nil { @@ -43,8 +43,8 @@ public class StateWidget: WidgetWrapper { self.canDrawConcurrently = true if !preview { - self.activeColorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_activeColor", defaultValue: self.activeColorState.key)) - self.nonactiveColorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_nonactiveColor", defaultValue: self.nonactiveColorState.key)) + self.activeColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_activeColor", defaultValue: self.activeColorState.key)) + self.nonactiveColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_nonactiveColor", defaultValue: self.nonactiveColorState.key)) } } @@ -92,7 +92,7 @@ public class StateWidget: WidgetWrapper { @objc private func toggleActiveColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.activeColorState = newColor } Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_activeColor", value: key) @@ -101,7 +101,7 @@ public class StateWidget: WidgetWrapper { @objc private func toggleNonactiveColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String else { return } - if let newColor = Color.allCases.first(where: { $0.key == key }) { + if let newColor = SColor.allCases.first(where: { $0.key == key }) { self.nonactiveColorState = newColor } Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_nonactiveColor", value: key) diff --git a/Kit/module/settings.swift b/Kit/module/settings.swift index 261e0dc8..b8602c82 100644 --- a/Kit/module/settings.swift +++ b/Kit/module/settings.swift @@ -21,7 +21,7 @@ public protocol Settings_v: NSView { open class Settings: NSStackView, Settings_p { private var config: UnsafePointer - private var widgets: [Widget] + private var widgets: [SWidget] private var segmentedControl: NSSegmentedControl? private var tabView: NSTabView? @@ -57,7 +57,7 @@ open class Settings: NSStackView, Settings_p { private var isPopupSettingsAvailable: Bool private var isNotificationsSettingsAvailable: Bool - init(config: UnsafePointer, widgets: UnsafeMutablePointer<[Widget]>, moduleSettings: Settings_v?, popupSettings: Popup_p?, notificationsSettings: NotificationsWrapper?) { + init(config: UnsafePointer, widgets: UnsafeMutablePointer<[SWidget]>, moduleSettings: Settings_v?, popupSettings: Popup_p?, notificationsSettings: NotificationsWrapper?) { self.config = config self.widgets = widgets.pointee self.moduleSettings = moduleSettings @@ -285,7 +285,7 @@ private class WidgetSelectorView: NSStackView { return view }() - fileprivate init(module: String, widgets: [Widget], stateCallback: @escaping () -> Void) { + fileprivate init(module: String, widgets: [SWidget], stateCallback: @escaping () -> Void) { self.module = module self.stateCallback = stateCallback diff --git a/Kit/module/widget.swift b/Kit/module/widget.swift index 3c5fb12c..b5e1503a 100644 --- a/Kit/module/widget.swift +++ b/Kit/module/widget.swift @@ -27,7 +27,7 @@ public enum widget_t: String { case tachometer = "tachometer" case state = "state" - public func new(module: String, config: NSDictionary, defaultWidget: widget_t) -> Widget? { + public func new(module: String, config: NSDictionary, defaultWidget: widget_t) -> SWidget? { guard let widgetConfig: NSDictionary = config[self.rawValue] as? NSDictionary else { return nil } var image: NSImage? = nil @@ -116,7 +116,7 @@ public enum widget_t: String { } if let item = item, let image = image { - return Widget(self, defaultWidget: defaultWidget, module: module, item: item, image: image) + return SWidget(self, defaultWidget: defaultWidget, module: module, item: item, image: image) } return nil @@ -219,7 +219,7 @@ open class WidgetWrapper: NSView, widget_p { } } -public class Widget { +public class SWidget { public let type: widget_t public let defaultWidget: widget_t public let module: String @@ -367,7 +367,7 @@ public class Widget { public class MenuBar { public var callback: (() -> Void)? = nil - public var widgets: [Widget] = [] + public var widgets: [SWidget] = [] private var moduleName: String private var menuBarItem: NSStatusItem? = nil @@ -379,13 +379,13 @@ public class MenuBar { public var view: MenuBarView = MenuBarView() public var oneView: Bool = false - public var activeWidgets: [Widget] { + public var activeWidgets: [SWidget] { self.widgets.filter({ $0.isActive }) } public var sortedWidgets: [widget_t] { get { var list: [widget_t: Int] = [:] - self.activeWidgets.forEach { (w: Widget) in + self.activeWidgets.forEach { (w: SWidget) in list[w.type] = w.position } return list.sorted { $0.1 < $1.1 }.map{ $0.key } @@ -423,7 +423,7 @@ public class MenuBar { NotificationCenter.default.removeObserver(self, name: .widgetRearrange, object: nil) } - public func append(_ widget: Widget) { + public func append(_ widget: SWidget) { widget.toggleCallback = { [weak self] (type, state) in if let s = self, s.oneView { if state, let w = s.activeWidgets.first(where: { $0.type == type }) { @@ -526,7 +526,7 @@ public class MenuBar { } private func toggleOneView() { - self.activeWidgets.forEach { (w: Widget) in + self.activeWidgets.forEach { (w: SWidget) in w.disable() } @@ -538,7 +538,7 @@ public class MenuBar { self.setupMenuBarItem(self.oneView) } - self.activeWidgets.forEach { (w: Widget) in + self.activeWidgets.forEach { (w: SWidget) in w.enable() } } diff --git a/Kit/types.swift b/Kit/types.swift index e532633b..0365df52 100644 --- a/Kit/types.swift +++ b/Kit/types.swift @@ -163,60 +163,60 @@ internal let Alignments: [KeyValue_t] = [ KeyValue_t(key: "right", value: "Right alignment", additional: NSTextAlignment.right) ] -public struct Color: KeyValue_p, Equatable { +public struct SColor: KeyValue_p, Equatable { public let key: String public let value: String public var additional: Any? - public static func == (lhs: Color, rhs: Color) -> Bool { + public static func == (lhs: SColor, rhs: SColor) -> Bool { return lhs.key == rhs.key } } -extension Color: CaseIterable { - public static var utilization: Color { return Color(key: "utilization", value: "Based on utilization", additional: NSColor.black) } - public static var pressure: Color { return Color(key: "pressure", value: "Based on pressure", additional: NSColor.black) } - public static var cluster: Color { return Color(key: "cluster", value: "Based on cluster", additional: NSColor.controlAccentColor) } +extension SColor: CaseIterable { + public static var utilization: SColor { return SColor(key: "utilization", value: "Based on utilization", additional: NSColor.black) } + public static var pressure: SColor { return SColor(key: "pressure", value: "Based on pressure", additional: NSColor.black) } + public static var cluster: SColor { return SColor(key: "cluster", value: "Based on cluster", additional: NSColor.controlAccentColor) } - public static var separator1: Color { return Color(key: "separator_1", value: "separator_1", additional: NSColor.black) } + public static var separator1: SColor { return SColor(key: "separator_1", value: "separator_1", additional: NSColor.black) } - public static var systemAccent: Color { return Color(key: "system", value: "System accent", additional: NSColor.controlAccentColor) } - public static var monochrome: Color { return Color(key: "monochrome", value: "Monochrome accent", additional: NSColor.textColor) } + public static var systemAccent: SColor { return SColor(key: "system", value: "System accent", additional: NSColor.controlAccentColor) } + public static var monochrome: SColor { return SColor(key: "monochrome", value: "Monochrome accent", additional: NSColor.textColor) } - public static var separator2: Color { return Color(key: "separator_2", value: "separator_2", additional: NSColor.black) } + public static var separator2: SColor { return SColor(key: "separator_2", value: "separator_2", additional: NSColor.black) } - public static var clear: Color { return Color(key: "clear", value: "Clear", additional: NSColor.clear) } - public static var white: Color { return Color(key: "white", value: "White", additional: NSColor.white) } - public static var black: Color { return Color(key: "black", value: "Black", additional: NSColor.black) } - public static var gray: Color { return Color(key: "gray", value: "Gray", additional: NSColor.gray) } - public static var secondGray: Color { return Color(key: "secondGray", value: "Second gray", additional: NSColor.systemGray) } - public static var darkGray: Color { return Color(key: "darkGray", value: "Dark gray", additional: NSColor.darkGray) } - public static var lightGray: Color { return Color(key: "lightGray", value: "Light gray", additional: NSColor.lightGray) } - public static var red: Color { return Color(key: "red", value: "Red", additional: NSColor.red) } - public static var secondRed: Color { return Color(key: "secondRed", value: "Second red", additional: NSColor.systemRed) } - public static var green: Color { return Color(key: "green", value: "Green", additional: NSColor.green) } - public static var secondGreen: Color { return Color(key: "secondGreen", value: "Second green", additional: NSColor.systemGreen) } - public static var blue: Color { return Color(key: "blue", value: "Blue", additional: NSColor.blue) } - public static var secondBlue: Color { return Color(key: "secondBlue", value: "Second blue", additional: NSColor.systemBlue) } - public static var yellow: Color { return Color(key: "yellow", value: "Yellow", additional: NSColor.yellow) } - public static var secondYellow: Color { return Color(key: "secondYellow", value: "Second yellow", additional: NSColor.systemYellow) } - public static var orange: Color { return Color(key: "orange", value: "Orange", additional: NSColor.orange) } - public static var secondOrange: Color { return Color(key: "secondOrange", value: "Second orange", additional: NSColor.systemOrange) } - public static var purple: Color { return Color(key: "purple", value: "Purple", additional: NSColor.purple) } - public static var secondPurple: Color { return Color(key: "secondPurple", value: "Second purple", additional: NSColor.systemPurple) } - public static var brown: Color { return Color(key: "brown", value: "Brown", additional: NSColor.brown) } - public static var secondBrown: Color { return Color(key: "secondBrown", value: "Second brown", additional: NSColor.systemBrown) } - public static var cyan: Color { return Color(key: "cyan", value: "Cyan", additional: NSColor.cyan) } - public static var magenta: Color { return Color(key: "magenta", value: "Magenta", additional: NSColor.magenta) } - public static var pink: Color { return Color(key: "pink", value: "Pink", additional: NSColor.systemPink) } - public static var teal: Color { return Color(key: "teal", value: "Teal", additional: NSColor.systemTeal) } - public static var indigo: Color { if #available(OSX 10.15, *) { - return Color(key: "indigo", value: "Indigo", additional: NSColor.systemIndigo) + public static var clear: SColor { return SColor(key: "clear", value: "Clear", additional: NSColor.clear) } + public static var white: SColor { return SColor(key: "white", value: "White", additional: NSColor.white) } + public static var black: SColor { return SColor(key: "black", value: "Black", additional: NSColor.black) } + public static var gray: SColor { return SColor(key: "gray", value: "Gray", additional: NSColor.gray) } + public static var secondGray: SColor { return SColor(key: "secondGray", value: "Second gray", additional: NSColor.systemGray) } + public static var darkGray: SColor { return SColor(key: "darkGray", value: "Dark gray", additional: NSColor.darkGray) } + public static var lightGray: SColor { return SColor(key: "lightGray", value: "Light gray", additional: NSColor.lightGray) } + public static var red: SColor { return SColor(key: "red", value: "Red", additional: NSColor.red) } + public static var secondRed: SColor { return SColor(key: "secondRed", value: "Second red", additional: NSColor.systemRed) } + public static var green: SColor { return SColor(key: "green", value: "Green", additional: NSColor.green) } + public static var secondGreen: SColor { return SColor(key: "secondGreen", value: "Second green", additional: NSColor.systemGreen) } + public static var blue: SColor { return SColor(key: "blue", value: "Blue", additional: NSColor.blue) } + public static var secondBlue: SColor { return SColor(key: "secondBlue", value: "Second blue", additional: NSColor.systemBlue) } + public static var yellow: SColor { return SColor(key: "yellow", value: "Yellow", additional: NSColor.yellow) } + public static var secondYellow: SColor { return SColor(key: "secondYellow", value: "Second yellow", additional: NSColor.systemYellow) } + public static var orange: SColor { return SColor(key: "orange", value: "Orange", additional: NSColor.orange) } + public static var secondOrange: SColor { return SColor(key: "secondOrange", value: "Second orange", additional: NSColor.systemOrange) } + public static var purple: SColor { return SColor(key: "purple", value: "Purple", additional: NSColor.purple) } + public static var secondPurple: SColor { return SColor(key: "secondPurple", value: "Second purple", additional: NSColor.systemPurple) } + public static var brown: SColor { return SColor(key: "brown", value: "Brown", additional: NSColor.brown) } + public static var secondBrown: SColor { return SColor(key: "secondBrown", value: "Second brown", additional: NSColor.systemBrown) } + public static var cyan: SColor { return SColor(key: "cyan", value: "Cyan", additional: NSColor.cyan) } + public static var magenta: SColor { return SColor(key: "magenta", value: "Magenta", additional: NSColor.magenta) } + public static var pink: SColor { return SColor(key: "pink", value: "Pink", additional: NSColor.systemPink) } + public static var teal: SColor { return SColor(key: "teal", value: "Teal", additional: NSColor.systemTeal) } + public static var indigo: SColor { if #available(OSX 10.15, *) { + return SColor(key: "indigo", value: "Indigo", additional: NSColor.systemIndigo) } else { - return Color(key: "indigo", value: "Indigo", additional: NSColor(red: 75, green: 0, blue: 130, alpha: 1)) + return SColor(key: "indigo", value: "Indigo", additional: NSColor(red: 75, green: 0, blue: 130, alpha: 1)) } } - public static var allCases: [Color] { + public static var allCases: [SColor] { return [.utilization, .pressure, .cluster, separator1, .systemAccent, .monochrome, separator2, .clear, .white, .black, .gray, .secondGray, .darkGray, .lightGray, @@ -226,7 +226,7 @@ extension Color: CaseIterable { ] } - public static var allColors: [Color] { + public static var allColors: [SColor] { return [.systemAccent, .monochrome, .separator2, .clear, .white, .black, .gray, .secondGray, .darkGray, .lightGray, .red, .secondRed, .green, .secondGreen, .blue, .secondBlue, .yellow, .secondYellow, .orange, .secondOrange, .purple, .secondPurple, .brown, .secondBrown, @@ -234,8 +234,8 @@ extension Color: CaseIterable { ] } - public static func fromString(_ key: String, defaultValue: Color = .systemAccent) -> Color { - return Color.allCases.first{ $0.key == key } ?? defaultValue + public static func fromString(_ key: String, defaultValue: SColor = .systemAccent) -> SColor { + return SColor.allCases.first{ $0.key == key } ?? defaultValue } } diff --git a/Modules/Battery/main.swift b/Modules/Battery/main.swift index 21b758a6..831eec12 100644 --- a/Modules/Battery/main.swift +++ b/Modules/Battery/main.swift @@ -110,7 +110,7 @@ public class Battery: Module { self.portalView.loadCallback(value) self.notificationsView.usageCallback(value) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as Mini: widget.setValue(abs(value.level)) diff --git a/Modules/Bluetooth/main.swift b/Modules/Bluetooth/main.swift index 240ed082..446d4b9c 100644 --- a/Modules/Bluetooth/main.swift +++ b/Modules/Bluetooth/main.swift @@ -121,7 +121,7 @@ public class Bluetooth: Module { } } - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as StackWidget: widget.setValues(list) default: break diff --git a/Modules/CPU/main.swift b/Modules/CPU/main.swift index 2c92b525..a997347c 100644 --- a/Modules/CPU/main.swift +++ b/Modules/CPU/main.swift @@ -50,34 +50,34 @@ public class CPU: Module { Store.shared.bool(key: "\(self.config.name)_clustersGroup", defaultValue: false) } private var systemColor: NSColor { - let color = Color.secondRed + let color = SColor.secondRed let key = Store.shared.string(key: "\(self.config.name)_systemColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor } private var userColor: NSColor { - let color = Color.secondBlue + let color = SColor.secondBlue let key = Store.shared.string(key: "\(self.config.name)_userColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor } private var eCoreColor: NSColor { - let color = Color.teal + let color = SColor.teal let key = Store.shared.string(key: "\(self.config.name)_eCoresColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor } private var pCoreColor: NSColor { - let color = Color.secondBlue + let color = SColor.secondBlue let key = Store.shared.string(key: "\(self.config.name)_pCoresColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor @@ -166,7 +166,7 @@ public class CPU: Module { WidgetCenter.shared.reloadTimelines(ofKind: CPU_entry.kind) } - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as Mini: widget.setValue(value.totalUsage) case let widget as LineChart: widget.setValue(value.totalUsage) diff --git a/Modules/CPU/popup.swift b/Modules/CPU/popup.swift index 4fbda7a8..d0d80f08 100644 --- a/Modules/CPU/popup.swift +++ b/Modules/CPU/popup.swift @@ -73,17 +73,17 @@ internal class Popup: PopupWrapper { private var lineChartScale: Scale = .none private var lineChartFixedScale: Double = 1 - private var systemColorState: Color = .secondRed + private var systemColorState: SColor = .secondRed private var systemColor: NSColor { self.systemColorState.additional as? NSColor ?? NSColor.systemRed } - private var userColorState: Color = .secondBlue + private var userColorState: SColor = .secondBlue private var userColor: NSColor { self.userColorState.additional as? NSColor ?? NSColor.systemBlue } - private var idleColorState: Color = .lightGray + private var idleColorState: SColor = .lightGray private var idleColor: NSColor { self.idleColorState.additional as? NSColor ?? NSColor.lightGray } - private var chartColorState: Color = .systemAccent + private var chartColorState: SColor = .systemAccent private var chartColor: NSColor { self.chartColorState.additional as? NSColor ?? NSColor.systemBlue } - private var eCoresColorState: Color = .teal + private var eCoresColorState: SColor = .teal private var eCoresColor: NSColor { self.eCoresColorState.additional as? NSColor ?? NSColor.systemTeal } - private var pCoresColorState: Color = .secondBlue + private var pCoresColorState: SColor = .secondBlue private var pCoresColor: NSColor { self.pCoresColorState.additional as? NSColor ?? NSColor.systemBlue } private var numberOfProcesses: Int { @@ -117,12 +117,12 @@ internal class Popup: PopupWrapper { )) self.setFrameSize(NSSize(width: self.frame.width, height: self.frame.height + self.detailsHeight + self.processesHeight)) - self.systemColorState = Color.fromString(Store.shared.string(key: "\(self.title)_systemColor", defaultValue: self.systemColorState.key)) - self.userColorState = Color.fromString(Store.shared.string(key: "\(self.title)_userColor", defaultValue: self.userColorState.key)) - self.idleColorState = Color.fromString(Store.shared.string(key: "\(self.title)_idleColor", defaultValue: self.idleColorState.key)) - self.chartColorState = Color.fromString(Store.shared.string(key: "\(self.title)_chartColor", defaultValue: self.chartColorState.key)) - self.eCoresColorState = Color.fromString(Store.shared.string(key: "\(self.title)_eCoresColor", defaultValue: self.eCoresColorState.key)) - self.pCoresColorState = Color.fromString(Store.shared.string(key: "\(self.title)_pCoresColor", defaultValue: self.pCoresColorState.key)) + self.systemColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_systemColor", defaultValue: self.systemColorState.key)) + self.userColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_userColor", defaultValue: self.userColorState.key)) + self.idleColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_idleColor", defaultValue: self.idleColorState.key)) + self.chartColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_chartColor", defaultValue: self.chartColorState.key)) + self.eCoresColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_eCoresColor", defaultValue: self.eCoresColorState.key)) + self.pCoresColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_pCoresColor", defaultValue: self.pCoresColorState.key)) self.lineChartHistory = Store.shared.int(key: "\(self.title)_lineChartHistory", defaultValue: self.lineChartHistory) self.lineChartScale = Scale.fromString(Store.shared.string(key: "\(self.title)_lineChartScale", defaultValue: self.lineChartScale.key)) self.lineChartFixedScale = Double(Store.shared.int(key: "\(self.title)_lineChartFixedScale", defaultValue: 100)) / 100 @@ -476,17 +476,17 @@ internal class Popup: PopupWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("System color"), component: selectView( action: #selector(self.toggleSystemColor), - items: Color.allColors, + items: SColor.allColors, selected: self.systemColorState.key )), PreferencesRow(localizedString("User color"), component: selectView( action: #selector(self.toggleUserColor), - items: Color.allColors, + items: SColor.allColors, selected: self.userColorState.key )), PreferencesRow(localizedString("Idle color"), component: selectView( action: #selector(self.toggleIdleColor), - items: Color.allColors, + items: SColor.allColors, selected: self.idleColorState.key )) ])) @@ -494,12 +494,12 @@ internal class Popup: PopupWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("Efficiency cores color"), component: selectView( action: #selector(self.toggleECoresColor), - items: Color.allColors, + items: SColor.allColors, selected: self.eCoresColorState.key )), PreferencesRow(localizedString("Performance cores color"), component: selectView( action: #selector(self.togglePCoresColor), - items: Color.allColors, + items: SColor.allColors, selected: self.pCoresColorState.key )) ])) @@ -512,7 +512,7 @@ internal class Popup: PopupWrapper { self.chartPrefSection = PreferencesSection([ PreferencesRow(localizedString("Chart color"), component: selectView( action: #selector(self.toggleChartColor), - items: Color.allColors, + items: SColor.allColors, selected: self.chartColorState.key )), PreferencesRow(localizedString("Chart history"), component: selectView( @@ -534,7 +534,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleSystemColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.systemColorState = newValue @@ -542,7 +542,7 @@ internal class Popup: PopupWrapper { self.systemColorView?.layer?.backgroundColor = (newValue.additional as? NSColor)?.cgColor } @objc private func toggleUserColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.userColorState = newValue @@ -550,7 +550,7 @@ internal class Popup: PopupWrapper { self.userColorView?.layer?.backgroundColor = (newValue.additional as? NSColor)?.cgColor } @objc private func toggleIdleColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.idleColorState = newValue @@ -561,7 +561,7 @@ internal class Popup: PopupWrapper { self.idleColorView?.layer?.backgroundColor = (newValue.additional as? NSColor)?.cgColor } @objc private func toggleChartColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.chartColorState = newValue @@ -571,7 +571,7 @@ internal class Popup: PopupWrapper { } } @objc private func toggleECoresColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.eCoresColorState = newValue @@ -579,7 +579,7 @@ internal class Popup: PopupWrapper { self.eCoresColorView?.layer?.backgroundColor = (newValue.additional as? NSColor)?.cgColor } @objc private func togglePCoresColor(_ sender: NSMenuItem) { - guard let key = sender.representedObject as? String, let newValue = Color.allColors.first(where: { $0.key == key }) else { + guard let key = sender.representedObject as? String, let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.pCoresColorState = newValue diff --git a/Modules/CPU/portal.swift b/Modules/CPU/portal.swift index f87bcf04..cc56e5b1 100644 --- a/Modules/CPU/portal.swift +++ b/Modules/CPU/portal.swift @@ -35,15 +35,15 @@ public class Portal: PortalWrapper { private var eCoresColorView: NSView? = nil private var pCoresColorView: NSView? = nil - private var systemColorState: Color = .secondRed + private var systemColorState: SColor = .secondRed private var systemColor: NSColor { self.systemColorState.additional as? NSColor ?? NSColor.systemRed } - private var userColorState: Color = .secondBlue + private var userColorState: SColor = .secondBlue private var userColor: NSColor { self.userColorState.additional as? NSColor ?? NSColor.systemBlue } - private var idleColorState: Color = .lightGray + private var idleColorState: SColor = .lightGray private var idleColor: NSColor { self.idleColorState.additional as? NSColor ?? NSColor.lightGray } - private var eCoresColorState: Color = .teal + private var eCoresColorState: SColor = .teal private var eCoresColor: NSColor { self.eCoresColorState.additional as? NSColor ?? NSColor.systemTeal } - private var pCoresColorState: Color = .secondBlue + private var pCoresColorState: SColor = .secondBlue private var pCoresColor: NSColor { self.pCoresColorState.additional as? NSColor ?? NSColor.systemBlue } public override func load() { @@ -73,11 +73,11 @@ public class Portal: PortalWrapper { } public func loadColors() { - self.systemColorState = Color.fromString(Store.shared.string(key: "\(self.name)_systemColor", defaultValue: self.systemColorState.key)) - self.userColorState = Color.fromString(Store.shared.string(key: "\(self.name)_userColor", defaultValue: self.userColorState.key)) - self.idleColorState = Color.fromString(Store.shared.string(key: "\(self.name)_idleColor", defaultValue: self.idleColorState.key)) - self.eCoresColorState = Color.fromString(Store.shared.string(key: "\(self.name)_eCoresColor", defaultValue: self.eCoresColorState.key)) - self.pCoresColorState = Color.fromString(Store.shared.string(key: "\(self.name)_pCoresColor", defaultValue: self.pCoresColorState.key)) + self.systemColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_systemColor", defaultValue: self.systemColorState.key)) + self.userColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_userColor", defaultValue: self.userColorState.key)) + self.idleColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_idleColor", defaultValue: self.idleColorState.key)) + self.eCoresColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_eCoresColor", defaultValue: self.eCoresColorState.key)) + self.pCoresColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_pCoresColor", defaultValue: self.pCoresColorState.key)) } private func charts() -> NSView { diff --git a/Modules/CPU/widget.swift b/Modules/CPU/widget.swift index 099e8368..afc174fa 100644 --- a/Modules/CPU/widget.swift +++ b/Modules/CPU/widget.swift @@ -12,6 +12,7 @@ import SwiftUI import WidgetKit import Charts +import Kit public struct CPU_entry: TimelineEntry { public static let kind = "CPUWidget" @@ -61,9 +62,9 @@ public struct CPUWidget: Widget { if let value = entry.value { HStack { Chart { - SectorMark(angle: .value("System load", value.systemLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.systemColor) - SectorMark(angle: .value("User load", value.userLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.userColor) - SectorMark(angle: .value("Idle", value.idleLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.idleColor) + SectorMark(angle: .value(localizedString("System"), value.systemLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.systemColor) + SectorMark(angle: .value(localizedString("User"), value.userLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.userColor) + SectorMark(angle: .value(localizedString("Idle"), value.idleLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.idleColor) } .frame(maxWidth: .infinity, maxHeight: 84) .chartLegend(.hidden) @@ -81,17 +82,13 @@ public struct CPUWidget: Widget { VStack(spacing: 3) { HStack { Rectangle().fill(self.systemColor).frame(width: 12, height: 12).cornerRadius(2) - Text("System:") - .font(.system(size: 12, weight: .regular)) - .foregroundColor(.secondary) + Text(localizedString("System")).font(.system(size: 12, weight: .regular)).foregroundColor(.secondary) Spacer() Text("\(Int(value.systemLoad*100))%") } HStack { Rectangle().fill(self.userColor).frame(width: 12, height: 12).cornerRadius(2) - Text("User:") - .font(.system(size: 12, weight: .regular)) - .foregroundColor(.secondary) + Text(localizedString("User")).font(.system(size: 12, weight: .regular)).foregroundColor(.secondary) Spacer() Text("\(Int(value.userLoad*100))%") } diff --git a/Modules/Clock/main.swift b/Modules/Clock/main.swift index 91bad425..9955fc23 100644 --- a/Modules/Clock/main.swift +++ b/Modules/Clock/main.swift @@ -105,7 +105,7 @@ public class Clock: Module { self.portalView.callback(clocks) }) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as StackWidget: widget.setValues(widgetList) default: break diff --git a/Modules/Clock/popup.swift b/Modules/Clock/popup.swift index 8ec1b4e0..a00ab7e9 100644 --- a/Modules/Clock/popup.swift +++ b/Modules/Clock/popup.swift @@ -165,7 +165,7 @@ private class ClockView: NSStackView { } internal class ClockChart: NSView { - private var color: NSColor = Color.systemAccent.additional as! NSColor + private var color: NSColor = SColor.systemAccent.additional as! NSColor private let calendar = Calendar.current private var hour: Int = 0 diff --git a/Modules/Disk/main.swift b/Modules/Disk/main.swift index e4a0e1d0..1f7746c3 100644 --- a/Modules/Disk/main.swift +++ b/Modules/Disk/main.swift @@ -253,7 +253,7 @@ public class Disk: Module { self.portalView.utilizationCallback(d) self.notificationsView.utilizationCallback(d.percentage) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as Mini: widget.setValue(d.percentage) case let widget as BarChart: widget.setValue([[ColorValue(d.percentage)]]) @@ -281,7 +281,7 @@ public class Disk: Module { self.portalView.activityCallback(d) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as SpeedWidget: widget.setValue(upload: d.activity.write, download: d.activity.read) diff --git a/Modules/Disk/popup.swift b/Modules/Disk/popup.swift index 4b9e61cb..b7bf37fb 100644 --- a/Modules/Disk/popup.swift +++ b/Modules/Disk/popup.swift @@ -15,9 +15,9 @@ import Kit internal class Popup: PopupWrapper { private var title: String - private var readColorState: Color = .secondBlue + private var readColorState: SColor = .secondBlue private var readColor: NSColor { self.readColorState.additional as? NSColor ?? NSColor.systemRed } - private var writeColorState: Color = .secondRed + private var writeColorState: SColor = .secondRed private var writeColor: NSColor { self.writeColorState.additional as? NSColor ?? NSColor.systemBlue } private var reverseOrderState: Bool = false @@ -44,8 +44,8 @@ internal class Popup: PopupWrapper { super.init(frame: NSRect(x: 0, y: 0, width: Constants.Popup.width, height: 0)) - self.readColorState = Color.fromString(Store.shared.string(key: "\(self.title)_readColor", defaultValue: self.readColorState.key)) - self.writeColorState = Color.fromString(Store.shared.string(key: "\(self.title)_writeColor", defaultValue: self.writeColorState.key)) + self.readColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_readColor", defaultValue: self.readColorState.key)) + self.writeColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_writeColor", defaultValue: self.writeColorState.key)) self.reverseOrderState = Store.shared.bool(key: "\(self.title)_reverseOrder", defaultValue: self.reverseOrderState) self.orientation = .vertical @@ -175,12 +175,12 @@ internal class Popup: PopupWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("Write color"), component: selectView( action: #selector(self.toggleWriteColor), - items: Color.allColors, + items: SColor.allColors, selected: self.writeColorState.key )), PreferencesRow(localizedString("Read color"), component: selectView( action: #selector(self.toggleReadColor), - items: Color.allColors, + items: SColor.allColors, selected: self.readColorState.key )) ])) @@ -197,7 +197,7 @@ internal class Popup: PopupWrapper { @objc private func toggleWriteColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.writeColorState = newValue @@ -211,7 +211,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleReadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.readColorState = newValue @@ -334,10 +334,10 @@ internal class NameView: NSStackView { private var writeState: NSView? = nil private var readColor: NSColor { - Color.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_readColor", defaultValue: Color.secondBlue.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_readColor", defaultValue: SColor.secondBlue.key)).additional as! NSColor } private var writeColor: NSColor { - Color.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_writeColor", defaultValue: Color.secondRed.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_writeColor", defaultValue: SColor.secondRed.key)).additional as! NSColor } public init(width: CGFloat, name: String, size: Int64, free: Int64, path: URL?) { @@ -443,10 +443,10 @@ internal class ChartView: NSStackView { private var ready: Bool = false private var readColor: NSColor { - Color.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_readColor", defaultValue: Color.secondBlue.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_readColor", defaultValue: SColor.secondBlue.key)).additional as! NSColor } private var writeColor: NSColor { - Color.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_writeColor", defaultValue: Color.secondRed.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(ModuleType.disk.rawValue)_writeColor", defaultValue: SColor.secondRed.key)).additional as! NSColor } private var reverseOrder: Bool { Store.shared.bool(key: "\(ModuleType.disk.rawValue)_reverseOrder", defaultValue: false) diff --git a/Modules/Disk/portal.swift b/Modules/Disk/portal.swift index 28916db0..89d3514e 100644 --- a/Modules/Disk/portal.swift +++ b/Modules/Disk/portal.swift @@ -20,14 +20,14 @@ public class Portal: PortalWrapper { private var usedField: NSTextField? = nil private var freeField: NSTextField? = nil - private var valueColorState: Color = .secondBlue + private var valueColorState: SColor = .secondBlue private var valueColor: NSColor { self.valueColorState.additional as? NSColor ?? NSColor.systemBlue } private var readColor: NSColor { - Color.fromString(Store.shared.string(key: "\(self.name)_readColor", defaultValue: Color.secondBlue.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(self.name)_readColor", defaultValue: SColor.secondBlue.key)).additional as! NSColor } private var writeColor: NSColor { - Color.fromString(Store.shared.string(key: "\(self.name)_writeColor", defaultValue: Color.secondRed.key)).additional as! NSColor + SColor.fromString(Store.shared.string(key: "\(self.name)_writeColor", defaultValue: SColor.secondRed.key)).additional as! NSColor } private var initialized: Bool = false @@ -58,7 +58,7 @@ public class Portal: PortalWrapper { } private func loadColors() { - self.valueColorState = Color.fromString(Store.shared.string(key: "\(self.name)_valueColor", defaultValue: self.valueColorState.key)) + self.valueColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_valueColor", defaultValue: self.valueColorState.key)) } private func charts() -> NSView { diff --git a/Modules/GPU/main.swift b/Modules/GPU/main.swift index 2c7ad278..0bcb59e1 100644 --- a/Modules/GPU/main.swift +++ b/Modules/GPU/main.swift @@ -129,7 +129,7 @@ public class GPU: Module { self.portalView.callback(selectedGPU) self.notificationsView.usageCallback(utilization) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as Mini: widget.setValue(utilization) diff --git a/Modules/Net/main.swift b/Modules/Net/main.swift index f0c99d13..4c0fca41 100644 --- a/Modules/Net/main.swift +++ b/Modules/Net/main.swift @@ -228,7 +228,7 @@ public class Network: Module { } } - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as SpeedWidget: widget.setValue(upload: upload, download: download) case let widget as NetworkChart: widget.setValue(upload: Double(upload), download: Double(download)) @@ -242,7 +242,7 @@ public class Network: Module { self.popupView.connectivityCallback(value) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as StateWidget: widget.setValue(value.status) default: break diff --git a/Modules/Net/popup.swift b/Modules/Net/popup.swift index 20a28e6a..ef1b32a2 100644 --- a/Modules/Net/popup.swift +++ b/Modules/Net/popup.swift @@ -79,7 +79,7 @@ internal class Popup: PopupWrapper { (22*CGFloat(self.numberOfProcesses)) + (self.numberOfProcesses == 0 ? 0 : Constants.Popup.separatorHeight + 22) } - private var downloadColorState: Color = .secondBlue + private var downloadColorState: SColor = .secondBlue private var downloadColor: NSColor { var value = NSColor.systemBlue if let color = self.downloadColorState.additional as? NSColor { @@ -87,7 +87,7 @@ internal class Popup: PopupWrapper { } return value } - private var uploadColorState: Color = .secondRed + private var uploadColorState: SColor = .secondRed private var uploadColor: NSColor { var value = NSColor.systemRed if let color = self.uploadColorState.additional as? NSColor { @@ -108,8 +108,8 @@ internal class Popup: PopupWrapper { height: 0 )) - self.downloadColorState = Color.fromString(Store.shared.string(key: "\(self.title)_downloadColor", defaultValue: self.downloadColorState.key)) - self.uploadColorState = Color.fromString(Store.shared.string(key: "\(self.title)_uploadColor", defaultValue: self.uploadColorState.key)) + self.downloadColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_downloadColor", defaultValue: self.downloadColorState.key)) + self.uploadColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_uploadColor", defaultValue: self.uploadColorState.key)) self.reverseOrderState = Store.shared.bool(key: "\(self.title)_reverseOrder", defaultValue: self.reverseOrderState) self.chartHistory = Store.shared.int(key: "\(self.title)_chartHistory", defaultValue: self.chartHistory) self.chartScale = Scale.fromString(Store.shared.string(key: "\(self.title)_chartScale", defaultValue: self.chartScale.key)) @@ -517,12 +517,12 @@ internal class Popup: PopupWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("Color of upload"), component: selectView( action: #selector(self.toggleUploadColor), - items: Color.allColors, + items: SColor.allColors, selected: self.uploadColorState.key )), PreferencesRow(localizedString("Color of download"), component: selectView( action: #selector(self.toggleDownloadColor), - items: Color.allColors, + items: SColor.allColors, selected: self.downloadColorState.key )) ])) @@ -566,7 +566,7 @@ internal class Popup: PopupWrapper { @objc private func toggleUploadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.uploadColorState = newValue @@ -580,7 +580,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleDownloadColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.downloadColorState = newValue diff --git a/Modules/Net/portal.swift b/Modules/Net/portal.swift index 8fcc7f34..7fbf62f0 100644 --- a/Modules/Net/portal.swift +++ b/Modules/Net/portal.swift @@ -34,7 +34,7 @@ public class Portal: PortalWrapper { } private var downloadColor: NSColor { - let v = Color.fromString(Store.shared.string(key: "\(self.name)_downloadColor", defaultValue: Color.secondBlue.key)) + let v = SColor.fromString(Store.shared.string(key: "\(self.name)_downloadColor", defaultValue: SColor.secondBlue.key)) var value = NSColor.systemBlue if let color = v.additional as? NSColor { value = color @@ -42,7 +42,7 @@ public class Portal: PortalWrapper { return value } private var uploadColor: NSColor { - let v = Color.fromString(Store.shared.string(key: "\(self.name)_uploadColor", defaultValue: Color.secondRed.key)) + let v = SColor.fromString(Store.shared.string(key: "\(self.name)_uploadColor", defaultValue: SColor.secondRed.key)) var value = NSColor.systemRed if let color = v.additional as? NSColor { value = color diff --git a/Modules/RAM/main.swift b/Modules/RAM/main.swift index ae1c558b..ea7b6e97 100644 --- a/Modules/RAM/main.swift +++ b/Modules/RAM/main.swift @@ -30,9 +30,7 @@ public struct RAM_Usage: Codable { var swap: Swap public var usage: Double { - get { - return Double((self.total - self.free) / self.total) - } + get { Double((self.total - self.free) / self.total) } } public var pressureLevel: DispatchSource.MemoryPressureEvent { @@ -59,25 +57,25 @@ public class RAM: Module { return Store.shared.bool(key: "\(self.config.name)_splitValue", defaultValue: false) } private var appColor: NSColor { - let color = Color.secondBlue + let color = SColor.secondBlue let key = Store.shared.string(key: "\(self.config.name)_appColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor } private var wiredColor: NSColor { - let color = Color.secondOrange + let color = SColor.secondOrange let key = Store.shared.string(key: "\(self.config.name)_wiredColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor } private var compressedColor: NSColor { - let color = Color.pink + let color = SColor.pink let key = Store.shared.string(key: "\(self.config.name)_compressedColor", defaultValue: color.key) - if let c = Color.fromString(key).additional as? NSColor { + if let c = SColor.fromString(key).additional as? NSColor { return c } return color.additional as! NSColor @@ -135,7 +133,7 @@ public class RAM: Module { self.notificationsView.loadCallback(value) let total: Double = value.total == 0 ? 1 : value.total - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as Mini: widget.setValue(value.usage) diff --git a/Modules/RAM/popup.swift b/Modules/RAM/popup.swift index 8f144ff0..88d8bfdb 100644 --- a/Modules/RAM/popup.swift +++ b/Modules/RAM/popup.swift @@ -57,15 +57,15 @@ internal class Popup: PopupWrapper { private var lineChartFixedScale: Double = 1 private var chartPrefSection: PreferencesSection? = nil - private var appColorState: Color = .secondBlue + private var appColorState: SColor = .secondBlue private var appColor: NSColor { self.appColorState.additional as? NSColor ?? NSColor.systemRed } - private var wiredColorState: Color = .secondOrange + private var wiredColorState: SColor = .secondOrange private var wiredColor: NSColor { self.wiredColorState.additional as? NSColor ?? NSColor.systemBlue } - private var compressedColorState: Color = .pink + private var compressedColorState: SColor = .pink private var compressedColor: NSColor { self.compressedColorState.additional as? NSColor ?? NSColor.lightGray } - private var freeColorState: Color = .lightGray + private var freeColorState: SColor = .lightGray private var freeColor: NSColor { self.freeColorState.additional as? NSColor ?? NSColor.systemBlue } - private var chartColorState: Color = .systemAccent + private var chartColorState: SColor = .systemAccent private var chartColor: NSColor { self.chartColorState.additional as? NSColor ?? NSColor.systemBlue } public init(_ module: ModuleType) { @@ -79,11 +79,11 @@ internal class Popup: PopupWrapper { )) self.setFrameSize(NSSize(width: self.frame.width, height: self.frame.height+self.processesHeight)) - self.appColorState = Color.fromString(Store.shared.string(key: "\(self.title)_appColor", defaultValue: self.appColorState.key)) - self.wiredColorState = Color.fromString(Store.shared.string(key: "\(self.title)_wiredColor", defaultValue: self.wiredColorState.key)) - self.compressedColorState = Color.fromString(Store.shared.string(key: "\(self.title)_compressedColor", defaultValue: self.compressedColorState.key)) - self.freeColorState = Color.fromString(Store.shared.string(key: "\(self.title)_freeColor", defaultValue: self.freeColorState.key)) - self.chartColorState = Color.fromString(Store.shared.string(key: "\(self.title)_chartColor", defaultValue: self.chartColorState.key)) + self.appColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_appColor", defaultValue: self.appColorState.key)) + self.wiredColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_wiredColor", defaultValue: self.wiredColorState.key)) + self.compressedColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_compressedColor", defaultValue: self.compressedColorState.key)) + self.freeColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_freeColor", defaultValue: self.freeColorState.key)) + self.chartColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_chartColor", defaultValue: self.chartColorState.key)) self.lineChartHistory = Store.shared.int(key: "\(self.title)_lineChartHistory", defaultValue: self.lineChartHistory) self.lineChartScale = Scale.fromString(Store.shared.string(key: "\(self.title)_lineChartScale", defaultValue: self.lineChartScale.key)) self.lineChartFixedScale = Double(Store.shared.int(key: "\(self.title)_lineChartFixedScale", defaultValue: 100)) / 100 @@ -288,22 +288,22 @@ internal class Popup: PopupWrapper { view.addArrangedSubview(PreferencesSection([ PreferencesRow(localizedString("App color"), component: selectView( action: #selector(toggleAppColor), - items: Color.allColors, + items: SColor.allColors, selected: self.appColorState.key )), PreferencesRow(localizedString("Wired color"), component: selectView( action: #selector(toggleWiredColor), - items: Color.allColors, + items: SColor.allColors, selected: self.wiredColorState.key )), PreferencesRow(localizedString("Compressed color"), component: selectView( action: #selector(toggleCompressedColor), - items: Color.allColors, + items: SColor.allColors, selected: self.compressedColorState.key )), PreferencesRow(localizedString("Free color"), component: selectView( action: #selector(toggleFreeColor), - items: Color.allColors, + items: SColor.allColors, selected: self.freeColorState.key )) ])) @@ -316,7 +316,7 @@ internal class Popup: PopupWrapper { self.chartPrefSection = PreferencesSection([ PreferencesRow(localizedString("Chart color"), component: selectView( action: #selector(self.toggleChartColor), - items: Color.allColors, + items: SColor.allColors, selected: self.chartColorState.key )), PreferencesRow(localizedString("Chart history"), component: selectView( @@ -339,7 +339,7 @@ internal class Popup: PopupWrapper { @objc private func toggleAppColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.appColorState = newValue @@ -350,7 +350,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleWiredColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.wiredColorState = newValue @@ -361,7 +361,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleCompressedColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.compressedColorState = newValue @@ -372,7 +372,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleFreeColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.freeColorState = newValue @@ -383,7 +383,7 @@ internal class Popup: PopupWrapper { } @objc private func toggleChartColor(_ sender: NSMenuItem) { guard let key = sender.representedObject as? String, - let newValue = Color.allColors.first(where: { $0.key == key }) else { + let newValue = SColor.allColors.first(where: { $0.key == key }) else { return } self.chartColorState = newValue diff --git a/Modules/RAM/portal.swift b/Modules/RAM/portal.swift index 341676b3..6acd7c44 100644 --- a/Modules/RAM/portal.swift +++ b/Modules/RAM/portal.swift @@ -22,13 +22,13 @@ public class Portal: PortalWrapper { private var initialized: Bool = false - private var appColorState: Color = .secondBlue + private var appColorState: SColor = .secondBlue private var appColor: NSColor { self.appColorState.additional as? NSColor ?? NSColor.systemRed } - private var wiredColorState: Color = .secondOrange + private var wiredColorState: SColor = .secondOrange private var wiredColor: NSColor { self.wiredColorState.additional as? NSColor ?? NSColor.systemBlue } - private var compressedColorState: Color = .pink + private var compressedColorState: SColor = .pink private var compressedColor: NSColor { self.compressedColorState.additional as? NSColor ?? NSColor.lightGray } - private var freeColorState: Color = .lightGray + private var freeColorState: SColor = .lightGray private var freeColor: NSColor { self.freeColorState.additional as? NSColor ?? NSColor.systemBlue } public override func load() { @@ -57,10 +57,10 @@ public class Portal: PortalWrapper { } public func loadColors() { - self.appColorState = Color.fromString(Store.shared.string(key: "\(self.name)_appColor", defaultValue: self.appColorState.key)) - self.wiredColorState = Color.fromString(Store.shared.string(key: "\(self.name)_wiredColor", defaultValue: self.wiredColorState.key)) - self.compressedColorState = Color.fromString(Store.shared.string(key: "\(self.name)_compressedColor", defaultValue: self.compressedColorState.key)) - self.freeColorState = Color.fromString(Store.shared.string(key: "\(self.name)_freeColor", defaultValue: self.freeColorState.key)) + self.appColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_appColor", defaultValue: self.appColorState.key)) + self.wiredColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_wiredColor", defaultValue: self.wiredColorState.key)) + self.compressedColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_compressedColor", defaultValue: self.compressedColorState.key)) + self.freeColorState = SColor.fromString(Store.shared.string(key: "\(self.name)_freeColor", defaultValue: self.freeColorState.key)) } private func charts() -> NSView { diff --git a/Modules/Sensors/main.swift b/Modules/Sensors/main.swift index 87e8afcb..fc35fc26 100644 --- a/Modules/Sensors/main.swift +++ b/Modules/Sensors/main.swift @@ -120,7 +120,7 @@ public class Sensors: Module { self.portalView.usageCallback(value.sensors) self.notificationsView.usageCallback(value.sensors) - self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in + self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: SWidget) in switch w.item { case let widget as StackWidget: widget.setValues(list) case let widget as BarChart: widget.setValue(flatList)