Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: animated artwork has an ordered list of sources, like the lyrics
My-Name-Is-Jefffa58ad499f1f
diff --git a/harness/album/stubs.m b/harness/album/stubs.mindex 45c332fe..f521c9f3 100644--- a/harness/album/stubs.m+++ b/harness/album/stubs.m@@ -14,3 +14,6 @@ void SGRObservePlayerTransition(id owner, void (^began)(id owner), void (^ended)// Shared/Fonts/FontImport.m: no font of the user's own in the harness.NSString *SGRegisterCustomFont(void) { return nil; }++// MotionSources.m: Apple Music is on, as it is by default.+BOOL SGMotionAppleMusicOn(void) { return YES; }diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 5f11b2c4..699e66af 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -166,3 +166,13 @@ NSString *SGSingModelError(void) { return nil; }NSString *SGSingModelSizeText(void) { return @""; }void SGSingDownloadModel(void) {}void SGSingCancelModelDownload(void) {}++// MotionSources.m: the default order, Canvas then Apple Music, over the catalog the harness builds.+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"+void SGMotionClipFor(NSURL *canvas, NSString *artist, NSString *album, SGMotionShape shape, CGFloat pixels, void (^done)(NSURL *file)) {+ void (^apple)(void) = ^{ SGMotionAlbumCover(artist, album, shape, pixels, done); };+ if (!canvas) { apple(); return; }+ SGMotionFile(canvas, ^(NSURL *file) { if (file) done(file); else apple(); });+}+SGModRow *SGMotionSourcesRow(void) { return nil; }+BOOL SGMotionAppleMusicOn(void) { return YES; }diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.xindex 523bdf8a..897ac5cf 100644--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x@@ -205,7 +205,7 @@ static void *kReadyContext = &kReadyContext;- (void)playMotionForArtist:(NSString *)artist album:(NSString *)album {NSString *key = artist.length && album.length ? [NSString stringWithFormat:@"%@\n%@", artist, album] : nil;- if (!key || [key isEqualToString:_motionAlbum] || !SGEnabled(SGRKeyAlbumMotion)) return;+ if (!key || [key isEqualToString:_motionAlbum] || !SGEnabled(SGRKeyAlbumMotion) || !SGMotionAppleMusicOn()) return;_motionAlbum = key;// The player's size: at the screen's full width a square cover ran to the 1920 stream, tens of MB.CGFloat pixels = SGMotionPixels();diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xindex 419ab4b4..ccce4aca 100644--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -374,19 +374,9 @@ void SGRPlayerMotionLyricsChanged(void) {NSURL *canvas = video && [address isKindOfClass:NSString.class] ? [NSURL URLWithString:address] : nil;NSString *artist = state.track.artistName, *album = metadata[@"album_title"];CGFloat pixels = SGMotionPixels();- void (^apple)(void) = ^{- SGMotionAlbumCover(artist, album, SGMotionTall, pixels, ^(NSURL *file) { show(track, file); });- };static NSUInteger logged;if (logged++ < 3) SGLog(@"redesign player: canvas %@ (%@)", canvas ? @"found" : @"none", type ?: @"no type");- if (!canvas) {- apple();- return;- }- SGMotionFile(canvas, ^(NSURL *file) {- if (file) show(track, file);- else apple();- });+ SGMotionClipFor(canvas, artist, album, SGMotionTall, pixels, ^(NSURL *file) { show(track, file); });}@enddiff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex 6cebed79..7b629e3f 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -303,10 +303,12 @@ UIViewController *SGRPlayerSettingsPage(NSArray *more) {});SGModRow *lowData = SGOptionRow(@"Download in Low Data Mode", @"Animated artwork, up to about 7 MB a song", SGKeyMotionLowData);lowData.visible = ^BOOL { return SGRPlayerBackground() == SGRPlayerBackgroundAnimated; };+ SGModRow *sources = SGMotionSourcesRow();+ sources.visible = lowData.visible;NSMutableArray<SGModSection *> *sections = [NSMutableArray arrayWithObjects:- SGNotedSection(nil, @[background, lowData],- @"Animated plays the Canvas or Apple Music's animated cover over Fluid, and the player's ⋯ menu switches between the two."),+ SGNotedSection(nil, @[background, sources, lowData],+ @"Animated plays the first clip its sources have, over Fluid, and the player's ⋯ menu switches between the two."),SGSection(nil, SGRNowPlayingBarRows()), nil];[sections addObjectsFromArray:more];SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:nil];diff --git a/tweak/Sources/Settings/SGSourcesPage.h b/tweak/Sources/Settings/SGSourcesPage.hnew file mode 100644index 00000000..359f3163--- /dev/null+++ b/tweak/Sources/Settings/SGSourcesPage.h@@ -0,0 +1,13 @@+// A page that orders sources, the lyrics' and the animated artwork's: drag them into the order they are+// asked; the ones below the line are off, and a tap moves one across.+#import <UIKit/UIKit.h>++@interface SGSource : NSObject+@property (nonatomic, copy) NSString *key, *name, *detail;++ (instancetype)sourceWithKey:(NSString *)key name:(NSString *)name detail:(NSString *)detail;+@end++// `all` is every source in the order the ones that are off are listed in; `order` and `setOrder` read and+// keep the keys that are on, in the order they are asked.+UIViewController *SGSourcesPageMake(NSString *title, NSString *note, NSArray<SGSource *> *all,+ NSArray<NSString *> *(^order)(void), void (^setOrder)(NSArray<NSString *> *keys));diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSourcesPage.m b/tweak/Sources/Settings/SGSourcesPage.msimilarity index 71%rename from tweak/Sources/Shared/LyricsSources/LyricsSourcesPage.mrename to tweak/Sources/Settings/SGSourcesPage.mindex 489e9bfc..331176eb 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSourcesPage.m+++ b/tweak/Sources/Settings/SGSourcesPage.m@@ -1,8 +1,17 @@-// Drag sources into the order they are asked; the ones below the line are off.#import "Core/SGCore.h"-#import "Settings/SGPage.h"-#import "Settings/SGPageStyle.h"-#import "LyricsSources.h"+#import "SGPage.h"+#import "SGPageStyle.h"+#import "SGSourcesPage.h"++@implementation SGSource++ (instancetype)sourceWithKey:(NSString *)key name:(NSString *)name detail:(NSString *)detail {+ SGSource *source = [self new];+ source.key = key;+ source.name = name;+ source.detail = detail;+ return source;+}+@endtypedef NS_ENUM(NSInteger, SGSourcesSection) {SGSourcesSectionOn = 0,@@ -11,6 +20,10 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {};@interface SGSourcesPage : SGPage+@property (nonatomic, copy) NSString *note;+@property (nonatomic, copy) NSArray<SGSource *> *all;+@property (nonatomic, copy) NSArray<NSString *> *(^order)(void);+@property (nonatomic, copy) void (^setOrder)(NSArray<NSString *> *keys);@end@implementation SGSourcesPage {@@ -19,22 +32,22 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {UIView *_footer;}-- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;- self.title = @"Lyrics sources";- return self;+- (SGSource *)sourceFor:(NSString *)key {+ for (SGSource *source in self.all) if ([source.key isEqualToString:key]) return source;+ return nil;}- (void)read {- _on = [SGLyricsOrder() mutableCopy];+ _on = [NSMutableArray array];+ for (NSString *key in self.order()) if ([self sourceFor:key] && ![_on containsObject:key]) [_on addObject:key];_off = [NSMutableArray array];- for (SGLyricsProvider *provider in SGLyricsAllProviders()) {- if (![_on containsObject:provider.key]) [_off addObject:provider.key];+ for (SGSource *source in self.all) {+ if (![_on containsObject:source.key]) [_off addObject:source.key];}}- (void)save {- SGLyricsSetOrder(_on);+ self.setOrder(_on);}- (void)viewDidLoad {@@ -42,8 +55,7 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {[self read];self.tableView.editing = YES;self.tableView.allowsSelectionDuringEditing = YES;- _footer = SGNote(@"Asked top to bottom until one has word timing. Sources get only the track, never "- "your account.");+ _footer = SGNote(self.note);self.tableView.tableFooterView = _footer;}@@ -84,7 +96,7 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {UITableViewCell *cell = SGDequeueCell(table, @"source");- SGLyricsProvider *provider = SGLyricsProviderFor([self keysIn:path.section][(NSUInteger)path.row]);+ SGSource *provider = [self sourceFor:[self keysIn:path.section][(NSUInteger)path.row]];BOOL on = path.section == SGSourcesSectionOn;// The asked ones are numbered, so the order reads as an order rather than a list.NSString *title = on ? [NSString stringWithFormat:@"%ld. %@", (long)path.row + 1, provider.name] : provider.name;@@ -130,9 +142,9 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {[_on removeObject:key];// Back to where it sits among the sources that are off, in the order they all come in.NSUInteger at = 0;- for (SGLyricsProvider *provider in SGLyricsAllProviders()) {- if ([provider.key isEqualToString:key]) break;- if ([_off containsObject:provider.key]) at++;+ for (SGSource *source in self.all) {+ if ([source.key isEqualToString:key]) break;+ if ([_off containsObject:source.key]) at++;}[_off insertObject:key atIndex:at];} else {@@ -145,6 +157,13 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {@end-UIViewController *SGLyricsSourcesPage(void) {- return [SGSourcesPage new];+UIViewController *SGSourcesPageMake(NSString *title, NSString *note, NSArray<SGSource *> *all,+ NSArray<NSString *> *(^order)(void), void (^setOrder)(NSArray<NSString *> *keys)) {+ SGSourcesPage *page = [[SGSourcesPage alloc] initWithStyle:UITableViewStyleInsetGrouped];+ page.title = title;+ page.note = note;+ page.all = all;+ page.order = order;+ page.setOrder = setOrder;+ return page;}diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.hindex 5510a4c7..2a317db4 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h@@ -42,6 +42,19 @@ CGFloat SGMotionPixels(void);// when the catalog could not be asked. Kept for the launch. Main queue.void SGMotionSongsWithISRC(NSString *isrc, void (^done)(NSArray *songs));+// Where moving artwork comes from (MotionSources.m): the keys that are on, in the order they are asked,+// Spotify's Canvas then Apple Music's animated cover unless the user changed it.+#define SGKeyMotionSources @"spotifyglass.motion.sources"+NSArray<NSString *> *SGMotionSourceOrder(void);+BOOL SGMotionAppleMusicOn(void);+// The first clip the order finds for a track, as a local file, or nil. `canvas` is the track's Canvas+// video, nil when it has none. Main queue.+void SGMotionClipFor(NSURL *canvas, NSString *artist, NSString *album, SGMotionShape shape, CGFloat pixels,+ void (^done)(NSURL *file));+// The row that opens the ordered list, for the Player page and the lock screen's.+@class SGModRow;+SGModRow *SGMotionSourcesRow(void);+// Any remote video (a Canvas) as a local file, or nil. Main queue.void SGMotionFile(NSURL *remote, void (^done)(NSURL *file));// Where a video the mod makes itself is kept under `key`, among the downloads, which are kept to thediff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.mindex a4cca41e..edfa7ad9 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m@@ -25,11 +25,14 @@ NSArray *SGLockScreenMotionRows(void) {SGLockArtwork artwork = SGLockScreenArtwork();return artwork == SGLockArtworkMotion || artwork == SGLockArtworkEverySong;};+ SGModRow *sources = SGMotionSourcesRow();+ sources.visible = lowData.visible;return @[SGChoiceRow(@"Full-screen artwork", @"The Canvas or Apple Music's animated cover, or the lyrics a line at a time. "@"Every song puts the cover over a moving blur of it where a song has neither",SGKeyLockScreenArtwork, @[@"Off", @"Moving artwork", @"Lyrics", @"Every song"], SGLockArtworkOff),style,+ sources,lowData,];}diff --git a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.xindex fab2bbbc..8e5c7c87 100644--- a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x+++ b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x@@ -101,19 +101,9 @@ static void showCover(NSString *uri, NSString *picture) {CGFloat pixels = SGMotionPixels();BOOL everySong = SGLockScreenArtwork() == SGLockArtworkEverySong;NSString *picture = pictureOf(state.track, metadata);- void (^apple)(void) = ^{- SGMotionAlbumCover(artist, album, SGMotionTall, pixels, ^(NSURL *file) {- if (file) show(uri, file);- else if (everySong) showCover(uri, picture);- });- };- if (!canvas) {- apple();- return;- }- SGMotionFile(canvas, ^(NSURL *file) {+ SGMotionClipFor(canvas, artist, album, SGMotionTall, pixels, ^(NSURL *file) {if (file) show(uri, file);- else apple();+ else if (everySong) showCover(uri, picture);});}}diff --git a/tweak/Sources/Shared/AnimatedArtwork/MotionSources.m b/tweak/Sources/Shared/AnimatedArtwork/MotionSources.mnew file mode 100644index 00000000..7033d54a--- /dev/null+++ b/tweak/Sources/Shared/AnimatedArtwork/MotionSources.m@@ -0,0 +1,76 @@+// Where a track's moving artwork comes from, in the user's order: the Canvas Spotify gives the track and+// Apple Music's animated album cover. Either can be switched off. The player and the lock screen walk the+// order (SGMotionClipFor); the album page's animated cover asks only whether Apple Music is on.+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Settings/SGSourcesPage.h"+#import "AnimatedArtwork.h"++static NSString *const kCanvas = @"canvas", *const kAppleMusic = @"applemusic";++static NSArray<SGSource *> *allSources(void) {+ return @[+ [SGSource sourceWithKey:kCanvas name:@"Spotify Canvas" detail:@"The track's own looping video"],+ [SGSource sourceWithKey:kAppleMusic name:@"Apple Music" detail:@"The album's animated cover"],+ ];+}++NSArray<NSString *> *SGMotionSourceOrder(void) {+ id stored = [NSUserDefaults.standardUserDefaults arrayForKey:SGKeyMotionSources];+ NSArray *keys = [stored isKindOfClass:NSArray.class] ? stored : @[kCanvas, kAppleMusic];+ NSMutableArray<NSString *> *order = [NSMutableArray array];+ for (id key in keys) {+ if (([key isEqual:kCanvas] || [key isEqual:kAppleMusic]) && ![order containsObject:key]) [order addObject:key];+ }+ return order;+}++BOOL SGMotionAppleMusicOn(void) {+ return [SGMotionSourceOrder() containsObject:kAppleMusic];+}++void SGMotionClipFor(NSURL *canvas, NSString *artist, NSString *album, SGMotionShape shape, CGFloat pixels,+ void (^done)(NSURL *file)) {+ NSArray<NSString *> *order = SGMotionSourceOrder();+ // The walk holds itself until it ends, when it lets go.+ __block void (^ask)(NSUInteger) = nil;+ void (^finish)(NSURL *) = ^(NSURL *file) {+ ask = nil;+ done(file);+ };+ void (^step)(NSUInteger) = ^(NSUInteger index) {+ if (index >= order.count) {+ finish(nil);+ return;+ }+ void (^next)(NSURL *) = ^(NSURL *file) {+ if (file) finish(file);+ else ask(index + 1);+ };+ if ([order[index] isEqualToString:kCanvas]) {+ if (canvas) SGMotionFile(canvas, next);+ else next(nil);+ } else {+ SGMotionAlbumCover(artist, album, shape, pixels, next);+ }+ };+ ask = step;+ step(0);+}++SGModRow *SGMotionSourcesRow(void) {+ SGModRow *row = SGPageRow(@"Artwork sources", ^UIViewController *{+ return SGSourcesPageMake(@"Artwork sources", @"Asked top to bottom until one has a clip for the track. Apple Music is "+ @"asked for the album by its name; it never sees your account.",+ allSources(), ^NSArray<NSString *> * { return SGMotionSourceOrder(); },+ ^(NSArray<NSString *> *keys) { [NSUserDefaults.standardUserDefaults setObject:keys forKey:SGKeyMotionSources]; });+ });+ row.value = ^NSString * {+ NSArray<NSString *> *order = SGMotionSourceOrder();+ if (!order.count) return @"Off";+ NSMutableArray<NSString *> *names = [NSMutableArray array];+ for (NSString *key in order) [names addObject:[key isEqualToString:kCanvas] ? @"Canvas" : @"Apple Music"];+ return [names componentsJoinedByString:@", "];+ };+ return SGWithSymbol(row, @"square.stack.3d.down.right");+}diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.mindex 535f75f2..29a40edc 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m@@ -12,6 +12,7 @@#import "Shared/Lyrics/Lyrics.h"#import "Shared/LocalFiles/LocalFiles.h"#import "Shared/LocalFiles/LocalLyrics.h"+#import "Settings/SGSourcesPage.h"#import "Headers/SPTPlayer.h"#import <stdatomic.h>@@ -553,3 +554,12 @@ void SGLyricsMigrateLegacyKeys(void) {SGSetEnabled(SGKeyLyricsAllTracks, SGFlag(kLegacyAllTracks, NO));SGLog(@"lyrics: carried the Musixmatch switches over as %@", [order componentsJoinedByString:@", "]);}++UIViewController *SGLyricsSourcesPage(void) {+ NSMutableArray<SGSource *> *all = [NSMutableArray array];+ for (SGLyricsProvider *provider in SGLyricsAllProviders()) {+ [all addObject:[SGSource sourceWithKey:provider.key name:provider.name detail:provider.detail]];+ }+ return SGSourcesPageMake(@"Lyrics sources", @"Asked top to bottom until one has word timing. Sources get only the track, never your account.",+ all, ^NSArray<NSString *> * { return SGLyricsOrder(); }, ^(NSArray<NSString *> *keys) { SGLyricsSetOrder(keys); });+}