1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 00:58:37 +00:00

flip param for network

This commit is contained in:
Toxblh 2019-03-21 21:49:34 +00:00
parent 780a8ba81e
commit 556c28df85
4 changed files with 48 additions and 28 deletions

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>0.20</string>
<key>CFBundleVersion</key>
<string>178</string>
<string>185</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>

View File

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

View File

@ -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 {

View File

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