Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: Automatic puts back what the track showed before its pick, or asks again
My-Name-Is-Jefff708c4a66c69
diff --git a/harness/lyrics-walk/README.md b/harness/lyrics-walk/README.mdindex 40e740b1..68314064 100644--- a/harness/lyrics-walk/README.md+++ b/harness/lyrics-walk/README.md@@ -9,7 +9,11 @@ redesigned player's ⋯ (`LyricsPick.m`, issue #67). Every source is answered by- a later walk, once the walk's answers have been forgotten (40 tracks), asks the pick first and keepsits lines as the pick's; with the pick's request failing, the pick stands and the walk's answer is keptas the order's, not the pick's, and the next walk asks the pick again; with the pick answering nothing,- the pick is dropped.+ the pick is dropped;+- a pick made while a walk runs stands, and when that walk began on an earlier pick, Automatic puts back+ what the track showed before any pick and the next request walks the order again;+- Automatic for a track whose record is gone (40 picks later) asks for the track again as on a first play,+ and never drops the lines shown for none.It does not cover the sources' own requests, Spotify's own lines weighed against the walk's (LyricsHook.x),or the menu.diff --git a/harness/lyrics-walk/check.m b/harness/lyrics-walk/check.mindex 490e874d..81aadc7f 100644--- a/harness/lyrics-walk/check.m+++ b/harness/lyrics-walk/check.m@@ -190,6 +190,44 @@ int main(int argc, char **argv) {CHECK([got.provider isEqualToString:@"Musixmatch"] && !got.picked && !SGLyricsChosenSource(@"t1"));sg_answers[@"lrclib"] = lines(YES);+ // A pick made while the walk runs stands, with the walk begun on an earlier pick. That walk asked the+ // earlier pick first, so its answer is not what the order would choose: Automatic puts back what the+ // track showed before any pick, and the next request walks the order again.+ NSArray<SGKaraokeLine *> *spotify = SGKaraokeStaticLines(@[@"s"]);+ sg_shown[@"t2"] = spotify;+ offers(@"t2");+ SGLyricsChooseSource(@"t2", @"lrclib");+ CHECK(![sg_shown[@"t2"] isEqualToArray:spotify]);+ walkOthers(NO);+ sg_held = @"lrclib";+ __block SGLyricsResult *late = nil;+ SGLyricsFetch(@"t2", ^(SGLyricsResult *result) { late = result; });+ pump(^BOOL { return sg_release != nil; });+ SGLyricsChooseSource(@"t2", @"netease");+ sg_held = nil;+ sg_release();+ sg_release = nil;+ pump(^BOOL { return late != nil; });+ CHECK([late.provider isEqualToString:@"NetEase"] && late.picked && [SGLyricsChosenSource(@"t2") isEqualToString:@"netease"]);+ SGLyricsChooseAutomatic(@"t2");+ CHECK(!SGLyricsChosenSource(@"t2") && [sg_shown[@"t2"] isEqualToArray:spotify] && [SGLyricsCreditFor(@"t2") isEqualToString:@"Spotify"]);+ [sg_asked removeAllObjects];+ got = fetch(@"t2");+ CHECK([sg_asked isEqualToArray:@[@"musixmatch:t2"]] && [got.provider isEqualToString:@"Musixmatch"] && !got.picked);++ // Automatic once what it puts back is forgotten, 40 picks later: the track is asked for again as on a+ // first play, and the lines it shows are never dropped for none.+ offers(@"t3");+ SGLyricsChooseSource(@"t3", @"lrclib");+ walkOthers(YES);+ CHECK([SGLyricsChosenSource(@"t3") isEqualToString:@"lrclib"]);+ [sg_answers removeAllObjects];+ SGLyricsChooseAutomatic(@"t3");+ pump(^BOOL { return sg_askedAgain.count > 0; });+ [NSRunLoop.mainRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];+ CHECK(!SGLyricsChosenSource(@"t3") && [sg_askedAgain isEqualToArray:@[@"t3"]] && !sg_shown[@"t3"]);+ CHECK(!fetch(@"t3"));+printf("lyrics-walk: all checks passed\n");}return 0;diff --git a/tweak/Sources/Shared/Lyrics/KaraokeSource.x b/tweak/Sources/Shared/Lyrics/KaraokeSource.xindex b9eeb4c7..e9be2320 100644--- a/tweak/Sources/Shared/Lyrics/KaraokeSource.x+++ b/tweak/Sources/Shared/Lyrics/KaraokeSource.x@@ -295,6 +295,18 @@ static BOOL requestFromSpotify(NSString *trackID) {return YES;}+// Main queue only. The track's lines are forgotten, but for a look still out, and the track playing is asked+// for again as on a first play.+void SGKaraokeAskAgain(NSString *trackID) {+ if (!trackID || [sg_looking containsObject:trackID]) return;+ [sg_lyrics removeObjectForKey:trackID];+ [sg_requested removeObject:trackID];+ [sg_asking removeObject:trackID];+ [sg_losses removeObjectForKey:trackID];+ if ([trackID isEqualToString:SGKaraokePlayingTrack()]) SGKaraokeRequestLyrics(trackID);+ announce(trackID);+}+void SGKaraokeAskSpotifyForTiming(NSString *trackID) {dispatch_async(dispatch_get_main_queue(), ^{if (!trackID || [sg_requested containsObject:trackID]) return;diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.hindex 5c60fb84..8c5afbc6 100644--- a/tweak/Sources/Shared/Lyrics/Lyrics.h+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h@@ -147,6 +147,9 @@ void SGKaraokeRequestLyrics(NSString *trackID);// Asks Spotify's JSON lyrics for the track once, and keeps its lines only if they are more finely// timed than the ones kept: the lyrics view was left with plain text, and Spotify may have it timed.void SGKaraokeAskSpotifyForTiming(NSString *trackID);+// Forgets the track's lines and, for the track playing, asks for them again as on a first play: the sources'+// order walked, then Spotify's own weighed against the answer. Main queue.+void SGKaraokeAskAgain(NSString *trackID);// Whether EeveeSpotify is injected alongside the mod.BOOL SGEeveeSpotifyInjected(void);// EeveeSpotify is injected and answers Spotify's lyrics, by its own settings (lyricsSource, anddiff --git a/tweak/Sources/Shared/LyricsSources/LyricsPick.m b/tweak/Sources/Shared/LyricsSources/LyricsPick.mindex e572a1e6..f6ea33c3 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsPick.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsPick.m@@ -1,6 +1,12 @@// A source picked for one track (issue #67). The walk stops at the first source with timed lyrics, so a source// lower in the order that has the song better timed is never asked; the redesigned player's ⋯ asks them all for// the track playing, lists the ones with lines, and keeps the one picked as the track's lyrics.+//+// A pick keeps the source's answer as the track's, marked picked, and records what the track showed before it.+// A later walk asks the pick first: lines keep it, nothing drops it, a failed request leaves it and keeps the+// walk's answer unmarked. A pick made while a walk runs stands, and the walk's answer is recorded as the+// order's only when the walk ran the order as it is. Automatic puts the record back, or with the record gone+// has the lyrics asked for again as on a first play.#import "Core/SGCore.h"#import "LyricsSources.h"#import "Shared/Lyrics/Lyrics.h"@@ -166,14 +172,17 @@ void SGLyricsChooseAutomatic(NSString *trackID) {SGLyricsAutomatic *automatic = sg_automatic[trackID];[sg_chosen removeObjectForKey:trackID];[sg_automatic removeObjectForKey:trackID];- if (!automatic.kept) {- // What the order chose is no longer kept, or was never learned: the walk asks the order again.- SGLog(@"lyrics: pick dropped for %@, asking the order again", trackID);- SGLyricsRestoreKept(trackID, nil);- SGLyricsFetch(trackID, ^(SGLyricsResult *lyrics) { show(trackID, lyrics.provider, lyrics.karaokeLines); });+ // The order's answer when it was learned, else nothing, so the next request walks the order again.+ SGLyricsRestoreKept(trackID, automatic.kept);+ if (!automatic.lines) {+ // What the track showed is gone with its record, or was nothing while its walk ran: the lyrics are+ // asked for as on a first play, the order's answer weighed against Spotify's own where that is done.+ SGLog(@"lyrics: pick dropped for %@, asking again", trackID);+ SGKaraokeAskAgain(trackID);+ // The lyrics page drops the pick's lines on this and takes the answer as it comes.+ [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsSourceChosenNotification object:trackID];return;}SGLog(@"lyrics: pick dropped for %@, back to %@, %lu lines", trackID, automatic.credit, (unsigned long)automatic.lines.count);- SGLyricsRestoreKept(trackID, automatic.kept);show(trackID, automatic.credit, automatic.lines);}diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.mindex eed2d2e8..8b8fda5d 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m@@ -414,8 +414,9 @@ static void finish(SGLyricsWalk *walk) {SGLyricsKeepChosen(trackID, lyrics);} else if ([picked isKindOfClass:SGLyricsResult.class]) {// A source was picked from the player's ⋯ while the walk ran: the pick stands, and the walk's answer- // is what Automatic puts back.- SGLyricsNoteOrderChoice(trackID, lyrics);+ // is what Automatic puts back. Not when the walk began with a pick of its own: that one was asked+ // first and may have answered, so the walk never learned what the order would choose.+ if (!walk.picked) SGLyricsNoteOrderChoice(trackID, lyrics);lyrics = picked;} else if (lyrics || (everyoneAsked && !failed) || merged.instrumental) {// With a pick whose request failed, the walk's answer is kept, but not as the pick's: it weighs