feat: added an option to make the pictogram transparent when no activity (#1177)

This commit is contained in:
Serhiy Mytrovtsiy
2022-11-25 16:35:25 +01:00
parent 688dc9432e
commit 9647d1fd6e
33 changed files with 70 additions and 13 deletions

View File

@@ -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()
}

View File

@@ -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()
}
}

View File

@@ -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" = "Ниво";

View File

@@ -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";

View File

@@ -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ň";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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" = "Επίπεδο";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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" = "سطح";

View File

@@ -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";

View File

@@ -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" = "רמה";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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" = "充電残量";

View File

@@ -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" = "잔량";

View File

@@ -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å";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -307,6 +307,7 @@
"Nonactive state color" = "Цвет неактивного состояния";
"Connectivity host (ICMP)" = "Хост подключения (ICMP)";
"Leave empty to disable the check" = "Оставьте пустым, чтобы отключить проверку";
"Transparent pictogram when no activity" = "Прозрачная пиктограмма при отсутствии активности";
// Battery
"Level" = "Уровень заряда";

View File

@@ -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";

View File

@@ -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å";

View File

@@ -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";

View File

@@ -307,6 +307,7 @@
"Nonactive state color" = "Колір неактивного стану";
"Connectivity host (ICMP)" = "Хост підключення (ICMP)";
"Leave empty to disable the check" = "Залиште пустим, щоб вимкнути перевірку";
"Transparent pictogram when no activity" = "Прозора піктограма, коли немає активності";
// Battery
"Level" = "Рівень заряду";

View File

@@ -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";

View File

@@ -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" = "电量";

View File

@@ -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" = "電量";