Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: the Player preview loads the playing track's clip when the player has none

My-Name-Is-Jeff1bbbd66115e2
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 30fa362d..7dec7243 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -525,6 +525,9 @@ Spotify's own player screen (artwork background, glass header buttons, Disable C
header, slider and sticky header flags, the cards under the player and the lyrics preview and player
buttons to hide); in the redesign the page instead leads with a card of the player (Redesigned/Player/
PlayerSettings.m): the background chosen edge to edge, and over its foot the cover, title, artist and progress;
+for Animated while the player has no clip, the card looks the playing track's up itself while it is on screen
+(SGMotionClipFor, the player's sources, size and Low Data Mode, into the store the player reads), Fluid until it
+is in, then the clip over it, poster first (harness/player/ `preview`);
under it a segmented control of the five backgrounds (Still, Colours, Fluid, Animated, Visualiser, changing the card at once)
with a note on what the one picked does, Artwork sources and Download in Low Data Mode while Animated is chosen,
and Mini player: Apple Music style (the tab bar's minimize on scroll), Device button (the now playing bar keeps
diff --git a/harness/player/README.md b/harness/player/README.md
index 77ef2cae..5ca7ebf6 100644
--- a/harness/player/README.md
+++ b/harness/player/README.md
@@ -75,6 +75,13 @@ come late, out of order, or not at all.
in), Fluid, Colours, Still, Visualiser (the hills over Fluid held still) and Animated again, with a note for
each and the header the same height throughout. The log ends with `settings checks: n of 8 right -- PASS` or
`FAIL`.
+- `preview` opens the Player page with the background Still at launch, so the player looks up no clip, and picks
+ Animated on it. The card looks the track's clip up itself: nothing is asked for before the page or while Still
+ shows, the card is Fluid while the clip comes (`HARNESS_CANVAS_DELAY`, 2 s), then the clip is in it with its
+ poster and the field held, the player still without one, and the file in the store, where `SGMotionFile` finds
+ it without asking the server again. Fluid and then Animated again bring it back at once. The clip's address is
+ the run's own, so the store never has it from a run before. The log ends with
+ `preview checks: n of 7 right -- PASS` or `FAIL`; on the sources before the fix it read 5 of 7.
- `visualiser` plays the Visualiser background, fed by `stubs.m`'s stand-in for the audio effects' reader: a song
of its own at 120 beats a minute, handed over in buffers of 1024 at 48 kHz. It checks the hills stand on the
Fluid field held still with the reader on and the link at up to 60 fps, blur behind the lyrics with the link at
diff --git a/harness/player/main.m b/harness/player/main.m
index bb4731f7..8f448001 100644
--- a/harness/player/main.m
+++ b/harness/player/main.m
@@ -23,6 +23,10 @@
// card over Animated, then Fluid, Colours, Still and Visualiser as the segmented control picks
// them, and Animated again, the note under it changing and the rows under the header holding
// still; each step checked, the log ends with settings checks n of m right -- PASS or FAIL
+// preview the Player page's card picking Animated while the player has no clip (the background Still at
+// launch): the card looks the track's clip up itself, shows Fluid until it comes in 2 s late, then
+// the clip; the clip is in the store for the player, and asked for only while the page shows;
+// the log ends with preview checks n of m right -- PASS or FAIL
// visualiser the Visualiser background (PlayerVisualiser.m) fed a song of the harness's own (stubs.m):
// the hills moving, blurred behind the lyrics, settling and stopping on a pause, back on play,
// and the ⋯ menu's switch to Fluid and back; the log ends with visualiser checks n of m right
@@ -34,6 +38,7 @@
#import <objc/message.h>
#import "Shared/Lyrics/Lyrics.h"
#import "Redesigned/Player/Player.h"
+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"
#import "Redesigned/Kit/SGRBridges.h"
#import "Redesigned/Kit/SGRField.h"
#import "Redesigned/Lyrics/MeaningSheet.h"
@@ -61,6 +66,8 @@ static NSString *scenario(void) {
static NSMutableDictionary<NSString *, SGRHarnessPicture *> *sg_pictures;
static NSUInteger sg_served;
+// How many times the clip itself was served.
+static NSUInteger sg_canvasServed;
static void serve(NSString *imageURI, UIImage *image, NSTimeInterval delay, BOOL fails) {
if (!sg_pictures) sg_pictures = [NSMutableDictionary dictionary];
@@ -87,10 +94,15 @@ static void serve(NSString *imageURI, UIImage *image, NSTimeInterval delay, BOOL
}
- (void)startLoading {
- // The motion scenario's clip, at once.
+ // The motion scenario's clip, at once, or HARNESS_CANVAS_DELAY seconds late.
if ([self.request.URL.host isEqualToString:@"canvas.harness"]) {
- const char *file = getenv("HARNESS_CANVAS_FILE");
- [self answer:file ? [NSData dataWithContentsOfFile:@(file)] : nil];
+ const char *file = getenv("HARNESS_CANVAS_FILE"), *delay = getenv("HARNESS_CANVAS_DELAY");
+ NSData *data = file ? [NSData dataWithContentsOfFile:@(file)] : nil;
+ NSThread *thread = NSThread.currentThread;
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((delay ? atof(delay) : 0) * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
+ sg_canvasServed++;
+ [self performSelector:@selector(answer:) onThread:thread withObject:data waitUntilDone:NO];
+ });
return;
}
NSString *name = self.request.URL.lastPathComponent;
@@ -566,6 +578,7 @@ static void loadLyrics(void) {
else if ([scenario() isEqualToString:@"cover"]) [self runCoverChecks];
else if ([scenario() isEqualToString:@"immersive"]) [self runImmersiveChecks];
else if ([scenario() isEqualToString:@"settings"]) [self runSettingsChecks];
+ else if ([scenario() isEqualToString:@"preview"]) [self runPreviewChecks];
else if ([scenario() isEqualToString:@"seek"]) [self runSeekChecks];
else if ([scenario() isEqualToString:@"visualiser"]) [self runVisualiserChecks];
// Opened, closed and opened again, so a screenshot can be taken of each state and of the move itself.
@@ -1062,6 +1075,66 @@ static UIView *firstOfClass(UIView *root, NSString *name) {
});
}
+// The Player page opened with the player showing no clip, Animated picked on it: the card looks the clip up.
+- (void)runPreviewChecks {
+ __block UINavigationController *nav;
+ UIView *(^showcase)(void) = ^{
+ return firstOfClass(((UITableViewController *)nav.topViewController).tableView.tableHeaderView, @"SGRPlayerShowcase");
+ };
+ void (^pick)(NSUInteger) = ^(NSUInteger index) {
+ UISegmentedControl *segments = (UISegmentedControl *)firstOfClass(showcase().superview, @"UISegmentedControl");
+ segments.selectedSegmentIndex = (NSInteger)index;
+ [segments sendActionsForControlEvents:UIControlEventValueChanged];
+ };
+ NSString *(^card)(void) = ^{
+ UIView *view = showcase();
+ SGRArtworkField *field = (SGRArtworkField *)firstOfClass(view, @"SGRArtworkField");
+ UIView *motion = firstOfClass(view, @"SGRPlayerMotionView");
+ CALayer *still = [motion valueForKey:@"_still"];
+ return [NSString stringWithFormat:@"card: clip %@ (poster %@), field fluid %d held %d; the player's clip %@; the clip served %lu times",
+ motion ? @"in" : @"out", still.contents ? @"drawn" : @"none", field.fluid, field.motionHeld, SGRPlayerMotionShowing() ? @"in" : @"none",
+ (unsigned long)sg_canvasServed];
+ };
+ BOOL (^clipIn)(void) = ^{ return (BOOL)(firstOfClass(showcase(), @"SGRPlayerMotionView") != nil); };
+ after(1, ^{
+ [self expect:sg_canvasServed == 0 && !SGRPlayerMotionShowing() step:@"before the page, nothing asked for"
+ detail:[NSString stringWithFormat:@"the clip served %lu times, the player's clip %@", (unsigned long)sg_canvasServed, SGRPlayerMotionShowing() ? @"in" : @"none"]];
+ nav = [[UINavigationController alloc] initWithRootViewController:SGRPlayerSettingsPage(@[])];
+ nav.modalPresentationStyle = UIModalPresentationFullScreen;
+ [self.window.rootViewController presentViewController:nav animated:NO completion:nil];
+ });
+ after(2, ^{
+ [self expect:!clipIn() && sg_canvasServed == 0 step:@"Still on the page, nothing asked for" detail:card()];
+ pick(3);
+ });
+ after(2.5, ^{
+ SGRArtworkField *field = (SGRArtworkField *)firstOfClass(showcase(), @"SGRArtworkField");
+ [self expect:!clipIn() && field.fluid step:@"Animated picked, Fluid while the clip comes" detail:card()];
+ });
+ after(6, ^{
+ SGRArtworkField *field = (SGRArtworkField *)firstOfClass(showcase(), @"SGRArtworkField");
+ CALayer *still = [firstOfClass(showcase(), @"SGRPlayerMotionView") valueForKey:@"_still"];
+ [self expect:clipIn() && still.contents && field.motionHeld && sg_canvasServed == 1 && !SGRPlayerMotionShowing()
+ step:@"the clip in the card, the player left alone" detail:card()];
+ NSLog(@"[harness] preview: screenshot the card now");
+ // The player's walk asks the store the same way: it finds the file without asking the server again.
+ SGMotionFile([NSURL URLWithString:@(getenv("HARNESS_CANVAS"))], ^(NSURL *file) {
+ [self expect:file && sg_canvasServed == 1 step:@"the clip in the store for the player"
+ detail:[NSString stringWithFormat:@"%@, served %lu times", file.lastPathComponent ?: @"no file", (unsigned long)sg_canvasServed]];
+ });
+ });
+ after(8, ^{ pick(2); });
+ after(8.5, ^{
+ [self expect:!clipIn() step:@"Fluid picked, the clip out" detail:card()];
+ pick(3);
+ [self expect:clipIn() && sg_canvasServed == 1 step:@"Animated again, the clip at once" detail:card()];
+ });
+ after(9.5, ^{
+ NSLog(@"[harness] preview checks: %lu of %lu right -- %@", (unsigned long)(self->_checks - self->_failures), (unsigned long)self->_checks,
+ self->_failures ? @"FAIL" : @"PASS");
+ });
+}
+
- (NSArray<UILabel *> *)labelsIn:(UIView *)view {
NSMutableArray<UILabel *> *labels = [NSMutableArray array];
for (UIView *sub in view.subviews) {
@@ -1509,6 +1582,13 @@ __attribute__((constructor(101))) static void sgr_harnessDefaults(void) {
[NSUserDefaults.standardUserDefaults setBool:YES forKey:@"spotifyglass.redesign"];
// Animated artwork, its clip served by the picture server to the shared session too.
if ([scenario() isEqualToString:@"visualiser"]) [NSUserDefaults.standardUserDefaults setInteger:4 forKey:@"spotifyglass.redesign.player.background"];
+ // Still at launch, so the player looks up no clip; an address of this run's own, so the store has none of it yet.
+ if ([scenario() isEqualToString:@"preview"]) {
+ [NSUserDefaults.standardUserDefaults setInteger:0 forKey:@"spotifyglass.redesign.player.background"];
+ setenv("HARNESS_CANVAS", [NSString stringWithFormat:@"https://canvas.harness/preview-%d.mp4", getpid()].UTF8String, 1);
+ setenv("HARNESS_CANVAS_DELAY", "2", 1);
+ [NSURLProtocol registerClass:SGRHarnessPictureServer.class];
+ }
if ([scenario() isEqualToString:@"motion"] || [scenario() isEqualToString:@"settings"]) {
[NSUserDefaults.standardUserDefaults setInteger:3 forKey:@"spotifyglass.redesign.player.background"];
setenv("HARNESS_CANVAS", "https://canvas.harness/clip.mp4", 1);
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index e3d73a10..f089a509 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -104,8 +104,12 @@ void SGRPlayerMotionFieldLaidOut(void);
// flown cover fade where they are rather than flying to or from it.
BOOL SGRPlayerMotionShowing(void);
// A view of its own playing that clip, drawn as the player draws it (its foot, the blur under the controls),
-// for the Player page's showcase; nil while no clip plays. It plays only in a window, like the player's.
-UIView *SGRPlayerMotionPreview(void);
+// for the Player page's showcase. It plays only in a window, like the player's. While the player has no clip
+// it is the playing track's, which the page looks up itself, by the player's sources and Low Data Mode, into
+// the store the player reads too: nil until it is in, and with `arrived` given the lookup starts, and
+// `arrived` runs once on the main queue when a call would return it (never when nothing is found, or the
+// track changed). Without `arrived` it only answers with a clip already in.
+UIView *SGRPlayerMotionPreview(void (^arrived)(void));
#pragma mark - the Visualiser (PlayerVisualiser.m)
diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.x
index af4c6030..51f0c62a 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x
+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x
@@ -342,14 +342,63 @@ BOOL SGRPlayerMotionShowing(void) {
return sg_motion != nil;
}
-UIView *SGRPlayerMotionPreview(void) {
- if (!sg_motionFile) return nil;
+static UIView *previewOf(NSURL *file, UIImage *poster) {
SGRPlayerMotionView *preview = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];
- [preview playFile:sg_motionFile poster:sg_motionPoster];
+ [preview playFile:file poster:poster];
[preview appear:NO then:^{}];
return preview;
}
+// The playing track's clip the Player page looked up itself while the player had none, and its poster; the
+// file is nil while the walk is out or after it found nothing. The walk is the player's (SGMotionClipFor, at
+// the size SGMotionFollower asks for), so its file lands in the store, where the player's own walk finds it.
+static NSString *sg_previewTrack;
+static NSURL *sg_previewFile;
+static UIImage *sg_previewPoster;
+static void (^sg_previewArrived)(void);
+
+UIView *SGRPlayerMotionPreview(void (^arrived)(void)) {
+ if (sg_motionFile) return previewOf(sg_motionFile, sg_motionPoster);
+ SPTPlayerState *state = SGPlayerState();
+ NSString *track = SGURIString(state.track.URI);
+ if (!track) return nil;
+ BOOL asked = [track isEqualToString:sg_previewTrack];
+ if (asked && sg_previewFile) return previewOf(sg_previewFile, sg_previewPoster);
+ if (!arrived) return nil;
+ // The newest page's to be told; a walk already out for this track is waited on rather than asked again.
+ sg_previewArrived = [arrived copy];
+ if (asked) return nil;
+ sg_previewTrack = track;
+ sg_previewFile = nil;
+ sg_previewPoster = nil;
+ NSDictionary *metadata = [state.track.metadata isKindOfClass:NSDictionary.class] ? state.track.metadata : nil;
+ SGLog(@"redesign player: the Player page looks up the clip of %@", track);
+ SGMotionClipFor(track, SGMotionCanvasIn(metadata), state.track.artistName, metadata[@"album_title"], SGMotionTall, SGMotionPixels(),
+ ^(NSURL *file, NSString *source) {
+ if (![track isEqualToString:sg_previewTrack]) return;
+ // Nothing found is not kept: the page asks again the next time it shows Animated.
+ if (!file) {
+ sg_previewTrack = nil;
+ sg_previewArrived = nil;
+ return;
+ }
+ SGMotionPoster(file, ^(UIImage *poster) {
+ if (![track isEqualToString:sg_previewTrack]) return;
+ void (^done)(void) = sg_previewArrived;
+ sg_previewArrived = nil;
+ if (!poster || poster.size.width <= 0) {
+ sg_previewTrack = nil;
+ return;
+ }
+ sg_previewFile = file;
+ sg_previewPoster = poster;
+ SGLog(@"redesign player: the Player page's clip from %@, %@", source, file.lastPathComponent);
+ if (done) done();
+ });
+ });
+ return nil;
+}
+
static SGMotionFollower *sg_follower;
// Spotify's units that are showing its music video, held weakly: one that goes without saying so lets go.
diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.m
index d31f66b9..6bcab36b 100644
--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m
+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m
@@ -5,8 +5,10 @@
// The progress is where the track was when the page appeared.
//
// The background is the player's own: a field of the same kind (Still, Colours, Fluid), for Animated
-// the clip the player is playing (SGRPlayerMotionPreview) in place of the field, or Fluid while there is
-// none, as in the player, and for Visualiser the hills over Fluid held still (SGRPlayerVisualiserPreview),
+// the clip the player is playing (SGRPlayerMotionPreview) in place of the field, or, while the player has
+// none, the playing track's clip looked up for the card while it is on screen, Fluid until it comes in and
+// for a track with none, as in the player; the clip crosses over the field as it arrives, its poster first
+// while its video decodes. And for Visualiser the hills over Fluid held still (SGRPlayerVisualiserPreview),
// moving with the song. It moves under the field's own conditions (in a window, Spotify in front, Reduce
// Motion and Low Power Mode off). Under the card a segmented control picks the background, all five of
// them: the names are one word each, each segment as wide as its name, so they fit side by side at an iPhone's
@@ -142,15 +144,27 @@ static NSArray<NSString *> *backgroundNotes(void) {
[self setNeedsLayout];
}
-// The background chosen, read again; a new one crosses over when animated. The clip is the one playing when
-// this is called: a track changed while the page shows keeps the last one until the page appears again.
+// The card on screen with Animated and no clip in it: one is looked up, and shown once it is in.
+- (void)didMoveToWindow {
+ [super didMoveToWindow];
+ if (self.window && !_motion && SGRPlayerBackground() == SGRPlayerBackgroundAnimated) [self reloadBackgroundAnimated:NO];
+}
+
+// The background chosen, read again; a new one crosses over when animated. The clip is the one playing, or
+// looked up, when this is called: a track changed while the page shows keeps the last one until the page
+// appears again. A clip is looked up only while the card is in a window.
- (void)reloadBackgroundAnimated:(BOOL)animated {
SGRPlayerBackgroundKind kind = SGRPlayerBackground();
+ __weak SGRPlayerShowcase *weakSelf = self;
+ void (^arrived)(void) = !self.window ? nil : ^{
+ SGRPlayerShowcase *showcase = weakSelf;
+ if (showcase.window && !showcase->_motion && SGRPlayerBackground() == SGRPlayerBackgroundAnimated) [showcase reloadBackgroundAnimated:YES];
+ };
void (^apply)(void) = ^{
self->_field.flows = kind == SGRPlayerBackgroundColours;
self->_field.fluid = kind >= SGRPlayerBackgroundFluid;
[self->_motion removeFromSuperview];
- self->_motion = kind == SGRPlayerBackgroundAnimated ? SGRPlayerMotionPreview() : nil;
+ self->_motion = kind == SGRPlayerBackgroundAnimated ? SGRPlayerMotionPreview(arrived) : nil;
if (self->_motion) [self insertSubview:self->_motion aboveSubview:self->_field];
[self->_visualiser removeFromSuperview];
self->_visualiser = kind == SGRPlayerBackgroundVisualiser ? SGRPlayerVisualiserPreview() : nil;