Skip to content

Commit

Permalink
Carefully avoid running the lyric updater when not onboarding. Force …
Browse files Browse the repository at this point in the history
…a lyric-updater start once finished onboarding. (this is needed because we have already fetched all the song details in the background)
  • Loading branch information
aviwad committed May 3, 2024
1 parent a2b5fb3 commit 2d0894d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct SpotifyLyricsInMenubarApp: App {
}
viewmodel.currentlyPlayingLyrics = try await viewmodel.fetchNetworkLyrics(for: currentlyPlaying, currentlyPlayingName, spotifyOrAppleMusic)
print("HELLOO")
if viewmodel.isPlaying, !viewmodel.currentlyPlayingLyrics.isEmpty, showLyrics {
if viewmodel.isPlaying, !viewmodel.currentlyPlayingLyrics.isEmpty, showLyrics, hasOnboarded {
viewmodel.startLyricUpdater(appleMusicOrSpotify: spotifyOrAppleMusic)
}
}
Expand All @@ -59,6 +59,7 @@ struct SpotifyLyricsInMenubarApp: App {
launchOnLogin = true
}
}
.disabled(!hasOnboarded)
Button(showLyrics ? "Don't Show Lyrics" : "Show Lyrics") {
if showLyrics {
showLyrics = false
Expand All @@ -68,6 +69,7 @@ struct SpotifyLyricsInMenubarApp: App {
viewmodel.startLyricUpdater(appleMusicOrSpotify: spotifyOrAppleMusic)
}
}
.disabled(!hasOnboarded)
Divider()
Button("Settings") {
NSApplication.shared.activate(ignoringOtherApps: true)
Expand Down Expand Up @@ -227,14 +229,17 @@ struct SpotifyLyricsInMenubarApp: App {
print(currentTrack)
}
}
viewmodel.startLyricUpdater(appleMusicOrSpotify: spotifyOrAppleMusic)
} else {
viewmodel.stopLyricUpdater()
}
}
.onChange(of: viewmodel.cookie) { newCookie in
viewmodel.accessToken = nil
}
.onChange(of: viewmodel.isPlaying) { nowPlaying in
if nowPlaying, showLyrics {
if !viewmodel.currentlyPlayingLyrics.isEmpty, spotifyOrAppleMusic ? viewmodel.appleMusicScript?.playerPosition != 0.0 : viewmodel.spotifyScript?.playerPosition != 0.0 {
if nowPlaying, showLyrics, hasOnboarded {
if !viewmodel.currentlyPlayingLyrics.isEmpty {
print("timer started for spotify change, lyrics not nil")
viewmodel.startLyricUpdater(appleMusicOrSpotify: spotifyOrAppleMusic)
}
Expand All @@ -256,7 +261,7 @@ struct SpotifyLyricsInMenubarApp: App {
Task {
if let nowPlaying, let currentlyPlayingName = viewmodel.currentlyPlayingName, let lyrics = await viewmodel.fetch(for: nowPlaying, currentlyPlayingName, spotifyOrAppleMusic) {
viewmodel.currentlyPlayingLyrics = lyrics
if viewmodel.isPlaying, !viewmodel.currentlyPlayingLyrics.isEmpty, showLyrics {
if viewmodel.isPlaying, !viewmodel.currentlyPlayingLyrics.isEmpty, showLyrics, hasOnboarded {
print("STARTING UPDATER")
viewmodel.startLyricUpdater(appleMusicOrSpotify: spotifyOrAppleMusic)
}
Expand Down

0 comments on commit 2d0894d

Please sign in to comment.