From 37859ef6269e11ac2a48662ecb88b737a7c990b5 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:19:24 -0400 Subject: [PATCH 1/6] fix offset due to possible miniplayer --- Examples/Spotify.ahk | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index 81d1861..a0d1a19 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -91,14 +91,22 @@ class Spotify { static ToggleFullscreen() => Spotify.FullscreenState := !Spotify.FullscreenState static MuteState { - get => Spotify.GetCurrentSongElement()[{Type:"Button", i:-2}] == "Mute" + get { + return ( + Spotify.GetCurrentSongElement()[{Type:"Button", i:-2}].Name == "Mute" or + Spotify.GetCurrentSongElement()[{Type:"Button", i:-3}].Name == "Mute" + ) + } set { currentState := Spotify.MuteState + if InStr(Spotify.GetCurrentSongElement()[{Type:"Button", i:-2}].Name, "ute") + index := -2 + else + index := -3 if Value && !currentState - Spotify.GetCurrentSongElement()[{Type:"Button", i:-2}].Click() - if !Value && currentState - Spotify.GetCurrentSongElement()[{Type:"Button", i:-2}].Click() - + Spotify.GetCurrentSongElement()[{Type:"Button", i:index}].Click() ; Unmuting + else if !Value && currentState + Spotify.GetCurrentSongElement()[{Type:"Button", i:index}].Click() ; Muting } } static ToggleMute() => Spotify.MuteState := !Spotify.MuteState From 18e79f227d38d5a667a69d5dbe5c07b3fbff78bc Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:19:35 -0400 Subject: [PATCH 2/6] fix volume --- Examples/Spotify.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index a0d1a19..b236f84 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -18,8 +18,8 @@ F11::Spotify.ToggleFullscreen() } ^Left::Spotify.NextSong() ^Right::Spotify.PreviousSong() -^+::Spotify.Volume += 10 -^-::Spotify.Volume -= 10 +^+::Spotify.Volume += 0.1 +^-::Spotify.Volume -= 0.1 ^m::Spotify.ToggleMute() class Spotify { From 750d7b0454a2294b69ee0e2b87b5b3c8daa13ee1 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:21:02 -0400 Subject: [PATCH 3/6] update like --- Examples/Spotify.ahk | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index b236f84..9167c1c 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -13,8 +13,11 @@ F11::Spotify.ToggleFullscreen() ^l:: { song := Spotify.CurrentSong - Spotify.Toast("You " (!Spotify.LikeState ? "liked " : "removed a like from ") song.Name " by " song.Artist) - Spotify.ToggleLike() + if Spotify.Like() { + Spotify.Toast("You liked " song.Name " by " song.Artist) + } else { + Spotify.Toast("Already liked? No like button found.") + } } ^Left::Spotify.NextSong() ^Right::Spotify.PreviousSong() @@ -37,16 +40,23 @@ class Spotify { } ; Internal methods to get some commonly used Spotify UIA elements static GetSpotifyElement() => UIA.ElementFromHandle(Spotify.winExe)[1] - static GetLikeElement() => Spotify.GetSpotifyElement().ElementFromPath({T:26, i:3}, {T:26,N:"Now playing: ",mm:2}, {T:0,N:"Library", mm:2}) + static GetLikeElement() { + try { + return Spotify.GetSpotifyElement().ElementFromPath({T:26, i:3}, {T:26, N:"Now playing: ", mm:2}, {T:0, N:"Add to Liked Songs", mm:3}) + } catch { + return + } + } static GetCurrentSongElement() => Spotify.FullscreenState ? Spotify.GetSpotifyElement() : Spotify.GetSpotifyElement()[{T:26, i:3}] - static LikeState { - get => Spotify.GetLikeElement().ToggleState - set => Spotify.GetLikeElement().ToggleState := value + static Like() { + el := Spotify.GetLikeElement() + if el { + el.Click() + return true + } + return false } - static Like() => Spotify.LikeState := 1 - static RemoveLike() => Spotify.LikeState := 0 - static ToggleLike() => Spotify.LikeState := !Spotify.LikeState static CurrentSong { get { From 352c447259da14cef1caa706dd7841b84b93fb62 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:22:04 -0400 Subject: [PATCH 4/6] update toast --- Examples/Spotify.ahk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index 9167c1c..4c1d496 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -9,14 +9,14 @@ UIA.AutoSetFocus := False F1::Spotify.TogglePlay() F11::Spotify.ToggleFullscreen() -^d::Spotify.Toast("Playing song: " (song := Spotify.CurrentSong).Name "`nArtist: " song.Artist "`nPlay time: " song.Time " / " song.Length) +^d::Spotify.Toast("Now Playing", (song := Spotify.CurrentSong).Name "`nArtist: " song.Artist "`nPlay time: " song.Time " / " song.Length) ^l:: { song := Spotify.CurrentSong if Spotify.Like() { - Spotify.Toast("You liked " song.Name " by " song.Artist) + Spotify.Toast("Like", "You liked " song.Name " by " song.Artist) } else { - Spotify.Toast("Already liked? No like button found.") + Spotify.Toast("Like", "Already liked? No like button found.") } } ^Left::Spotify.NextSong() @@ -31,12 +31,12 @@ class Spotify { static exePath := A_AppData "\Spotify\Spotify.exe" ; Internal method to show a Toast message, but before that remove the previous one - static Toast(message) { + static Toast(title, message) { TrayTip A_IconHidden := true Sleep 200 A_IconHidden := false - TrayTip(message, "Spotify info") + TrayTip(message, title) } ; Internal methods to get some commonly used Spotify UIA elements static GetSpotifyElement() => UIA.ElementFromHandle(Spotify.winExe)[1] From 67cd1d1642575f5cc5013f3d858f687a37756ede Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:22:32 -0400 Subject: [PATCH 5/6] fix getting current track --- Examples/Spotify.ahk | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index 4c1d496..b3c3685 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -61,11 +61,33 @@ class Spotify { static CurrentSong { get { contentEl := Spotify.GetCurrentSongElement() + if Spotify.FullscreenState { + name := contentEl[{Type: "Text", i: 3}].Name + ; Only one artist is displayed when fullscreen + artists := contentEl[{Type: "Text", i: 4}].Name + time := contentEl[{Type: "Text", i: 5}].Name + length := contentEl[{Type: "Text", i: 7}].Name + } else { + name := contentEl[{Type: "Group"}, {Type: "Link", i: 1}].Name + artists := 0 + for (link in contentEl.FindElements([{Type: "Group"}, {Type: "Link"}])) { + if A_Index < 3 { + continue + } + if artists == 0 { + artists := link.Name + continue + } + artists := artists ", " link.Name + } + time := contentEl[{Type: "Text", i: 1}].Name + length := contentEl[{Type: "Text", i: 3}].Name + } return { - Name:contentEl[{Type:"Group"},{Type:"Link",i:2}].Name, - Artist:contentEl[{Type:"Group"},{Type:"Link",i:3}].Name, - Time:contentEl[{Type:"Text", i:1}].Name, - Length:contentEl[{Type:"Text", i:3}].Name + Name:name, + Artist:artists, + Time:time, + Length:length, } } } From ba06fe2ef4ca9f630736a7a79fcd03863a4a6485 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Thu, 3 Apr 2025 19:52:03 -0400 Subject: [PATCH 6/6] update fullscreen --- Examples/Spotify.ahk | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Examples/Spotify.ahk b/Examples/Spotify.ahk index b3c3685..581bb6c 100644 --- a/Examples/Spotify.ahk +++ b/Examples/Spotify.ahk @@ -110,14 +110,27 @@ class Spotify { static PreviousSong() => Spotify.GetCurrentSongElement()[{Name:"Previous"}].Click() static FullscreenState { - get => Spotify.GetSpotifyElement()[-1].Type == UIA.Type.Button + get { + try { + fse := Spotify.GetSpotifyElement()[{Type: "Button", i: -1}] + return InStr(fse.Name, "Exit full screen") + } catch { + return true + } + } set { WinActivate(Spotify.winExe) WinWaitActive(Spotify.winExe,,1) - if Spotify.FullscreenState - Spotify.GetSpotifyElement()[-1].Click() - else + if Spotify.FullscreenState { + try { + Spotify.GetSpotifyElement()[{Type: "Button", i: -1}].Click() + } catch { + ; No buttons available, and {Esc} doesn't work here. + ; Sometimes works after a few seconds. + } + } else { Spotify.GetCurrentSongElement()[-1].Click() + } } } static ToggleFullscreen() => Spotify.FullscreenState := !Spotify.FullscreenState