mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: add colors translation
This commit is contained in:
@@ -16,9 +16,9 @@ public class BarChart: WidgetWrapper {
|
||||
private var labelState: Bool = false
|
||||
private var boxState: Bool = true
|
||||
private var frameState: Bool = false
|
||||
private var colorState: widget_c = .systemAccent
|
||||
private var colorState: Color = .systemAccent
|
||||
|
||||
private var colors: [widget_c] = widget_c.allCases
|
||||
private var colors: [Color] = Color.allCases
|
||||
private var value: [Double] = []
|
||||
private var pressureLevel: Int = 0
|
||||
private var colorZones: colorZones = (0.6, 0.8)
|
||||
@@ -50,10 +50,8 @@ public class BarChart: WidgetWrapper {
|
||||
if let box = configuration["Box"] as? Bool {
|
||||
self.boxState = box
|
||||
}
|
||||
if let colorsToDisable = configuration["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter { (color: widget_c) -> Bool in
|
||||
return !colorsToDisable.contains("\(color.self)")
|
||||
}
|
||||
if let unsupportedColors = configuration["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter{ !unsupportedColors.contains($0.key) }
|
||||
}
|
||||
if let color = configuration["Color"] as? String {
|
||||
if let defaultColor = colors.first(where: { "\($0.self)" == color }) {
|
||||
@@ -75,7 +73,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 = widget_c(rawValue: Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.rawValue)) ?? self.colorState
|
||||
self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key))
|
||||
}
|
||||
|
||||
if preview {
|
||||
@@ -185,7 +183,7 @@ public class BarChart: WidgetWrapper {
|
||||
} else {
|
||||
(isDarkMode ? NSColor.white : NSColor.black).set()
|
||||
}
|
||||
default: colorFromString("\(self.colorState.self)").set()
|
||||
default: (self.colorState.additional as? NSColor ?? NSColor.controlAccentColor).set()
|
||||
}
|
||||
|
||||
partition.fill()
|
||||
@@ -273,12 +271,12 @@ public class BarChart: WidgetWrapper {
|
||||
)
|
||||
view.addSubview(self.frameSettingsView!)
|
||||
|
||||
view.addSubview(SelectColorRow(
|
||||
view.addSubview(SelectRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 0, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Color"),
|
||||
action: #selector(toggleColor),
|
||||
items: self.colors.map{ $0.rawValue },
|
||||
selected: self.colorState.rawValue
|
||||
items: self.colors,
|
||||
selected: self.colorState.key
|
||||
))
|
||||
|
||||
return view
|
||||
@@ -335,10 +333,14 @@ public class BarChart: WidgetWrapper {
|
||||
}
|
||||
|
||||
@objc private func toggleColor(_ sender: NSMenuItem) {
|
||||
if let newColor = widget_c.allCases.first(where: { $0.rawValue == sender.title }) {
|
||||
self.colorState = newColor
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: self.colorState.rawValue)
|
||||
self.display()
|
||||
guard let key = sender.representedObject as? String else {
|
||||
return
|
||||
}
|
||||
if let newColor = Color.allCases.first(where: { $0.key == key }) {
|
||||
self.colorState = newColor
|
||||
}
|
||||
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key)
|
||||
self.display()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LineChart: WidgetWrapper {
|
||||
private var frameState: Bool = false
|
||||
private var valueState: Bool = false
|
||||
private var valueColorState: Bool = false
|
||||
private var colorState: widget_c = .systemAccent
|
||||
private var colorState: Color = .systemAccent
|
||||
|
||||
private let width: CGFloat = 34
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LineChart: WidgetWrapper {
|
||||
width: 34,
|
||||
height: Constants.Widget.height - (2*Constants.Widget.margin.y)
|
||||
), num: 60)
|
||||
private var colors: [widget_c] = widget_c.allCases
|
||||
private var colors: [Color] = Color.allCases
|
||||
private var value: Double = 0
|
||||
private var pressureLevel: Int = 0
|
||||
|
||||
@@ -50,10 +50,8 @@ public class LineChart: WidgetWrapper {
|
||||
if let value = config!["Value"] as? Bool {
|
||||
self.valueState = value
|
||||
}
|
||||
if let colorsToDisable = config!["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter { (color: widget_c) -> Bool in
|
||||
return !colorsToDisable.contains("\(color.self)")
|
||||
}
|
||||
if let unsupportedColors = config!["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter{ !unsupportedColors.contains($0.key) }
|
||||
}
|
||||
if let color = config!["Color"] as? String {
|
||||
if let defaultColor = colors.first(where: { "\($0.self)" == color }) {
|
||||
@@ -77,7 +75,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 = widget_c(rawValue: Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.rawValue)) ?? self.colorState
|
||||
self.colorState = Color.fromString(Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.key))
|
||||
}
|
||||
|
||||
if self.labelState {
|
||||
@@ -120,7 +118,7 @@ public class LineChart: WidgetWrapper {
|
||||
} else {
|
||||
color = (isDarkMode ? NSColor.white : NSColor.black)
|
||||
}
|
||||
default: color = colorFromString("\(self.colorState.self)")
|
||||
default: color = self.colorState.additional as? NSColor ?? NSColor.controlAccentColor
|
||||
}
|
||||
|
||||
if self.labelState {
|
||||
@@ -287,12 +285,12 @@ public class LineChart: WidgetWrapper {
|
||||
)
|
||||
view.addSubview(self.frameSettingsView!)
|
||||
|
||||
view.addSubview(SelectColorRow(
|
||||
view.addSubview(SelectRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 1, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Color"),
|
||||
action: #selector(toggleColor),
|
||||
items: self.colors.map{ $0.rawValue },
|
||||
selected: self.colorState.rawValue
|
||||
items: self.colors,
|
||||
selected: self.colorState.key
|
||||
))
|
||||
|
||||
view.addSubview(ToggleTitleRow(
|
||||
@@ -368,11 +366,15 @@ public class LineChart: WidgetWrapper {
|
||||
}
|
||||
|
||||
@objc private func toggleColor(_ sender: NSMenuItem) {
|
||||
if let newColor = widget_c.allCases.first(where: { $0.rawValue == sender.title }) {
|
||||
self.colorState = newColor
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: self.colorState.rawValue)
|
||||
self.display()
|
||||
guard let key = sender.representedObject as? String else {
|
||||
return
|
||||
}
|
||||
if let newColor = Color.allCases.first(where: { $0.key == key }) {
|
||||
self.colorState = newColor
|
||||
}
|
||||
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key)
|
||||
self.display()
|
||||
}
|
||||
|
||||
@objc private func toggleValueColor(_ sender: NSControl) {
|
||||
|
||||
@@ -16,13 +16,13 @@ public class Mini: WidgetWrapper {
|
||||
private let defaultTitle: String
|
||||
|
||||
private var labelState: Bool = true
|
||||
private var colorState: widget_c = .monochrome
|
||||
private var colorState: Color = .monochrome
|
||||
|
||||
private var labelLayer: CATextLayer? = nil
|
||||
private var valueLayer: CATextLayer? = nil
|
||||
|
||||
private let onlyValueWidth: CGFloat = 40
|
||||
private var colors: [widget_c] = widget_c.allCases
|
||||
private var colors: [Color] = Color.allCases
|
||||
|
||||
private var value: Double = 0
|
||||
private var pressureLevel: Int = 0
|
||||
@@ -53,10 +53,8 @@ public class Mini: WidgetWrapper {
|
||||
if let label = configuration["Label"] as? Bool {
|
||||
self.labelState = label
|
||||
}
|
||||
if let colorsToDisable = configuration["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter { (color: widget_c) -> Bool in
|
||||
return !colorsToDisable.contains("\(color.self)")
|
||||
}
|
||||
if let unsupportedColors = configuration["Unsupported colors"] as? [String] {
|
||||
self.colors = self.colors.filter{ !unsupportedColors.contains($0.key) }
|
||||
}
|
||||
if let color = configuration["Color"] as? String {
|
||||
if let defaultColor = colors.first(where: { "\($0.self)" == color }) {
|
||||
@@ -76,7 +74,7 @@ public class Mini: WidgetWrapper {
|
||||
self.canDrawConcurrently = true
|
||||
|
||||
if !preview {
|
||||
self.colorState = widget_c(rawValue: Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.rawValue)) ?? self.colorState
|
||||
self.colorState = Color.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)
|
||||
}
|
||||
}
|
||||
@@ -112,7 +110,7 @@ public class Mini: WidgetWrapper {
|
||||
case .utilization: color = value.usageColor()
|
||||
case .pressure: color = self.pressureLevel.pressureColor()
|
||||
case .monochrome: color = (isDarkMode ? NSColor.white : NSColor.black)
|
||||
default: color = colorFromString("\(self.colorState.self)")
|
||||
default: color = self.colorState.additional as? NSColor ?? NSColor.controlAccentColor
|
||||
}
|
||||
|
||||
let stringAttributes = [
|
||||
@@ -185,23 +183,27 @@ public class Mini: WidgetWrapper {
|
||||
state: self.labelState
|
||||
))
|
||||
|
||||
view.addSubview(SelectColorRow(
|
||||
view.addSubview(SelectRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 0, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Color"),
|
||||
action: #selector(toggleColor),
|
||||
items: self.colors.map{ $0.rawValue },
|
||||
selected: self.colorState.rawValue
|
||||
items: self.colors,
|
||||
selected: self.colorState.key
|
||||
))
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@objc private func toggleColor(_ sender: NSMenuItem) {
|
||||
if let newColor = widget_c.allCases.first(where: { $0.rawValue == sender.title }) {
|
||||
self.colorState = newColor
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: self.colorState.rawValue)
|
||||
self.display()
|
||||
guard let key = sender.representedObject as? String else {
|
||||
return
|
||||
}
|
||||
if let newColor = Color.allCases.first(where: { $0.key == key }) {
|
||||
self.colorState = newColor
|
||||
}
|
||||
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key)
|
||||
self.display()
|
||||
}
|
||||
|
||||
@objc private func toggleLabel(_ sender: NSControl) {
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
9A58DEA424B3647600716A9F /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A58DEA324B3647600716A9F /* settings.swift */; };
|
||||
9A599701261121F00043560F /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A599700261121F00043560F /* Label.swift */; };
|
||||
9A5AF11B2469CE9B00684737 /* popup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A5AF11A2469CE9B00684737 /* popup.swift */; };
|
||||
9A5F191626220D510085C3CC /* types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A5F191526220D510085C3CC /* types.swift */; };
|
||||
9A65295825B78056005E2DE4 /* NetworkChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65295725B78056005E2DE4 /* NetworkChart.swift */; };
|
||||
9A65654A253F20EF0096B607 /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A656549253F20EF0096B607 /* settings.swift */; };
|
||||
9A656562253F788A0096B607 /* popup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A656561253F788A0096B607 /* popup.swift */; };
|
||||
@@ -409,6 +410,7 @@
|
||||
9A599700261121F00043560F /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
|
||||
9A5AF11A2469CE9B00684737 /* popup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = popup.swift; sourceTree = "<group>"; };
|
||||
9A5F0503256A9135002FF75F /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
9A5F191526220D510085C3CC /* types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = types.swift; sourceTree = "<group>"; };
|
||||
9A65295725B78056005E2DE4 /* NetworkChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkChart.swift; sourceTree = "<group>"; };
|
||||
9A654920244074B500E30B74 /* extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = extensions.swift; sourceTree = "<group>"; };
|
||||
9A65492224407EA600E30B74 /* store.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = store.swift; sourceTree = "<group>"; };
|
||||
@@ -621,6 +623,7 @@
|
||||
9A0C82D324460E4400FAE3D4 /* launchAtLogin.swift */,
|
||||
9A654920244074B500E30B74 /* extensions.swift */,
|
||||
9A1D5E4A25235C8100B82BFC /* helpers.swift */,
|
||||
9A5F191526220D510085C3CC /* types.swift */,
|
||||
9A0C82DD24460F7200FAE3D4 /* Info.plist */,
|
||||
9A9D728924471FAE005CF997 /* SMC.swift */,
|
||||
9A81C76F2449B8D500825D92 /* Charts.swift */,
|
||||
@@ -1439,6 +1442,7 @@
|
||||
9A1D5E4B25235C8100B82BFC /* helpers.swift in Sources */,
|
||||
9A0C82EE2446124800FAE3D4 /* SystemKit.swift in Sources */,
|
||||
9A9D728A24471FAE005CF997 /* SMC.swift in Sources */,
|
||||
9A5F191626220D510085C3CC /* types.swift in Sources */,
|
||||
9A0C82E824460F9E00FAE3D4 /* launchAtLogin.swift in Sources */,
|
||||
9A0C82E924460F9F00FAE3D4 /* store.swift in Sources */,
|
||||
);
|
||||
|
||||
@@ -341,7 +341,7 @@ public extension NSView {
|
||||
return row
|
||||
}
|
||||
|
||||
func SelectRow(frame: NSRect, title: String, action: Selector, items: [KeyValue_t], selected: String) -> NSView {
|
||||
func SelectRow(frame: NSRect, title: String, action: Selector, items: [KeyValue_p], selected: String) -> NSView {
|
||||
let row: NSView = NSView(frame: frame)
|
||||
|
||||
let rowTitle: NSTextField = LabelField(frame: NSRect(x: 0, y: (row.frame.height - 16)/2, width: row.frame.width - 52, height: 17), title)
|
||||
@@ -360,7 +360,7 @@ public extension NSView {
|
||||
return row
|
||||
}
|
||||
|
||||
func SelectView(action: Selector, items: [KeyValue_t], selected: String) -> NSPopUpButton {
|
||||
func SelectView(action: Selector, items: [KeyValue_p], selected: String) -> NSPopUpButton {
|
||||
let select: NSPopUpButton = NSPopUpButton(frame: NSRect(x: 0, y: 0, width: 50, height: 26))
|
||||
select.target = self
|
||||
select.action = action
|
||||
@@ -384,20 +384,6 @@ public extension NSView {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Notification.Name {
|
||||
static let toggleSettings = Notification.Name("toggleSettings")
|
||||
static let toggleModule = Notification.Name("toggleModule")
|
||||
static let togglePopup = Notification.Name("togglePopup")
|
||||
static let toggleWidget = Notification.Name("toggleWidget")
|
||||
static let openModuleSettings = Notification.Name("openModuleSettings")
|
||||
static let settingsAppear = Notification.Name("settingsAppear")
|
||||
static let switchWidget = Notification.Name("switchWidget")
|
||||
static let checkForUpdates = Notification.Name("checkForUpdates")
|
||||
static let changeCronInterval = Notification.Name("changeCronInterval")
|
||||
static let clickInSettings = Notification.Name("clickInSettings")
|
||||
static let refreshPublicIP = Notification.Name("refreshPublicIP")
|
||||
}
|
||||
|
||||
public class NSButtonWithPadding: NSButton {
|
||||
public var horizontalPadding: CGFloat = 0
|
||||
public var verticalPadding: CGFloat = 0
|
||||
|
||||
@@ -12,27 +12,13 @@
|
||||
import Cocoa
|
||||
import os.log
|
||||
|
||||
public typealias AppUpdateIntervalType = String
|
||||
public enum AppUpdateInterval: AppUpdateIntervalType {
|
||||
case atStart = "At start"
|
||||
case separator_1 = "separator_1"
|
||||
case oncePerDay = "Once per day"
|
||||
case oncePerWeek = "Once per week"
|
||||
case oncePerMonth = "Once per month"
|
||||
case separator_2 = "separator_2"
|
||||
case never = "Never"
|
||||
public protocol KeyValue_p {
|
||||
var key: String { get }
|
||||
var value: String { get }
|
||||
var additional: Any? { get }
|
||||
}
|
||||
public let AppUpdateIntervals: [KeyValue_t] = [
|
||||
KeyValue_t(key: "At start", value: AppUpdateInterval.atStart.rawValue),
|
||||
KeyValue_t(key: "separator_1", value: "separator_1"),
|
||||
KeyValue_t(key: "Once per day", value: AppUpdateInterval.oncePerDay.rawValue),
|
||||
KeyValue_t(key: "Once per week", value: AppUpdateInterval.oncePerWeek.rawValue),
|
||||
KeyValue_t(key: "Once per month", value: AppUpdateInterval.oncePerMonth.rawValue),
|
||||
KeyValue_t(key: "separator_2", value: "separator_2"),
|
||||
KeyValue_t(key: "Never", value: AppUpdateInterval.never.rawValue)
|
||||
]
|
||||
|
||||
public struct KeyValue_t {
|
||||
public struct KeyValue_t: KeyValue_p {
|
||||
public let key: String
|
||||
public let value: String
|
||||
public let additional: Any?
|
||||
@@ -44,102 +30,6 @@ public struct KeyValue_t {
|
||||
}
|
||||
}
|
||||
|
||||
public let TemperatureUnits: [KeyValue_t] = [
|
||||
KeyValue_t(key: "system", value: "System"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "celsius", value: "Celsius", additional: UnitTemperature.celsius),
|
||||
KeyValue_t(key: "fahrenheit", value: "Fahrenheit", additional: UnitTemperature.fahrenheit)
|
||||
]
|
||||
|
||||
public enum DataSizeBase: String {
|
||||
case bit = "bit"
|
||||
case byte = "byte"
|
||||
}
|
||||
public let SpeedBase: [KeyValue_t] = [
|
||||
KeyValue_t(key: "bit", value: "Bit", additional: DataSizeBase.bit),
|
||||
KeyValue_t(key: "byte", value: "Byte", additional: DataSizeBase.byte)
|
||||
]
|
||||
|
||||
public let SensorsWidgetMode: [KeyValue_t] = [
|
||||
KeyValue_t(key: "automatic", value: "Automatic"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "oneRow", value: "One row"),
|
||||
KeyValue_t(key: "twoRows", value: "Two rows"),
|
||||
]
|
||||
|
||||
public let SpeedPictogram: [KeyValue_t] = [
|
||||
KeyValue_t(key: "none", value: "None"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "dots", value: "Dots"),
|
||||
KeyValue_t(key: "arrows", value: "Arrows"),
|
||||
KeyValue_t(key: "chars", value: "Characters"),
|
||||
]
|
||||
|
||||
public let BatteryAdditionals: [KeyValue_t] = [
|
||||
KeyValue_t(key: "none", value: "None"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "percentage", value: "Percentage"),
|
||||
KeyValue_t(key: "time", value: "Time"),
|
||||
KeyValue_t(key: "percentageAndTime", value: "Percentage and time"),
|
||||
KeyValue_t(key: "timeAndPercentage", value: "Time and percentage"),
|
||||
]
|
||||
|
||||
public let ShortLong: [KeyValue_t] = [
|
||||
KeyValue_t(key: "short", value: "Short"),
|
||||
KeyValue_t(key: "long", value: "Long"),
|
||||
]
|
||||
|
||||
public let ReaderUpdateIntervals: [Int] = [1, 2, 3, 5, 10, 15, 30]
|
||||
public let NumbersOfProcesses: [Int] = [0, 3, 5, 8, 10, 15]
|
||||
|
||||
public typealias Bandwidth = (upload: Int64, download: Int64)
|
||||
public let NetworkReaders: [KeyValue_t] = [
|
||||
KeyValue_t(key: "interface", value: "Interface based"),
|
||||
KeyValue_t(key: "process", value: "Processes based"),
|
||||
]
|
||||
|
||||
public enum widget_c: String {
|
||||
case utilization = "Based on utilization"
|
||||
case pressure = "Based on pressure"
|
||||
|
||||
case separator_1 = "separator_1"
|
||||
|
||||
case systemAccent = "System accent"
|
||||
case monochrome = "Monochrome accent"
|
||||
|
||||
case separator_2 = "separator_2"
|
||||
|
||||
case clear = "Clear"
|
||||
case white = "White"
|
||||
case black = "Black"
|
||||
case gray = "Gray"
|
||||
case secondGray = "Second gray"
|
||||
case darkGray = "Dark gray"
|
||||
case lightGray = "Light gray"
|
||||
case red = "Red"
|
||||
case secondRed = "Second red"
|
||||
case green = "Green"
|
||||
case secondGreen = "Second green"
|
||||
case blue = "Blue"
|
||||
case secondBlue = "Second blue"
|
||||
case yellow = "Yellow"
|
||||
case secondYellow = "Second yellow"
|
||||
case orange = "Orange"
|
||||
case secondOrange = "Second orange"
|
||||
case purple = "Purple"
|
||||
case secondPurple = "Second purple"
|
||||
case brown = "Brown"
|
||||
case secondBrown = "Second brown"
|
||||
case cyan = "Cyan"
|
||||
case magenta = "Magenta"
|
||||
case pink = "Pink"
|
||||
case teal = "Teal"
|
||||
case indigo = "Indigo"
|
||||
}
|
||||
extension widget_c: CaseIterable {}
|
||||
|
||||
public typealias colorZones = (orange: Double, red: Double)
|
||||
|
||||
public struct Units {
|
||||
public let bytes: Int64
|
||||
|
||||
@@ -457,69 +347,6 @@ public func syncShell(_ args: String) -> String {
|
||||
return output
|
||||
}
|
||||
|
||||
public func colorFromString(_ colorString: String) -> NSColor {
|
||||
switch colorString {
|
||||
case "black":
|
||||
return NSColor.black
|
||||
case "darkGray":
|
||||
return NSColor.darkGray
|
||||
case "lightGray":
|
||||
return NSColor.lightGray
|
||||
case "gray":
|
||||
return NSColor.gray
|
||||
case "secondGray":
|
||||
return NSColor.systemGray
|
||||
case "white":
|
||||
return NSColor.white
|
||||
case "red":
|
||||
return NSColor.red
|
||||
case "secondRed":
|
||||
return NSColor.systemRed
|
||||
case "green":
|
||||
return NSColor.green
|
||||
case "secondGreen":
|
||||
return NSColor.systemGreen
|
||||
case "blue":
|
||||
return NSColor.blue
|
||||
case "secondBlue":
|
||||
return NSColor.systemBlue
|
||||
case "yellow":
|
||||
return NSColor.yellow
|
||||
case "secondYellow":
|
||||
return NSColor.systemYellow
|
||||
case "orange":
|
||||
return NSColor.orange
|
||||
case "secondOrange":
|
||||
return NSColor.systemOrange
|
||||
case "purple":
|
||||
return NSColor.purple
|
||||
case "secondPurple":
|
||||
return NSColor.systemPurple
|
||||
case "brown":
|
||||
return NSColor.brown
|
||||
case "secondBrown":
|
||||
return NSColor.systemBrown
|
||||
case "cyan":
|
||||
return NSColor.cyan
|
||||
case "magenta":
|
||||
return NSColor.magenta
|
||||
case "clear":
|
||||
return NSColor.clear
|
||||
case "pink":
|
||||
return NSColor.systemPink
|
||||
case "teal":
|
||||
return NSColor.systemTeal
|
||||
case "indigo":
|
||||
if #available(OSX 10.15, *) {
|
||||
return NSColor.systemIndigo
|
||||
} else {
|
||||
return NSColor(hexString: "#4B0082")
|
||||
}
|
||||
default:
|
||||
return NSColor.controlAccentColor
|
||||
}
|
||||
}
|
||||
|
||||
public func IsNewestVersion(currentVersion: String, latestVersion: String) -> Bool {
|
||||
let currentNumber = currentVersion.replacingOccurrences(of: "v", with: "")
|
||||
let latestNumber = latestVersion.replacingOccurrences(of: "v", with: "")
|
||||
|
||||
@@ -14,7 +14,7 @@ import ServiceManagement
|
||||
|
||||
public struct LaunchAtLogin {
|
||||
private static let id = "\(Bundle.main.bundleIdentifier!).LaunchAtLogin"
|
||||
|
||||
|
||||
public static var isEnabled: Bool {
|
||||
get {
|
||||
guard let jobs = (SMCopyAllJobDictionaries(kSMDomainUserLaunchd).takeRetainedValue() as? [[String: AnyObject]]) else {
|
||||
|
||||
168
StatsKit/types.swift
Normal file
168
StatsKit/types.swift
Normal file
@@ -0,0 +1,168 @@
|
||||
//
|
||||
// types.swift
|
||||
// StatsKit
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 10/04/2021.
|
||||
// Using Swift 5.0.
|
||||
// Running on macOS 10.15.
|
||||
//
|
||||
// Copyright © 2021 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
public enum AppUpdateInterval: String {
|
||||
case atStart = "At start"
|
||||
case separator_1 = "separator_1"
|
||||
case oncePerDay = "Once per day"
|
||||
case oncePerWeek = "Once per week"
|
||||
case oncePerMonth = "Once per month"
|
||||
case separator_2 = "separator_2"
|
||||
case never = "Never"
|
||||
}
|
||||
public let AppUpdateIntervals: [KeyValue_t] = [
|
||||
KeyValue_t(key: "At start", value: AppUpdateInterval.atStart.rawValue),
|
||||
KeyValue_t(key: "separator_1", value: "separator_1"),
|
||||
KeyValue_t(key: "Once per day", value: AppUpdateInterval.oncePerDay.rawValue),
|
||||
KeyValue_t(key: "Once per week", value: AppUpdateInterval.oncePerWeek.rawValue),
|
||||
KeyValue_t(key: "Once per month", value: AppUpdateInterval.oncePerMonth.rawValue),
|
||||
KeyValue_t(key: "separator_2", value: "separator_2"),
|
||||
KeyValue_t(key: "Never", value: AppUpdateInterval.never.rawValue)
|
||||
]
|
||||
|
||||
public let TemperatureUnits: [KeyValue_t] = [
|
||||
KeyValue_t(key: "system", value: "System"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "celsius", value: "Celsius", additional: UnitTemperature.celsius),
|
||||
KeyValue_t(key: "fahrenheit", value: "Fahrenheit", additional: UnitTemperature.fahrenheit)
|
||||
]
|
||||
|
||||
public enum DataSizeBase: String {
|
||||
case bit = "bit"
|
||||
case byte = "byte"
|
||||
}
|
||||
public let SpeedBase: [KeyValue_t] = [
|
||||
KeyValue_t(key: "bit", value: "Bit", additional: DataSizeBase.bit),
|
||||
KeyValue_t(key: "byte", value: "Byte", additional: DataSizeBase.byte)
|
||||
]
|
||||
|
||||
public let SensorsWidgetMode: [KeyValue_t] = [
|
||||
KeyValue_t(key: "automatic", value: "Automatic"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "oneRow", value: "One row"),
|
||||
KeyValue_t(key: "twoRows", value: "Two rows"),
|
||||
]
|
||||
|
||||
public let SpeedPictogram: [KeyValue_t] = [
|
||||
KeyValue_t(key: "none", value: "None"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "dots", value: "Dots"),
|
||||
KeyValue_t(key: "arrows", value: "Arrows"),
|
||||
KeyValue_t(key: "chars", value: "Characters"),
|
||||
]
|
||||
|
||||
public let BatteryAdditionals: [KeyValue_t] = [
|
||||
KeyValue_t(key: "none", value: "None"),
|
||||
KeyValue_t(key: "separator", value: "separator"),
|
||||
KeyValue_t(key: "percentage", value: "Percentage"),
|
||||
KeyValue_t(key: "time", value: "Time"),
|
||||
KeyValue_t(key: "percentageAndTime", value: "Percentage and time"),
|
||||
KeyValue_t(key: "timeAndPercentage", value: "Time and percentage"),
|
||||
]
|
||||
|
||||
public let ShortLong: [KeyValue_t] = [
|
||||
KeyValue_t(key: "short", value: "Short"),
|
||||
KeyValue_t(key: "long", value: "Long"),
|
||||
]
|
||||
|
||||
public let ReaderUpdateIntervals: [Int] = [1, 2, 3, 5, 10, 15, 30]
|
||||
public let NumbersOfProcesses: [Int] = [0, 3, 5, 8, 10, 15]
|
||||
|
||||
public typealias Bandwidth = (upload: Int64, download: Int64)
|
||||
public let NetworkReaders: [KeyValue_t] = [
|
||||
KeyValue_t(key: "interface", value: "Interface based"),
|
||||
KeyValue_t(key: "process", value: "Processes based"),
|
||||
]
|
||||
|
||||
public struct Color: KeyValue_p, Equatable {
|
||||
public let key: String
|
||||
public let value: String
|
||||
public var additional: Any?
|
||||
|
||||
public static func == (lhs: Color, rhs: Color) -> 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 separator_1: Color { return Color(key: "separator_1", value: "separator_1", additional: NSColor.black) }
|
||||
|
||||
public static var systemAccent: Color { return Color(key: "system", value: "System accent", additional: NSColor.black) }
|
||||
public static var monochrome: Color { return Color(key: "monochrome", value: "Monochrome accent", additional: NSColor.black) }
|
||||
|
||||
public static var separator_2: Color { return Color(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.black) }
|
||||
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.black) }
|
||||
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.black) }
|
||||
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.black) }
|
||||
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)
|
||||
} else {
|
||||
return Color(key: "indigo", value: "Indigo", additional: NSColor(hexString: "#4B0082"))
|
||||
} }
|
||||
|
||||
public static var allCases: [Color] {
|
||||
return [.utilization, .pressure, separator_1,
|
||||
.systemAccent, .monochrome, separator_2,
|
||||
.clear, .white, .black, .gray, .secondGray, .darkGray, .lightGray,
|
||||
.red, .secondRed, .green, .secondGreen, .blue, .secondBlue, .yellow, .secondYellow,
|
||||
.orange, .secondOrange, .purple, .secondPurple, .brown, .secondBrown,
|
||||
.cyan, .magenta, .pink, .teal, .indigo
|
||||
]
|
||||
}
|
||||
|
||||
public static func fromString(_ key: String, defaultValue: Color = .systemAccent) -> Color {
|
||||
return Color.allCases.first{ $0.key == key } ?? defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
public typealias colorZones = (orange: Double, red: Double)
|
||||
|
||||
public extension Notification.Name {
|
||||
static let toggleSettings = Notification.Name("toggleSettings")
|
||||
static let toggleModule = Notification.Name("toggleModule")
|
||||
static let togglePopup = Notification.Name("togglePopup")
|
||||
static let toggleWidget = Notification.Name("toggleWidget")
|
||||
static let openModuleSettings = Notification.Name("openModuleSettings")
|
||||
static let settingsAppear = Notification.Name("settingsAppear")
|
||||
static let switchWidget = Notification.Name("switchWidget")
|
||||
static let checkForUpdates = Notification.Name("checkForUpdates")
|
||||
static let changeCronInterval = Notification.Name("changeCronInterval")
|
||||
static let clickInSettings = Notification.Name("clickInSettings")
|
||||
static let refreshPublicIP = Notification.Name("refreshPublicIP")
|
||||
}
|
||||
Reference in New Issue
Block a user