mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added an option to make the pictogram transparent when no activity (#1177)
This commit is contained in:
@@ -330,7 +330,6 @@ public class BarChart: WidgetWrapper {
|
||||
self.colorState = newColor
|
||||
}
|
||||
|
||||
print(key)
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_color", value: key)
|
||||
self.display()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
private var unitsState: Bool = true
|
||||
private var monochromeState: Bool = false
|
||||
private var valueColorState: Bool = false
|
||||
private var transparentIconsState: Bool = false
|
||||
|
||||
private var downloadColorState: Color = .secondBlue
|
||||
private var uploadColorState: Color = .secondRed
|
||||
@@ -34,16 +35,16 @@ public class SpeedWidget: WidgetWrapper {
|
||||
private var width: CGFloat = 58
|
||||
|
||||
private var valueColorView: NSView? = nil
|
||||
private var transparentIconView: NSView? = nil
|
||||
|
||||
private var downloadColor: NSColor {
|
||||
get {
|
||||
return self.monochromeState ? MonochromeColor.blue : (self.downloadColorState.additional as? NSColor ?? NSColor.systemBlue)
|
||||
}
|
||||
self.monochromeState ? MonochromeColor.blue : (self.downloadColorState.additional as? NSColor ?? NSColor.systemBlue)
|
||||
}
|
||||
private var uploadColor: NSColor {
|
||||
get {
|
||||
return self.monochromeState ? MonochromeColor.red : (self.uploadColorState.additional as? NSColor ?? NSColor.red)
|
||||
}
|
||||
self.monochromeState ? MonochromeColor.red : (self.uploadColorState.additional as? NSColor ?? NSColor.red)
|
||||
}
|
||||
private var noActivityColor: NSColor {
|
||||
self.transparentIconsState ? NSColor.clear : NSColor.textColor
|
||||
}
|
||||
|
||||
public init(title: String, config: NSDictionary?, preview: Bool = false) {
|
||||
@@ -75,6 +76,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
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.transparentIconsState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_transparentIcons", defaultValue: self.transparentIconsState)
|
||||
}
|
||||
|
||||
if self.valueState && self.icon != "none" {
|
||||
@@ -157,12 +159,12 @@ public class SpeedWidget: WidgetWrapper {
|
||||
|
||||
var downloadCircle = NSBezierPath()
|
||||
downloadCircle = NSBezierPath(ovalIn: CGRect(x: Constants.Widget.margin.x, y: y-0.2, width: size, height: size))
|
||||
(self.downloadValue >= 1_024 ? self.downloadColor : NSColor.textColor).set()
|
||||
(self.downloadValue >= 1_024 ? self.downloadColor : self.noActivityColor).set()
|
||||
downloadCircle.fill()
|
||||
|
||||
var uploadCircle = NSBezierPath()
|
||||
uploadCircle = NSBezierPath(ovalIn: CGRect(x: Constants.Widget.margin.x, y: 10.5, width: size, height: size))
|
||||
(self.uploadValue >= 1_024 ? self.uploadColor : NSColor.textColor).set()
|
||||
(self.uploadValue >= 1_024 ? self.uploadColor : self.noActivityColor).set()
|
||||
uploadCircle.fill()
|
||||
}
|
||||
|
||||
@@ -182,7 +184,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
arrowAngle: arrowAngle
|
||||
)
|
||||
|
||||
(self.downloadValue >= 1_024 ? self.downloadColor : NSColor.textColor).set()
|
||||
(self.downloadValue >= 1_024 ? self.downloadColor : self.noActivityColor).set()
|
||||
downloadArrow.lineWidth = lineWidth
|
||||
downloadArrow.stroke()
|
||||
downloadArrow.close()
|
||||
@@ -195,7 +197,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
arrowAngle: arrowAngle
|
||||
)
|
||||
|
||||
(self.uploadValue >= 1_024 ? self.uploadColor : NSColor.textColor).set()
|
||||
(self.uploadValue >= 1_024 ? self.uploadColor : self.noActivityColor).set()
|
||||
uploadArrow.lineWidth = lineWidth
|
||||
uploadArrow.stroke()
|
||||
uploadArrow.close()
|
||||
@@ -207,7 +209,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
if self.symbols.count > 1 {
|
||||
let downloadAttributes = [
|
||||
NSAttributedString.Key.font: NSFont.systemFont(ofSize: 9, weight: .regular),
|
||||
NSAttributedString.Key.foregroundColor: self.downloadValue >= 1_024 ? self.downloadColor : NSColor.textColor,
|
||||
NSAttributedString.Key.foregroundColor: self.downloadValue >= 1_024 ? self.downloadColor : self.noActivityColor,
|
||||
NSAttributedString.Key.paragraphStyle: NSMutableParagraphStyle()
|
||||
]
|
||||
let rect = CGRect(x: Constants.Widget.margin.x, y: 1, width: 8, height: rowHeight)
|
||||
@@ -218,7 +220,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
if !self.symbols.isEmpty {
|
||||
let uploadAttributes = [
|
||||
NSAttributedString.Key.font: NSFont.systemFont(ofSize: 9, weight: .regular),
|
||||
NSAttributedString.Key.foregroundColor: self.uploadValue >= 1_024 ? self.uploadColor : NSColor.textColor,
|
||||
NSAttributedString.Key.foregroundColor: self.uploadValue >= 1_024 ? self.uploadColor : self.noActivityColor,
|
||||
NSAttributedString.Key.paragraphStyle: NSMutableParagraphStyle()
|
||||
]
|
||||
let rect = CGRect(x: Constants.Widget.margin.x, y: rowHeight+1, width: 8, height: rowHeight)
|
||||
@@ -237,6 +239,16 @@ public class SpeedWidget: WidgetWrapper {
|
||||
selected: self.icon
|
||||
))
|
||||
|
||||
self.transparentIconView = toggleSettingRow(
|
||||
title: localizedString("Transparent pictogram when no activity"),
|
||||
action: #selector(toggleTransparentIcons),
|
||||
state: self.transparentIconsState
|
||||
)
|
||||
if let v = self.transparentIconView {
|
||||
view.addArrangedSubview(v)
|
||||
findAndToggleEnableNSControlState(v, state: self.icon != "none")
|
||||
}
|
||||
|
||||
view.addArrangedSubview(selectSettingsRow(
|
||||
title: localizedString("Base"),
|
||||
action: #selector(toggleBase),
|
||||
@@ -337,6 +349,8 @@ public class SpeedWidget: WidgetWrapper {
|
||||
NotificationCenter.default.post(name: .toggleModule, object: nil, userInfo: ["module": self.title, "state": true])
|
||||
self.state = true
|
||||
}
|
||||
|
||||
findAndToggleEnableNSControlState(self.transparentIconView, state: self.icon != "none")
|
||||
}
|
||||
|
||||
@objc private func toggleBase(_ sender: NSMenuItem) {
|
||||
@@ -408,4 +422,17 @@ public class SpeedWidget: WidgetWrapper {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func toggleTransparentIcons(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
self.transparentIconsState = state! == .on ? true : false
|
||||
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_transparentIcons", value: self.transparentIconsState)
|
||||
self.display()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Цвят на неактивното състояние";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Оставете празно, за да изключите проверката";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Ниво";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nivell";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Barva neaktivního stavu";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Úroveň";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Niveau";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Ladezustand";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Επίπεδο";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Level";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nivel";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "رنگ حالت غیر فعال";
|
||||
"Connectivity host (ICMP)" = "میزبان اتصال (ICMP)";
|
||||
"Leave empty to disable the check" = "خالی بگذارید تا بررسی غیرفعال شود";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "سطح";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Niveau";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "רמה";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Stanje";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Töltöttségi szint";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Level";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Livello";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "充電残量";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "잔량";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nivå";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Niveau";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Kolor stanu nieaktywnego";
|
||||
"Connectivity host (ICMP)" = "Host łączności (ICMP)";
|
||||
"Leave empty to disable the check" = "Pozostaw puste, aby wyłączyć sprawdzanie";
|
||||
"Transparent pictogram when no activity" = "Przejrzysty piktogram, przy braku aktywności";
|
||||
|
||||
// Battery
|
||||
"Level" = "Poziom naładowania";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nível";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nível";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nivel";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Цвет неактивного состояния";
|
||||
"Connectivity host (ICMP)" = "Хост подключения (ICMP)";
|
||||
"Leave empty to disable the check" = "Оставьте пустым, чтобы отключить проверку";
|
||||
"Transparent pictogram when no activity" = "Прозрачная пиктограмма при отсутствии активности";
|
||||
|
||||
// Battery
|
||||
"Level" = "Уровень заряда";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Barva neaktivnega stanja";
|
||||
"Connectivity host (ICMP)" = "Gostitelj za preverjanje povezljivosti (ICMP)";
|
||||
"Leave empty to disable the check" = "Pustite prazno, če želite onemogočiti preverjanje povezljivosti";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Raven";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Nivå";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Etkin olmayan durum rengi";
|
||||
"Connectivity host (ICMP)" = "Bağlantı sunucusu (ICMP)";
|
||||
"Leave empty to disable the check" = "Kontrolü devre dışı bırakmak için boş bırakın";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Doluluk";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Колір неактивного стану";
|
||||
"Connectivity host (ICMP)" = "Хост підключення (ICMP)";
|
||||
"Leave empty to disable the check" = "Залиште пустим, щоб вимкнути перевірку";
|
||||
"Transparent pictogram when no activity" = "Прозора піктограма, коли немає активності";
|
||||
|
||||
// Battery
|
||||
"Level" = "Рівень заряду";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "Nonactive state color";
|
||||
"Connectivity host (ICMP)" = "Connectivity host (ICMP)";
|
||||
"Leave empty to disable the check" = "Leave empty to disable the check";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "Dung lượng Pin";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "非活跃状态颜色";
|
||||
"Connectivity host (ICMP)" = "连接Host (ICMP)";
|
||||
"Leave empty to disable the check" = "不在该选项内输入以禁用检查";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "电量";
|
||||
|
||||
@@ -307,6 +307,7 @@
|
||||
"Nonactive state color" = "未連線狀態色彩";
|
||||
"Connectivity host (ICMP)" = "連線主機 (ICMP)";
|
||||
"Leave empty to disable the check" = "留空來停用檢查";
|
||||
"Transparent pictogram when no activity" = "Transparent pictogram when no activity";
|
||||
|
||||
// Battery
|
||||
"Level" = "電量";
|
||||
|
||||
Reference in New Issue
Block a user