Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: Spotify no longer freezes after launch when EeveeSpotify is injected with its own lyrics on
My-Name-Is-Jeffa07186be91d2
diff --git a/tweak/Sources/Shared/Lyrics/KaraokeSource.x b/tweak/Sources/Shared/Lyrics/KaraokeSource.xindex 903394c3..a014855e 100644--- a/tweak/Sources/Shared/Lyrics/KaraokeSource.x+++ b/tweak/Sources/Shared/Lyrics/KaraokeSource.x@@ -12,6 +12,8 @@#import "Shared/AnimatedArtwork/AnimatedArtwork.h"#import "Shared/LyricsSources/LyricsSources.h"#import "Headers/SPTPlayer.h"+#import <mach-o/dyld.h>+#import <objc/runtime.h>static const NSUInteger kKeptTracks = 40;static const NSUInteger kSeenTracks = 200;@@ -190,10 +192,65 @@ static void askAgainLater(NSString *trackID) {});}-// Main queue only. NO, asking nothing, before any request of Spotify's has shown the headers.+// Whether a loaded image has this file name; EeveeSpotify's Reincarnated fork also loads EeveeSwiftProtobuf.+static BOOL imageLoaded(NSString *wanted) {+ for (uint32_t i = 0; i < _dyld_image_count(); i++) {+ const char *image = _dyld_get_image_name(i);+ if (image && [@(image).lastPathComponent caseInsensitiveCompare:wanted] == NSOrderedSame) return YES;+ }+ return NO;+}++// Only loaded code counts, never a file's name: an IPA can keep EeveeSpotify's icons+// ([email protected]) after its dylib is gone. EeveeSpotify ships as EeveeSpotify.dylib, but an+// IPA builder can rename it (EeveeSpotify-6.6.dylib) or wrap it as EeveeSpotify.framework, so its Swift+// settings page, which every fork keeps under the module EeveeSpotify, counts as well. It may load after+// the mod, so a NO is asked again, though only once more images have loaded, and a YES is kept.+BOOL SGEeveeSpotifyInjected(void) {+ static BOOL found;+ static uint32_t looked;+ uint32_t images = _dyld_image_count();+ if (found || images == looked) return found;+ looked = images;+ if (imageLoaded(@"EeveeSpotify.dylib") || objc_getClass("_TtC12EeveeSpotify27EeveeSettingsViewController")) {+ found = YES;+ SGLog(@"lyrics: EeveeSpotify is injected");+ }+ return found;+}++// Whether EeveeSpotify answers Spotify's lyrics, read from its own settings in the standard defaults.+// It decides at launch and asks for a restart to change, so the first answer is kept. Anything not+// known to turn its lyrics off counts as on, a missing key and an unknown version included.+static BOOL eeveeLyricsOn(void) {+ static BOOL on;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;+ id source = [defaults objectForKey:@"lyricsSource"]; // 4 is "Do not replace lyrics"+ id patch = [defaults objectForKey:@"patchType"]; // Reincarnated: 0 not set, 1 off, 2 on+ BOOL sourceOff = [source isKindOfClass:NSNumber.class] && [source integerValue] == 4;+ BOOL unpatched = imageLoaded(@"EeveeSwiftProtobuf") && [patch isKindOfClass:NSNumber.class]+ && ([patch integerValue] == 0 || [patch integerValue] == 1);+ on = !(getenv("EEVEE_DISABLE_ALL") || sourceOff || unpatched);+ SGLog(@"lyrics: EeveeSpotify's lyrics are %@ (lyricsSource %@, patchType %@)", on ? @"on" : @"off", source, patch);+ });+ return on;+}++BOOL SGLyricsStandAsideForEevee(void) {+ return SGEeveeSpotifyInjected() && eeveeLyricsOn() && !SGHidden(SGKeyLyricsBesideEevee);+}++BOOL SGEeveeLyricsOn(void) {+ return SGEeveeSpotifyInjected() && eeveeLyricsOn();+}++// Main queue only. NO, asking nothing, before any request of Spotify's has shown the headers, and with+// EeveeSpotify injected, whose lyrics answer the request: a second asker beside it froze Spotify after launch.static BOOL requestFromSpotify(NSString *trackID) {NSDictionary<NSString *, NSString *> *headers = sg_spclientHeaders;- if (!headers) return NO;+ if (!headers || SGLyricsStandAsideForEevee()) return NO;[sg_requested addObject:trackID];[sg_asking addObject:trackID];[sg_looking addObject:trackID];diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.hindex e9944e48..0da7344d 100644--- a/tweak/Sources/Shared/Lyrics/Lyrics.h+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h@@ -117,6 +117,17 @@ 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);+// Whether EeveeSpotify is injected alongside the mod.+BOOL SGEeveeSpotifyInjected(void);+// EeveeSpotify is injected and answers Spotify's lyrics, by its own settings (lyricsSource, and+// patchType in its Reincarnated fork). Both answering the same request froze Spotify after launch, so+// then the mod's sources and its own requests for Spotify's lyrics stand aside (LyricsSources'+// SGLyricsEnabled, SGKaraokeRequestLyrics). Its settings are read once, as it reads them at launch.+BOOL SGEeveeLyricsOn(void);+// The Lyrics page's "Use these sources anyway", for an EeveeSpotify whose settings read wrong.+#define SGKeyLyricsBesideEevee @"spotifyglass.lyrics.besideEevee"+// SGEeveeLyricsOn, unless the user asked for the mod's sources beside it.+BOOL SGLyricsStandAsideForEevee(void);// The base62 id, a local file's lyrics key (Shared/LocalFiles), nil before the player reported.NSString *SGKaraokePlayingTrack(void);NSInteger SGKaraokePositionMs(void); // negative when unknowndiff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.mindex f8adffe6..eab57735 100644--- a/tweak/Sources/Shared/Lyrics/LyricsSettings.m+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m@@ -21,6 +21,12 @@ SGModSection *SGLyricsSourcesSection(BOOL namingSource) {NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObjects:sources, imported,SGOptionRow(@"Lyrics for every track", @"Even where Spotify has none", SGKeyLyricsAllTracks), SGSpicyLyricsKeyRow(), nil];if (namingSource) [rows addObject:SGOptionRow(@"Show source", nil, SGKeyLyricsCredit)];+ if (SGEeveeLyricsOn()) {+ [rows addObject:SGOptionRow(@"Use these sources anyway", @"Only if EeveeSpotify's lyrics are really off", SGKeyLyricsBesideEevee)];+ return SGNotedSection(@"Sources", rows, @"EeveeSpotify's lyrics are on, so it answers Spotify's lyrics and these sources stay "+ @"off: both answering froze Spotify after launch. Turn its lyrics off in its own "+ @"settings to use these.");+ }return SGSection(@"Sources", rows);}diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.mindex bec08b8e..c3b946e4 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m@@ -199,8 +199,10 @@ void SGLyricsSetOrder(NSArray<NSString *> *keys) {[NSUserDefaults.standardUserDefaults setObject:keys ?: @[] forKey:SGKeyLyricsProviders];}+// With EeveeSpotify injected, its own lyrics answer Spotify's requests and the mod's stand aside: two+// tweaks holding and answering the same request froze Spotify after launch.BOOL SGLyricsEnabled(void) {- return SGLyricsOrder().count > 0;+ return SGLyricsOrder().count > 0 && !SGLyricsStandAsideForEevee();}#pragma mark - what is known about the track