From bec69c0572e105725317e9999032f912556cccb7 Mon Sep 17 00:00:00 2001 From: Avi Wadhwa Date: Sun, 14 Apr 2024 19:12:40 -0700 Subject: [PATCH] Lyrics Refresh button when Apple Music ID -> Spotify ID fails, minor comment cleanup in main() and viewmodel --- .../SpotifyLyricsInMenubarApp.swift | 21 ++++++++++++------- SpotifyLyricsInMenubar/viewModel.swift | 4 +--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift index 9f9d545..b750fb1 100644 --- a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift +++ b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift @@ -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 @@ -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") { @@ -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 { @@ -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 { diff --git a/SpotifyLyricsInMenubar/viewModel.swift b/SpotifyLyricsInMenubar/viewModel.swift index e7fe544..7c058a8 100644 --- a/SpotifyLyricsInMenubar/viewModel.swift +++ b/SpotifyLyricsInMenubar/viewModel.swift @@ -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