mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
MusicBarItem: add support for "disableMarquee" param
This commit is contained in:
parent
705d0a64b5
commit
3432e24a55
@ -274,11 +274,12 @@ class SupportedTypesHolder {
|
||||
) },
|
||||
|
||||
"music": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval }
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval; case disableMarquee }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
let disableMarquee = try container.decodeIfPresent(Bool.self, forKey: .disableMarquee)
|
||||
return (
|
||||
item: .music(interval: interval ?? 1800.00),
|
||||
item: .music(interval: interval ?? 5.0, disableMarquee: disableMarquee ?? false),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
@ -336,7 +337,7 @@ enum ItemType: Decodable {
|
||||
case weather(interval: Double, units: String, api_key: String, icon_type: String)
|
||||
case currency(interval: Double, from: String, to: String, full: Bool)
|
||||
case inputsource()
|
||||
case music(interval: Double)
|
||||
case music(interval: Double, disableMarquee: Bool)
|
||||
case groupBar(items: [BarItemDefinition])
|
||||
case nightShift()
|
||||
case dnd()
|
||||
@ -365,6 +366,7 @@ enum ItemType: Decodable {
|
||||
case restTime
|
||||
case flip
|
||||
case autoResize
|
||||
case disableMarquee
|
||||
}
|
||||
|
||||
enum ItemTypeRaw: String, Decodable {
|
||||
@ -437,8 +439,9 @@ enum ItemType: Decodable {
|
||||
self = .inputsource()
|
||||
|
||||
case .music:
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||
self = .music(interval: interval)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
|
||||
let disableMarquee = try container.decodeIfPresent(Bool.self, forKey: .disableMarquee) ?? false
|
||||
self = .music(interval: interval, disableMarquee: disableMarquee)
|
||||
|
||||
case .groupBar:
|
||||
let items = try container.decode([BarItemDefinition].self, forKey: .items)
|
||||
|
||||
@ -273,8 +273,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, full: full)
|
||||
case .inputsource():
|
||||
barItem = InputSourceBarItem(identifier: identifier)
|
||||
case let .music(interval: interval):
|
||||
barItem = MusicBarItem(identifier: identifier, interval: interval)
|
||||
case let .music(interval: interval, disableMarquee: disableMarquee):
|
||||
barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee)
|
||||
case let .groupBar(items: items):
|
||||
barItem = GroupBarItem(identifier: identifier, items: items)
|
||||
case .nightShift():
|
||||
|
||||
@ -27,13 +27,15 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
]
|
||||
|
||||
private let interval: TimeInterval
|
||||
private let disableMarquee: Bool
|
||||
private var songTitle: String?
|
||||
private var timer: Timer?
|
||||
private let iconSize = NSSize(width: 21, height: 21)
|
||||
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, disableMarquee: Bool) {
|
||||
self.interval = interval
|
||||
self.disableMarquee = disableMarquee
|
||||
|
||||
super.init(identifier: identifier, title: "⏳")
|
||||
isBordered = false
|
||||
@ -237,11 +239,17 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
|
||||
if let songTitle = self.songTitle?.ifNotEmpty {
|
||||
self.title = " " + songTitle + " "
|
||||
titleUpdated = true
|
||||
self.timer?.invalidate()
|
||||
self.timer = nil
|
||||
self.timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.marquee), userInfo: nil, repeats: true)
|
||||
|
||||
if (disableMarquee) {
|
||||
self.title = " " + songTitle
|
||||
} else {
|
||||
self.title = " " + songTitle + " "
|
||||
self.timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.marquee), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
titleUpdated = true
|
||||
}
|
||||
if let _ = tempTitle.ifNotEmpty,
|
||||
let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: ident.rawValue) {
|
||||
|
||||
@ -207,9 +207,10 @@ To close a group, use the button:
|
||||
{
|
||||
"type": "music",
|
||||
"align": "center",
|
||||
"width": 80,
|
||||
"bordered": false,
|
||||
"refreshInterval": 2, // in seconds
|
||||
"width": 80, // Optional
|
||||
"bordered": false, // Optional
|
||||
"refreshInterval": 2, // in seconds. Optional. Default 5 seconds
|
||||
"disableMarquee": true // to disable marquee effect. Optional. Default false
|
||||
},
|
||||
```
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user