Skip to content

Commit

Permalink
Lyrics Refresh button when Apple Music ID -> Spotify ID fails, minor …
Browse files Browse the repository at this point in the history
…comment cleanup in main() and viewmodel
  • Loading branch information
aviwad committed Apr 15, 2024
1 parent e70fa5b commit bec69c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 14 additions & 7 deletions SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ServiceManagement
struct SpotifyLyricsInMenubarApp: App {
@StateObject var viewmodel = viewModel.shared
@AppStorage("launchOnLogin") var launchOnLogin: Bool = false
// True: means Apple Music, False: Spotify
@AppStorage("spotifyOrAppleMusic") var spotifyOrAppleMusic: Bool = false
@AppStorage("showLyrics") var showLyrics: Bool = true
@AppStorage("hasOnboarded") var hasOnboarded: Bool = false
Expand All @@ -36,6 +37,17 @@ struct SpotifyLyricsInMenubarApp: App {
}
}
}
// Special case where Apple Music -> Spotify ID matching fails (perhaps Apple Music music was not the media in foreground, network failure, genuine no match)
// Apple Music Persistent ID exists but Spotify ID (currently playing) is nil
} else if viewmodel.currentlyPlayingAppleMusicPersistentID != nil, viewmodel.currentlyPlaying == nil {
Text("No Lyrics Found ☹️")
Button("Check For Lyrics Again") {
Task {
// Fetch updates the currentlyPlaying ID which will call Lyric Updater
try await viewmodel.appleMusicFetch()
}
}

}
Divider()
Button(launchOnLogin ? "Don't Launch At Login" : "Automatically Launch On Login") {
Expand Down Expand Up @@ -67,15 +79,10 @@ struct SpotifyLyricsInMenubarApp: App {
return
}
print("Application just started. lets check whats playing")
// if spotifyOrAppleMusic ? viewmodel.appleMusicScript?.playerState == .playing : viewmodel.spotifyScript?.playerState == .playing {
// viewmodel.isPlaying = true
// } else {
// viewmodel.isPlaying = false
// }
viewmodel.isPlaying = spotifyOrAppleMusic ? viewmodel.appleMusicScript?.playerState == .playing : viewmodel.spotifyScript?.playerState == .playing
if spotifyOrAppleMusic {
if let currentTrackName = viewmodel.appleMusicScript?.currentTrack?.name {
// viewmodel.currentlyPlaying = nil
// Don't set currentlyPlaying here: the persistentID change triggers the appleMusicFetch which will set spotify's currentlyPlaying
if currentTrackName == "" {
viewmodel.currentlyPlayingName = nil
} else {
Expand Down Expand Up @@ -125,7 +132,7 @@ struct SpotifyLyricsInMenubarApp: App {
}
if spotifyOrAppleMusic {
if let currentTrackName = viewmodel.appleMusicScript?.currentTrack?.name {
// viewmodel.currentlyPlaying = nil
// Don't set currentlyPlaying here: the persistentID change triggers the appleMusicFetch which will set spotify's currentlyPlaying
if currentTrackName == "" {
viewmodel.currentlyPlayingName = nil
} else {
Expand Down
4 changes: 1 addition & 3 deletions SpotifyLyricsInMenubar/viewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,13 @@ extension viewModel {
// check for musickit auth
if status != .authorized || appleMusicStorePlaybackID == nil {
print("not authorized (or we dont have playback id yet) , lets wait a bit")
// A little delay to make sure we have musickit auth + storeplayback id by then (most likely)
try await Task.sleep(nanoseconds: 100000000)
if status != .authorized {
print("still not authorized i give up")
}
}
print("authorized")
// A little delay to make sure we have musickit auth + storeplayback id by then (most likely)
// Faulty
//try await Task.sleep(nanoseconds: 100000000)
guard let appleMusicStorePlaybackID else {
print("no playback store id, giving up")
return
Expand Down

0 comments on commit bec69c0

Please sign in to comment.