diff --git a/MTMR/Widgets/DarkModeBarItem.swift b/MTMR/Widgets/DarkModeBarItem.swift index ceaba78..65cb7b0 100644 --- a/MTMR/Widgets/DarkModeBarItem.swift +++ b/MTMR/Widgets/DarkModeBarItem.swift @@ -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) diff --git a/MTMR/Widgets/DnDBarItem.swift b/MTMR/Widgets/DnDBarItem.swift index 18344ca..a710821 100644 --- a/MTMR/Widgets/DnDBarItem.swift +++ b/MTMR/Widgets/DnDBarItem.swift @@ -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) diff --git a/MTMR/Widgets/MusicBarItem.swift b/MTMR/Widgets/MusicBarItem.swift index 23b2029..a4484c5 100644 --- a/MTMR/Widgets/MusicBarItem.swift +++ b/MTMR/Widgets/MusicBarItem.swift @@ -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 { diff --git a/MTMR/Widgets/NightShiftBarItem.swift b/MTMR/Widgets/NightShiftBarItem.swift index 517a8e7..b0ec5b1 100644 --- a/MTMR/Widgets/NightShiftBarItem.swift +++ b/MTMR/Widgets/NightShiftBarItem.swift @@ -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) diff --git a/MTMR/Widgets/PomodoroBarItem.swift b/MTMR/Widgets/PomodoroBarItem.swift index 7e081f7..54cccde 100644 --- a/MTMR/Widgets/PomodoroBarItem.swift +++ b/MTMR/Widgets/PomodoroBarItem.swift @@ -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) { diff --git a/MTMR/Widgets/UpNextScrubberTouchBarItem.swift b/MTMR/Widgets/UpNextScrubberTouchBarItem.swift index fb0f1ea..105e460 100644 --- a/MTMR/Widgets/UpNextScrubberTouchBarItem.swift +++ b/MTMR/Widgets/UpNextScrubberTouchBarItem.swift @@ -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 diff --git a/MTMR/Widgets/YandexWeatherBarItem.swift b/MTMR/Widgets/YandexWeatherBarItem.swift index ed47009..459ec50 100644 --- a/MTMR/Widgets/YandexWeatherBarItem.swift +++ b/MTMR/Widgets/YandexWeatherBarItem.swift @@ -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) {