Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: keep Canvas in shared stories while the redesign hides it (#131)
My-Name-Is-Jeffefe2ad556835
diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 8230c5ef..f22a6cba 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -241,8 +241,10 @@ NSNotificationName const SGSingButtonDidChangeNotification = @"harness.singButto#import "Shared/AnimatedArtwork/AnimatedArtwork.h"NSArray<NSString *> *SGMotionSourceOrder(void) { return @[@"canvas", @"applemusic"]; }NSURL *SGMotionCanvasIn(NSDictionary *metadata) {- id address = metadata[@"canvas.url"];- return [metadata[@"canvas.type"] hasPrefix:@"VIDEO"] && [address isKindOfClass:NSString.class] ? [NSURL URLWithString:address] : nil;+ // PlayerField.x moves the keys under SGMotionHiddenCanvas, as on the phone.+ id type = metadata[@"canvas.type"] ?: metadata[SGMotionHiddenCanvas @"canvas.type"];+ id address = metadata[@"canvas.url"] ?: metadata[SGMotionHiddenCanvas @"canvas.url"];+ return [type hasPrefix:@"VIDEO"] && [address isKindOfClass:NSString.class] ? [NSURL URLWithString:address] : nil;}void SGMotionClipFor(NSString *uri, NSURL *canvas, NSString *artist, NSString *album, SGMotionShape shape, CGFloat pixels,void (^done)(NSURL *file, NSString *source)) {diff --git a/tweak/Sources/Redesigned/Player/PlayerField.x b/tweak/Sources/Redesigned/Player/PlayerField.xindex e6ff4795..e98912bf 100644--- a/tweak/Sources/Redesigned/Player/PlayerField.x+++ b/tweak/Sources/Redesigned/Player/PlayerField.x@@ -22,6 +22,7 @@#import "Settings/SGModPage.h"#import "Redesigned/Kit/SGRKit.h"#import "Player.h"+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"// Past the plane's edges: above for the pull that dismisses the player, below for the bounce at the end// of the cards.@@ -176,6 +177,35 @@ static void publishCover(void) {}%end+#pragma mark - Canvas++// The artwork is the picture; Spotify's Canvas video would cover the field and the corners. The player makes+// its Canvas cell (CanvasNowPlayingCell) only for a track whose metadata names a Canvas, so the keys move under+// SGMotionHiddenCanvas. ios-feature-canvas.canvas_enabled stays on: forced off, it also took the Canvas off the+// share sheet's story card (issue #87), which finds it without these keys.+static char kTrackMetadataKey;++%hook SPTPlayerTrack+- (NSDictionary *)metadata {+ NSDictionary *metadata = %orig;+ if (!metadata) return nil;+ // Read for every track many times a second, so the stripped copy is kept beside the dictionary it copies,+ // as LyricsHook.x does. A local file's edit (LocalFileInfo.x) hands out a new one, which is looked at again.+ NSArray *cached = objc_getAssociatedObject(self, &kTrackMetadataKey);+ if (cached.firstObject == metadata) return cached.lastObject;+ NSMutableDictionary *stripped = nil;+ for (NSString *key in metadata) {+ if (![key hasPrefix:@"canvas."]) continue;+ if (!stripped) stripped = [metadata mutableCopy];+ stripped[[SGMotionHiddenCanvas stringByAppendingString:key]] = metadata[key];+ [stripped removeObjectForKey:key];+ }+ NSDictionary *result = stripped ? [stripped copy] : metadata; // handed out again, so unchangeable+ objc_setAssociatedObject(self, &kTrackMetadataKey, @[metadata, result], OBJC_ASSOCIATION_RETAIN);+ return result;+}+%end+// A cover that loads after the track changed sets an image and lays nothing out, so the list is looked// at again a few times while it comes in, as the Kit does for the bar.@interface SGRPlayerCoverWatcher : NSObject <SGPlayerStateObserver>@@ -202,8 +232,6 @@ static SGRPlayerCoverWatcher *sg_coverWatcher;%ctor {// Registered whatever the switch says: the flag rows elsewhere lock to these while it is on.NSMutableDictionary<NSString *, id> *flags = [@{- // The artwork is the picture; Canvas video would cover the field and the corners.- @"ios-feature-canvas.canvas_enabled": @NO,// The header, slider and sheets the trees were recorded with (trees/clean/player/01.txt:122// id=Context menu, :216 SPTNowPlayingSliderV2).@"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled": @YES,diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.hindex 9978c41c..9158e09a 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h@@ -62,7 +62,10 @@ void SGMotionSongsWithISRC(NSString *isrc, void (^done)(NSArray *songs));#define SGKeyMotionSources @"spotifyglass.motion.sources"NSArray<NSString *> *SGMotionSourceOrder(void);BOOL SGMotionAppleMusicOn(void);-// The track's Canvas video as its metadata names it (canvas.url, of a canvas.type that is a video), or nil.+// The redesign moves a track's canvas.* metadata keys under this prefix, so Spotify's player makes no Canvas cell.+#define SGMotionHiddenCanvas @"spotifyglass."+// The track's Canvas video as its metadata names it (canvas.url, of a canvas.type that is a video, under either+// name), or nil.NSURL *SGMotionCanvasIn(NSDictionary *metadata);// The first clip the order finds for the track `uri`, as a local file, or nil, and the key of the source it// came from. `canvas` is the track's Canvas video, nil when its metadata names none, and then Spotify'sdiff --git a/tweak/Sources/Shared/AnimatedArtwork/MotionSources.m b/tweak/Sources/Shared/AnimatedArtwork/MotionSources.mindex c32039c3..8d0ec15e 100644--- a/tweak/Sources/Shared/AnimatedArtwork/MotionSources.m+++ b/tweak/Sources/Shared/AnimatedArtwork/MotionSources.m@@ -36,7 +36,8 @@ BOOL SGMotionAppleMusicOn(void) {NSURL *SGMotionCanvasIn(NSDictionary *metadata) {if (![metadata isKindOfClass:NSDictionary.class]) return nil;- id type = metadata[@"canvas.type"], address = metadata[@"canvas.url"];+ id type = metadata[@"canvas.type"] ?: metadata[SGMotionHiddenCanvas @"canvas.type"];+ id address = metadata[@"canvas.url"] ?: metadata[SGMotionHiddenCanvas @"canvas.url"];BOOL video = [type isKindOfClass:NSString.class] && [type rangeOfString:@"video" options:NSCaseInsensitiveSearch].location != NSNotFound;return video && [address isKindOfClass:NSString.class] ? [NSURL URLWithString:address] : nil;}