mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
flip param for network
This commit is contained in:
parent
780a8ba81e
commit
556c28df85
@ -19,7 +19,7 @@
|
|||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.20</string>
|
<string>0.20</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>178</string>
|
<string>185</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@ -338,7 +338,7 @@ enum ItemType: Decodable {
|
|||||||
case nightShift()
|
case nightShift()
|
||||||
case dnd()
|
case dnd()
|
||||||
case pomodoro(workTime: Double, restTime: Double)
|
case pomodoro(workTime: Double, restTime: Double)
|
||||||
case network()
|
case network(flip: Bool)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case type
|
case type
|
||||||
@ -359,6 +359,7 @@ enum ItemType: Decodable {
|
|||||||
case items
|
case items
|
||||||
case workTime
|
case workTime
|
||||||
case restTime
|
case restTime
|
||||||
|
case flip
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ItemTypeRaw: String, Decodable {
|
enum ItemTypeRaw: String, Decodable {
|
||||||
@ -448,7 +449,8 @@ enum ItemType: Decodable {
|
|||||||
self = .pomodoro(workTime: workTime, restTime: restTime)
|
self = .pomodoro(workTime: workTime, restTime: restTime)
|
||||||
|
|
||||||
case .network:
|
case .network:
|
||||||
self = .network()
|
let flip = try container.decodeIfPresent(Bool.self, forKey: .flip) ?? false
|
||||||
|
self = .network(flip: flip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ extension ItemType {
|
|||||||
return "com.toxblh.mtmr.dnd."
|
return "com.toxblh.mtmr.dnd."
|
||||||
case .pomodoro(interval: _):
|
case .pomodoro(interval: _):
|
||||||
return PomodoroBarItem.identifier
|
return PomodoroBarItem.identifier
|
||||||
case .network():
|
case .network(flip: _):
|
||||||
return NetworkBarItem.identifier
|
return NetworkBarItem.identifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,8 +281,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
barItem = DnDBarItem(identifier: identifier)
|
barItem = DnDBarItem(identifier: identifier)
|
||||||
case let .pomodoro(workTime: workTime, restTime: restTime):
|
case let .pomodoro(workTime: workTime, restTime: restTime):
|
||||||
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
||||||
case .network():
|
case let .network(flip: flip):
|
||||||
barItem = NetworkBarItem(identifier: identifier)
|
barItem = NetworkBarItem(identifier: identifier, flip: flip)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||||
|
|||||||
@ -12,7 +12,10 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
static var name: String = "network"
|
static var name: String = "network"
|
||||||
static var identifier: String = "com.toxblh.mtmr.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: " ")
|
super.init(identifier: identifier, title: " ")
|
||||||
startMonitoringProcess()
|
startMonitoringProcess()
|
||||||
}
|
}
|
||||||
@ -95,34 +98,49 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
return humanText
|
return humanText
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTitle(up: String, down: String) {
|
func appendUpSpeed(appendString: NSMutableAttributedString, up: String, titleFont: NSFont, newStr: Bool = false) {
|
||||||
let titleFont = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFont.Weight.light)
|
appendString.append(NSMutableAttributedString(
|
||||||
|
string: newStr ? "\n↑" : "↑",
|
||||||
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↑",
|
|
||||||
attributes: [
|
attributes: [
|
||||||
NSAttributedString.Key.foregroundColor: NSColor.blue,
|
NSAttributedString.Key.foregroundColor: NSColor.blue,
|
||||||
NSAttributedString.Key.font: titleFont,
|
NSAttributedString.Key.font: titleFont,
|
||||||
]))
|
]))
|
||||||
|
|
||||||
newTitle.append(NSMutableAttributedString(
|
appendString.append(NSMutableAttributedString(
|
||||||
string: up,
|
string: up,
|
||||||
attributes: [
|
attributes: [
|
||||||
NSAttributedString.Key.font: titleFont,
|
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
|
self.attributedTitle = newTitle
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user