mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
Update music title right after switch to the next track
This commit is contained in:
parent
091208e536
commit
088f141da3
@ -32,9 +32,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
self.tapClosure = { [weak self] in self?.playPause() }
|
||||
self.longTapClosure = { [weak self] in self?.nextTrack() }
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.updatePlayer()
|
||||
}
|
||||
self.refreshAndSchedule()
|
||||
}
|
||||
|
||||
@objc func marquee(){
|
||||
@ -118,14 +116,17 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
if (musicPlayer.className == "SpotifyApplication") {
|
||||
let mp = (musicPlayer as SpotifyApplication)
|
||||
mp.nextTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if (musicPlayer.className == "ITunesApplication") {
|
||||
let mp = (musicPlayer as iTunesApplication)
|
||||
mp.nextTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if (musicPlayer.className == "VOXApplication") {
|
||||
let mp = (musicPlayer as VoxApplication)
|
||||
mp.next!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if (musicPlayer.className == "SafariApplication") {
|
||||
// You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use 'do JavaScript'.
|
||||
@ -136,12 +137,15 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
let tab = tab as! SafariTab
|
||||
if (tab.URL?.starts(with: "https://music.yandex.ru"))! {
|
||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('player-controls__btn_next')[0].click()", in: tab)
|
||||
updatePlayer()
|
||||
return
|
||||
} else if ((tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))!) {
|
||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('audio_page_player_next')[0].click()", in: tab)
|
||||
updatePlayer()
|
||||
return
|
||||
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('ytp-next-button')[0].click()", in: tab)
|
||||
updatePlayer()
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -152,6 +156,15 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
}
|
||||
|
||||
func refreshAndSchedule() {
|
||||
DispatchQueue.main.async {
|
||||
self.updatePlayer()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + self.interval) { [weak self] in
|
||||
self?.refreshAndSchedule()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updatePlayer() {
|
||||
var iconUpdated = false
|
||||
var titleUpdated = false
|
||||
@ -215,9 +228,6 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
|
||||
if (tempTitle == self.songTitle) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + self.interval) { [weak self] in
|
||||
self?.updatePlayer()
|
||||
}
|
||||
return
|
||||
} else {
|
||||
self.songTitle = tempTitle
|
||||
@ -251,9 +261,6 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
self.title = ""
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + self.interval) { [weak self] in
|
||||
self?.updatePlayer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user