mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
Update native widgets to use new actions parameter
This commit is contained in:
parent
420614b7ba
commit
2c179606d3
@ -11,7 +11,7 @@ class DarkModeBarItem: CustomButtonTouchBarItem, Widget {
|
||||
isBordered = false
|
||||
setWidth(value: 24)
|
||||
|
||||
tapClosure = { [weak self] in self?.DarkModeToggle() }
|
||||
actions[.singleTap] = { [weak self] in self?.DarkModeToggle() }
|
||||
|
||||
timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ class DnDBarItem: CustomButtonTouchBarItem {
|
||||
isBordered = false
|
||||
setWidth(value: 32)
|
||||
|
||||
tapClosure = { [weak self] in self?.DnDToggle() }
|
||||
actions[.singleTap] = { [weak self] in self?.DnDToggle() }
|
||||
|
||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||
|
||||
|
||||
@ -41,9 +41,12 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
|
||||
super.init(identifier: identifier, title: "⏳")
|
||||
isBordered = false
|
||||
|
||||
tapClosure = { [weak self] in self?.playPause() }
|
||||
longTapClosure = { [weak self] in self?.nextTrack() }
|
||||
|
||||
actions = [
|
||||
.singleTap: { [weak self] in self?.playPause() },
|
||||
.doubleTap: { [weak self] in self?.previousTrack() },
|
||||
.longTap: { [weak self] in self?.nextTrack() }
|
||||
]
|
||||
|
||||
refreshAndSchedule()
|
||||
}
|
||||
@ -177,6 +180,31 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func previousTrack() {
|
||||
for ident in playerBundleIdentifiers {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||
if musicPlayer.isRunning {
|
||||
if ident == .Spotify {
|
||||
let mp = (musicPlayer as SpotifyApplication)
|
||||
mp.previousTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if ident == .iTunes {
|
||||
let mp = (musicPlayer as iTunesApplication)
|
||||
mp.previousTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if ident == .Music {
|
||||
let mp = (musicPlayer as MusicApplication)
|
||||
mp.previousTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func refreshAndSchedule() {
|
||||
DispatchQueue.main.async {
|
||||
|
||||
@ -31,7 +31,7 @@ class NightShiftBarItem: CustomButtonTouchBarItem {
|
||||
isBordered = false
|
||||
setWidth(value: 28)
|
||||
|
||||
tapClosure = { [weak self] in self?.nightShiftAction() }
|
||||
actions[.singleTap] = { [weak self] in self?.nightShiftAction() }
|
||||
|
||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||
|
||||
|
||||
@ -50,8 +50,10 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
self.workTime = workTime
|
||||
self.restTime = restTime
|
||||
super.init(identifier: identifier, title: defaultTitle)
|
||||
tapClosure = { [weak self] in self?.startStopWork() }
|
||||
longTapClosure = { [weak self] in self?.startStopRest() }
|
||||
actions = [
|
||||
.singleTap: { [weak self] in self?.startStopWork() },
|
||||
.longTap: { [weak self] in self?.startStopRest() }
|
||||
]
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
|
||||
@ -75,7 +75,7 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
let item = UpNextItem(event: event)
|
||||
item.backgroundColor = self.getBackgroundColor(startDate: event.startDate)
|
||||
// Bind tap event
|
||||
item.tapClosure = { [weak self] in
|
||||
item.actions[.singleTap] = { [weak self] in
|
||||
self?.switchToApp(event: event)
|
||||
}
|
||||
// Add to view
|
||||
|
||||
@ -51,7 +51,7 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
||||
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
||||
manager.startUpdatingLocation()
|
||||
|
||||
tapClosure = tapClosure ?? defaultTapAction
|
||||
actions[.singleTap] = actions[.singleTap] ?? defaultTapAction
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user