diff --git a/MTMR/Info.plist b/MTMR/Info.plist
index b137245..02df04a 100644
--- a/MTMR/Info.plist
+++ b/MTMR/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
0.20
CFBundleVersion
- 178
+ 185
LSApplicationCategoryType
public.app-category.utilities
LSMinimumSystemVersion
diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift
index 7ac5c27..8fa1413 100644
--- a/MTMR/ItemsParsing.swift
+++ b/MTMR/ItemsParsing.swift
@@ -338,7 +338,7 @@ enum ItemType: Decodable {
case nightShift()
case dnd()
case pomodoro(workTime: Double, restTime: Double)
- case network()
+ case network(flip: Bool)
private enum CodingKeys: String, CodingKey {
case type
@@ -359,6 +359,7 @@ enum ItemType: Decodable {
case items
case workTime
case restTime
+ case flip
}
enum ItemTypeRaw: String, Decodable {
@@ -448,7 +449,8 @@ enum ItemType: Decodable {
self = .pomodoro(workTime: workTime, restTime: restTime)
case .network:
- self = .network()
+ let flip = try container.decodeIfPresent(Bool.self, forKey: .flip) ?? false
+ self = .network(flip: flip)
}
}
}
diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift
index a2862ef..a23ebe8 100644
--- a/MTMR/TouchBarController.swift
+++ b/MTMR/TouchBarController.swift
@@ -49,7 +49,7 @@ extension ItemType {
return "com.toxblh.mtmr.dnd."
case .pomodoro(interval: _):
return PomodoroBarItem.identifier
- case .network():
+ case .network(flip: _):
return NetworkBarItem.identifier
}
}
@@ -281,8 +281,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
barItem = DnDBarItem(identifier: identifier)
case let .pomodoro(workTime: workTime, restTime: restTime):
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
- case .network():
- barItem = NetworkBarItem(identifier: identifier)
+ case let .network(flip: flip):
+ barItem = NetworkBarItem(identifier: identifier, flip: flip)
}
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
diff --git a/MTMR/Widgets/NetworkBarItem.swift b/MTMR/Widgets/NetworkBarItem.swift
index cfbec3b..21c5820 100644
--- a/MTMR/Widgets/NetworkBarItem.swift
+++ b/MTMR/Widgets/NetworkBarItem.swift
@@ -12,7 +12,10 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
static var name: String = "network"
static var identifier: String = "com.toxblh.mtmr.network"
- init(identifier: NSTouchBarItem.Identifier) {
+ private let flip: Bool
+
+ init(identifier: NSTouchBarItem.Identifier, flip: Bool = false) {
+ self.flip = flip
super.init(identifier: identifier, title: " ")
startMonitoringProcess()
}
@@ -95,34 +98,49 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
return humanText
}
- func setTitle(up: String, down: String) {
- let titleFont = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFont.Weight.light)
-
- let newTitle = NSMutableAttributedString(
- string: "↓",
- attributes: [
- NSAttributedString.Key.foregroundColor: NSColor.red,
- NSAttributedString.Key.font: titleFont,
- ])
-
- newTitle.append(NSMutableAttributedString(
- string: down,
- attributes: [
- NSAttributedString.Key.font: titleFont
- ]))
-
- newTitle.append(NSMutableAttributedString(
- string: "\n↑",
+ func appendUpSpeed(appendString: NSMutableAttributedString, up: String, titleFont: NSFont, newStr: Bool = false) {
+ appendString.append(NSMutableAttributedString(
+ string: newStr ? "\n↑" : "↑",
attributes: [
NSAttributedString.Key.foregroundColor: NSColor.blue,
NSAttributedString.Key.font: titleFont,
- ]))
+ ]))
- newTitle.append(NSMutableAttributedString(
+ appendString.append(NSMutableAttributedString(
string: up,
attributes: [
NSAttributedString.Key.font: titleFont,
- ]))
+ ]))
+ }
+
+ func appendDownSpeed(appendString: NSMutableAttributedString, down: String, titleFont: NSFont, newStr: Bool = false) {
+ appendString.append(NSMutableAttributedString(
+ string: newStr ? "\n↓" : "↓",
+ attributes: [
+ NSAttributedString.Key.foregroundColor: NSColor.red,
+ NSAttributedString.Key.font: titleFont,
+ ]))
+
+ appendString.append(NSMutableAttributedString(
+ string: down,
+ attributes: [
+ NSAttributedString.Key.font: titleFont
+ ]))
+ }
+
+ func setTitle(up: String, down: String) {
+ let titleFont = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFont.Weight.light)
+
+ let newTitle: NSMutableAttributedString = NSMutableAttributedString(string: "")
+
+ if (self.flip) {
+ appendUpSpeed(appendString: newTitle, up: up, titleFont: titleFont)
+ appendDownSpeed(appendString: newTitle, down: down, titleFont: titleFont, newStr: true)
+ } else {
+ appendDownSpeed(appendString: newTitle, down: down, titleFont: titleFont)
+ appendUpSpeed(appendString: newTitle, up: up, titleFont: titleFont, newStr: true)
+ }
+
self.attributedTitle = newTitle
}