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 blends into the field and switches from the more menu
My-Name-Is-Jeffd44e3fda83c4
diff --git a/harness/menu/README.md b/harness/menu/README.mdindex db85742a..ab639a50 100644--- a/harness/menu/README.md+++ b/harness/menu/README.md@@ -6,7 +6,7 @@ pitch the way it would on the phone. Speed and pitch themselves are stubs that lTHEOS=$HOME/theos ./build.shxcrun simctl install <udid> build/MenuHarness.app- xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open]+ xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated]It has a scene delegate, so it runs on the iOS 27 simulator as well as 26. The mod's own lines(`SGLog`) go to the unified log: `xcrun simctl spawn <udid> log stream --predicate 'eventMessage CONTAINS "[spotifyglass]"'`.@@ -26,6 +26,9 @@ the Pitch and the row read "−3 st".- `stuck` never gives it rows; the mod logs `no rows of Spotify's N s after the menu appeared`.- `open` opens the block on a first menu, closes that menu and brings up a second one with the blockalready open, as it stays for the session.+- `animated` offers the redesign's Animated artwork switch (stubbed): it flips the switch with the block+ closed and again with it open, and reports where its row sits each time, `PASS` when the row is inside+ the block and the switch shows what was set.For the first second the block is on screen, every frame is checked for anything it draws in thesystem tint (`tint check: 0 of the block's first N frames ...`).diff --git a/harness/menu/main.m b/harness/menu/main.mindex 47001370..9f979a3b 100644--- a/harness/menu/main.m+++ b/harness/menu/main.m@@ -2,7 +2,7 @@// so SpeedPitchMenu.x's hook adds Speed and pitch the way it would on the phone.//// THEOS=$HOME/theos ./build.sh && xcrun simctl install <udid> build/MenuHarness.app-// xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open]+// xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated]//// The plain run opens the menu at 1 s, opens the block at 3 s, moves the sliders at 5 s, checks what the// block says at 6 s (PASS or FAIL lines), closes the block at 7 s and checks its row at 8 s. `loading` builds the sheet the way Spotify's is (the ivars of ContextMenuViewController in@@ -11,6 +11,8 @@// once its item factories have answered; `stuck` never hands them over. `open` opens the block on a first// menu, closes it, and brings up a second one with the block open, as it stays for the session. Every frame of the first second the block is on screen// is checked for a colour of the system tint on anything it draws, and what the sheet shows is reported.+// `animated` offers the redesign's Animated artwork switch: it is flipped, then the block opened and+// closed, and where the switch's row sits is reported each time.#import <UIKit/UIKit.h>#pragma mark - what SpeedPitchMenu.x calls@@ -29,6 +31,10 @@ BOOL SGPlayerPitchAvailable(void) { return YES; }static BOOL sg_follows = YES;BOOL SGPlayerPitchFollowsSpeed(void) { return sg_follows; }void SGSetPlayerPitchFollowsSpeed(BOOL follows) { sg_follows = follows; NSLog(@"[harness] pitch follows speed %d", follows); }+static BOOL sg_animated;+BOOL SGPlayerMenuOffersAnimatedArtwork(void) { return [NSProcessInfo.processInfo.arguments containsObject:@"animated"]; }+BOOL SGPlayerMenuAnimatedArtwork(void) { return sg_animated; }+void SGPlayerMenuSetAnimatedArtwork(BOOL on) { sg_animated = on; NSLog(@"[harness] animated artwork %d", on); }// The audio effects' settings, kept in a dictionary: the reverb slider reads and writes them.static NSMutableDictionary *sg_dsp;BOOL SGDSPSwitch(NSString *key) { return [sg_dsp[key] boolValue]; }@@ -323,6 +329,33 @@ static void tapRow(UIViewController *menu) {[[CADisplayLink displayLinkWithTarget:watch selector:@selector(tick:)] addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];[player presentViewController:navigation animated:YES completion:nil];};+ if (argument(@"animated")) {+ void (^where)(NSString *) = ^(NSString *when) {+ UIView *block = findBlock(menu.view);+ UISwitch *toggle = nil;+ for (UIView *row in block.subviews) {+ for (UIView *view in row.subviews) {+ if ([view isKindOfClass:UISwitch.class] && [view.accessibilityLabel isEqualToString:@"Animated artwork"]) toggle = (UISwitch *)view;+ }+ }+ CGRect row = [toggle.superview convertRect:toggle.superview.bounds toView:block];+ BOOL inside = CGRectContainsRect(block.bounds, row) && row.size.height > 0;+ NSLog(@"[harness] %@: block %.0f tall, the Animated artwork row at %.0f (%@), switch %@ -- %@", when,+ block.bounds.size.height, row.origin.y, inside ? @"inside the block" : @"cut off", toggle.on ? @"on" : @"off",+ toggle && inside && toggle.on == sg_animated ? @"PASS" : @"FAIL");+ if (toggle && ![when isEqualToString:@"closed"]) {+ toggle.on = !toggle.on;+ [toggle sendActionsForControlEvents:UIControlEventValueChanged];+ }+ };+ after(1, present);+ after(2.5, ^{ where(@"shown"); });+ after(3, ^{ tapRow(menu); });+ after(4.5, ^{ where(@"opened"); });+ after(5, ^{ tapRow(menu); });+ after(6.5, ^{ where(@"closed"); });+ return;+ }if (argument(@"open")) {// The block keeps whether it was open for the session: open it on a first menu, close that menu,// and watch a second one come up with the block already open.diff --git a/harness/player/README.md b/harness/player/README.mdindex 223f8e13..d3c82e8c 100644--- a/harness/player/README.md+++ b/harness/player/README.md@@ -38,6 +38,12 @@ come late, out of order, or not at all.that brings the controls back, with `ok` or `WRONG`. At 6 s it logs the sheet's frame: a card insidethe safe area with a grabber, where the sheet before it covered the whole screen.+- `motion` is Animated artwork. The clip, `HARNESS_CANVAS_FILE` (any mp4, `harness/fluid-clip` writes one),+ is served as the track's Canvas before the player's background has laid out; then the background lays+ out, the lyrics open and close, the background is built again, and the ⋯ menu's switch goes off, on, and+ off with the player out of its window. Each step is checked (the clip on the field, the cover hidden, the+ foot and the blur, the thumbnail) and the log ends with `motion checks: n of 9 right -- PASS` or `FAIL`.+`HARNESS_VOLUME=0` leaves out the volume row that the phone has and the tree does not.A screen recording is the way to see a move:diff --git a/harness/player/main.m b/harness/player/main.mindex fdb9db92..a6572949 100644--- a/harness/player/main.m+++ b/harness/player/main.m@@ -11,6 +11,9 @@// checked by colour at the end of each step; the log says PASS or FAIL// landscape the landscape lyrics at 3 s, a line's meanings over them, a pause and a resume; each// step logs whether the controls are up and what a touch on the lines lands on+// motion Animated artwork: a clip (HARNESS_CANVAS_FILE, an mp4) that comes in before the player has+// laid out, then the field, the lyrics, a field built again, the menu's switch and the player+// closed, each step checked; the log ends with motion checks n of m right -- PASS or FAIL// HARNESS_VOLUME=0 leaves out the volume row the phone has (trees/clean/player/01.txt has none).#import <UIKit/UIKit.h>#import <objc/runtime.h>@@ -60,7 +63,7 @@ static void serve(NSString *imageURI, UIImage *image, NSTimeInterval delay, BOOL}+ (BOOL)canInitWithRequest:(NSURLRequest *)request {- return [request.URL.host isEqualToString:@"i.scdn.co"];+ return [request.URL.host isEqualToString:@"i.scdn.co"] || [request.URL.host isEqualToString:@"canvas.harness"];}+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {@@ -68,6 +71,12 @@ static void serve(NSString *imageURI, UIImage *image, NSTimeInterval delay, BOOL}- (void)startLoading {+ // The motion scenario's clip, at once.+ if ([self.request.URL.host isEqualToString:@"canvas.harness"]) {+ const char *file = getenv("HARNESS_CANVAS_FILE");+ [self answer:file ? [NSData dataWithContentsOfFile:@(file)] : nil];+ return;+ }NSString *name = self.request.URL.lastPathComponent;SGRHarnessPicture *picture = name.length >= 24 ? sg_pictures[[name substringFromIndex:name.length - 24]] : nil;NSThread *thread = NSThread.currentThread;@@ -310,6 +319,8 @@ static void loadLyrics(void) {UIViewController *_bar;UICollectionView *_covers;UIScrollView *_list;+ UIView *_plane, *_host;+ UIViewController *_background;NSUInteger _failures, _checks;}@@ -467,6 +478,14 @@ static void loadLyrics(void) {player.view = host;_units = @[info, duration, floating, playback, footer, scrollUnit, background, player];_covers = covers;+ _plane = plane;+ _host = host;+ _background = background;+ // The player has not been opened yet: its background plane is laid out only when it is.+ if ([scenario() isEqualToString:@"motion"]) {+ [plane removeFromSuperview];+ _units = @[info, duration, floating, playback, footer, scrollUnit, player];+ }[self start];[self layOut];// Spotify lays its units out again as a track's elements arrive, which is what the redesign's@@ -490,6 +509,7 @@ static void loadLyrics(void) {else if ([scenario() isEqualToString:@"look"]) [self runLook];else if ([scenario() isEqualToString:@"scroll"]) [self runScrollChecks];else if ([scenario() isEqualToString:@"landscape"]) [self runLandscape];+ else if ([scenario() isEqualToString:@"motion"]) [self runMotionChecks];// Opened, closed and opened again, so a screenshot can be taken of each state and of the move itself.else for (NSNumber *at in @[@2, @6, @10]) {dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(at.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{@@ -652,6 +672,103 @@ static void logLandscape(NSString *step, NSString *want) {}// Up must be taken back to the top, down (the dismissal's pull) left where it went.+#pragma mark - Animated artwork++BOOL SGPlayerMenuAnimatedArtwork(void);+void SGPlayerMenuSetAnimatedArtwork(BOOL on);++static UIView *motionView(void) {+ for (UIView *view in SGRPlayerField().subviews) {+ if ([NSStringFromClass(view.class) isEqualToString:@"SGRPlayerMotionView"]) return view;+ }+ return nil;+}++- (void)expect:(BOOL)ok step:(NSString *)step detail:(NSString *)detail {+ _checks++;+ if (!ok) _failures++;+ NSLog(@"[harness] motion check %@: %@ -- %@", step, detail, ok ? @"ok" : @"WRONG");+}++- (void)runMotionChecks {+ // The clip comes in before the player has laid out, as for the track restored at launch.+ after(3, ^{+ [self expect:SGRPlayerMotionShowing() && !SGRPlayerField() step:@"before the player opened"+ detail:[NSString stringWithFormat:@"clip %@, field %@", SGRPlayerMotionShowing() ? @"in" : @"missing", SGRPlayerField() ? @"made" : @"not made"]];+ });+ after(4, ^{+ [self->_list insertSubview:self->_plane atIndex:0];+ self->_units = [self->_units arrayByAddingObject:self->_background];+ [self layOut];+ });+ after(5, ^{+ UIView *motion = motionView();+ CALayer *foot = [motion valueForKey:@"_foot"], *clip = [motion valueForKey:@"_clip"];+ UIVisualEffectView *seam = [motion valueForKey:@"_seamBlur"], *lyrics = [motion valueForKey:@"_lyricsBlur"];+ [self expect:motion != nil && self->_covers.layer.mask != nil step:@"the player opened"+ detail:[NSString stringWithFormat:@"clip %@ the field, cover %@", motion ? @"on" : @"not on", self->_covers.layer.mask ? @"hidden" : @"shown"]];+ CGFloat seamAt = round(clip.frame.size.height * 0.9);+ BOOL footDown = foot && fabs(foot.frame.origin.y - seamAt) < 1 && CGRectGetMaxY(foot.frame) >= self.window.bounds.size.height+ && foot.contents && foot.contentsRect.size.height < 0.05 && CGRectGetMaxY(foot.contentsRect) > 0.999;+ [self expect:footDown step:@"the foot"+ detail:[NSString stringWithFormat:@"clip %@, foot %@ from rows %@", NSStringFromCGRect(clip.frame), NSStringFromCGRect(foot.frame), NSStringFromCGRect(foot.contentsRect)]];+ [self expect:seam.effect && !lyrics.effect step:@"the blur from the seam"+ detail:[NSString stringWithFormat:@"seam blur %@, from %@ of the height, lyrics blur %@", seam.effect ? @"on" : @"off",+ [[seam.maskView.layer.sublayers.firstObject valueForKey:@"locations"] componentsJoinedByString:@" to "], lyrics.effect ? @"on" : @"off"]];+ NSLog(@"[harness] motion: screenshot the clip now");+ });+ after(7, ^{ SGRPlayerToggleLyrics(); });+ after(8.5, ^{+ UIVisualEffectView *lyrics = [motionView() valueForKey:@"_lyricsBlur"];+ UIView *thumb = nil;+ for (UIView *view in self->_host.subviews) {+ if ([NSStringFromClass(view.class) isEqualToString:@"SGRPlayerLyricsOverlay"]) thumb = [view valueForKey:@"thumb"];+ }+ BOOL away = thumb && !CGAffineTransformIsIdentity(thumb.transform) && thumb.alpha > 0.99;+ [self expect:SGRPlayerLyricsOpen() && lyrics.effect && away step:@"the lyrics"+ detail:[NSString stringWithFormat:@"lyrics %@, clip blurred %@, thumbnail %@ at alpha %.2f", SGRPlayerLyricsOpen() ? @"up" : @"down",+ lyrics.effect ? @"yes" : @"no", thumb && !CGAffineTransformIsIdentity(thumb.transform) ? @"in its corner" : @"at the cover", thumb.alpha]];+ NSLog(@"[harness] motion: screenshot the lyrics now");+ });+ after(10, ^{ SGRPlayerToggleLyrics(); });+ // Spotify builds the player's background again: the clip goes onto the new field.+ after(11.5, ^{+ UIView *old = SGRPlayerField();+ UIView *plane = [[UIView alloc] initWithFrame:self->_plane.frame];+ UIViewController *background = [_TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController new];+ background.view = plane;+ [self->_plane removeFromSuperview];+ [self->_list insertSubview:plane atIndex:0];+ self->_plane = plane;+ NSMutableArray *units = [self->_units mutableCopy];+ [units replaceObjectAtIndex:[units indexOfObject:self->_background] withObject:background];+ self->_units = units;+ self->_background = background;+ [self layOut];+ [self expect:SGRPlayerField() != old && motionView() != nil step:@"a field built again" detail:motionView() ? @"the clip moved onto it" : @"the clip left behind"];+ });+ after(12.5, ^{+ SGPlayerMenuSetAnimatedArtwork(NO);+ [self expect:!SGRPlayerMotionShowing() && !motionView() && !self->_covers.layer.mask && !SGPlayerMenuAnimatedArtwork()+ step:@"switched off from the menu" detail:[NSString stringWithFormat:@"clip %@, cover %@", motionView() ? @"still there" : @"gone",+ self->_covers.layer.mask ? @"hidden" : @"back"]];+ SGPlayerMenuSetAnimatedArtwork(YES);+ });+ after(14, ^{+ [self expect:motionView() && self->_covers.layer.mask step:@"switched on again"+ detail:[NSString stringWithFormat:@"clip %@, cover %@", motionView() ? @"back" : @"missing", self->_covers.layer.mask ? @"hidden" : @"shown"]];+ // The player closed: the cover list cannot be found, and switching off must still bring its cover back.+ [self->_host removeFromSuperview];+ SGPlayerMenuSetAnimatedArtwork(NO);+ [self expect:!self->_covers.layer.mask step:@"switched off with the player closed" detail:self->_covers.layer.mask ? @"cover still hidden" : @"cover back"];+ [self->_list addSubview:self->_host];+ });+ after(15, ^{+ NSLog(@"[harness] motion checks: %lu of %lu right -- %@", (unsigned long)(self->_checks - self->_failures), (unsigned long)self->_checks,+ self->_failures ? @"FAIL" : @"PASS");+ });+}+- (void)runScrollChecks {after(2, ^{UIScrollView *list = self->_list;@@ -708,6 +825,12 @@ static void logLandscape(NSString *step, NSString *want) {// Before every %ctor, so the redesign's gate reads on, and every session gets the picture server.__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:@"motion"]) {+ [NSUserDefaults.standardUserDefaults setInteger:3 forKey:@"spotifyglass.redesign.player.background"];+ setenv("HARNESS_CANVAS", "https://canvas.harness/clip.mp4", 1);+ [NSURLProtocol registerClass:SGRHarnessPictureServer.class];+ }Method original = class_getClassMethod(NSURLSessionConfiguration.class, @selector(defaultSessionConfiguration));Method harness = class_getClassMethod(NSURLSessionConfiguration.class, @selector(sgr_harnessDefault));method_exchangeImplementations(original, harness);diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.mindex 1d9add6d..c8e1dd18 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m@@ -12,7 +12,7 @@ UIViewController *SGRNowPlayingBarSettingsPage(void) {SGHideRow(@"Hide the device button", nil, SGRHideBarConnect),]),SGSection(nil, @[- SGChoiceRow(@"Background", @"Animated plays the Canvas or Apple Music's animated cover, over Fluid",+ SGChoiceRow(@"Background", @"Animated plays the Canvas or Apple Music's animated cover, over Fluid; the player's ⋯ menu switches between the two",SGRKeyPlayerBackground, SGRPlayerBackgroundNames(), SGRPlayerBackground()),SGOptionRow(@"Download in Low Data Mode", @"Animated artwork, up to about 7 MB a song", SGKeyMotionLowData),]),diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex e2584773..88eb9d04 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -15,6 +15,7 @@// PlayerLyrics.x the lyrics in the player: the cover as a thumbnail, the title up beside it// PlayerGestures.x the gestures' hookup// PlayerMorph.x the open and close grown out of the now playing bar's card, the cover flown+// PlayerMotion.x Animated artwork: the Canvas or Apple Music's animated cover behind the player//// Speed and pitch, once the redesign's own, are Shared/Player/SpeedPitch.h's; PlayerHeader.x still hands// the more button over, so a menu opened from it is taken for the player's.@@ -33,7 +34,8 @@ typedef NS_ENUM(NSInteger, SGRPlayerBackgroundKind) {SGRPlayerBackgroundStill, // the artwork blurred and held stillSGRPlayerBackgroundColours, // the artwork's colours drifting (SGRFlow.h)SGRPlayerBackgroundFluid, // the artwork itself blurred and turning (SGRFluid.h)- SGRPlayerBackgroundAnimated, // the track's Canvas or Apple Music's animated cover, over Fluid (PlayerMotion.x)+ SGRPlayerBackgroundAnimated, // the track's Canvas or Apple Music's animated cover, over Fluid (PlayerMotion.x);+ // the player's ⋯ menu switches between this and Fluid};SGRPlayerBackgroundKind SGRPlayerBackground(void);// The names of the choices, in order.@@ -78,6 +80,11 @@ void SGRPlayerShowLandscape(BOOL show);// The animated artwork follows the lyrics: blurred behind them (PlayerMotion.x).void SGRPlayerMotionLyricsChanged(void);+// The field was laid out (PlayerField.x): the clip goes onto it, and the cover is hidden or shown again.+void SGRPlayerMotionFieldLaidOut(void);+// A clip is playing in place of the cover, which is then hidden: the lyrics' thumbnail and the open's+// flown cover fade where they are rather than flying to or from it.+BOOL SGRPlayerMotionShowing(void);// Alpha 0, no touches, hidden from accessibility, set again on every call: for Spotify's Swift views,// which SGRSuppress cannot keep (PlayerControls.x).diff --git a/tweak/Sources/Redesigned/Player/PlayerField.x b/tweak/Sources/Redesigned/Player/PlayerField.xindex 9201ca9d..9236c099 100644--- a/tweak/Sources/Redesigned/Player/PlayerField.x+++ b/tweak/Sources/Redesigned/Player/PlayerField.x@@ -89,6 +89,7 @@ static SGRArtworkField *fieldIn(UIView *plane) {if (field.superview != plane) [plane addSubview:field];else if (plane.subviews.lastObject != field) [plane bringSubviewToFront:field];if (!CGRectEqualToRect(field.frame, plane.bounds)) field.frame = plane.bounds;+ SGRPlayerMotionFieldLaidOut();}- (void)backgroundViewModel:(id)model didChangeColor:(id)color playerState:(id)state {diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex 4e838f0a..68444b62 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -460,9 +460,13 @@ static void setOpen(BOOL open, BOOL animated) {SGRPlayerLyricsOverlay *overlay = overlayIn(host);place(overlay, host, l);CGAffineTransform away = thumbTransform(l);+ // Over an animated artwork the cover is hidden, so the thumbnail fades where it sits rather than flying+ // to or from an empty slot.+ BOOL fades = SGRPlayerMotionShowing();// The state it starts from, so the animation has both ends of every value and nothing jumps into it.- overlay.thumb.transform = open ? CGAffineTransformIdentity : away;- overlay.cover.layer.cornerRadius = thumbRadius(l, !open);+ overlay.thumb.transform = open && !fades ? CGAffineTransformIdentity : away;+ overlay.thumb.alpha = open && fades ? 0 : 1;+ overlay.cover.layer.cornerRadius = thumbRadius(l, fades || !open);if (open) {overlay.cover.image = SGRNowPlayingArtwork(NULL, NULL);overlay.stage.alpha = 0;@@ -478,8 +482,9 @@ static void setOpen(BOOL open, BOOL animated) {}void (^move)(void) = ^{- overlay.thumb.transform = open ? away : CGAffineTransformIdentity;- overlay.cover.layer.cornerRadius = thumbRadius(l, open);+ overlay.thumb.transform = open || fades ? away : CGAffineTransformIdentity;+ overlay.thumb.alpha = !open && fades ? 0 : 1;+ overlay.cover.layer.cornerRadius = thumbRadius(l, open || fades);placeTitleRow(l);sg_floating.viewIfLoaded.alpha = open ? 0 : 1;};diff --git a/tweak/Sources/Redesigned/Player/PlayerMorph.x b/tweak/Sources/Redesigned/Player/PlayerMorph.xindex 2838d4cf..d06959e1 100644--- a/tweak/Sources/Redesigned/Player/PlayerMorph.x+++ b/tweak/Sources/Redesigned/Player/PlayerMorph.x@@ -192,6 +192,9 @@ static CGFloat screenRadius(void) {to = CGRectOffset(to, -sheet.origin.x, -sheet.origin.y);self->_cover.frame = CGRectOffset(lerpRect(from, to, t), sheet.origin.x, sheet.origin.y);self->_cover.layer.cornerRadius = lerp(from.size.width / 2, SGRRadiusArtwork * scale, t);+ // Over an animated artwork the player's cover is hidden: the flown one fades out on the+ // way there instead of landing on an empty slot.+ self->_cover.alpha = SGRPlayerMotionShowing() ? 1 - ramp(0.6, 1, t) : 1;}}}];diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xindex 9865c7f7..8382c7a4 100644--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -1,124 +1,221 @@// Player redesign: Animated artwork, the track's Canvas or Apple Music's animated cover behind the player,// the way the Music app draws it. The clip runs edge to edge from the top, sharp to near its foot, where-// it dissolves into the Fluid field under it (PlayerField.x keeps the field Fluid for this choice). The-// player's square cover goes while a clip plays, so a track without one keeps its cover. Behind the-// lyrics the clip is blurred.+// it dissolves into its own last rows drawn on down to the bottom of the field, so it ends in its own+// colour rather than on the Fluid field. A blur comes in from the seam (from above the controls for a+// Canvas as tall as the screen) and lies under the controls; behind the lyrics the whole clip is blurred.+// The player's square cover goes while a clip plays, so a track without one keeps its cover over Fluid+// (PlayerField.x keeps the field Fluid for this choice). The player's ⋯ menu switches between Animated+// and Fluid at once (Shared/Player/SpeedPitch.h).//// The clip is a subview of the field, not of the background plane: the plane's layout brings the field to-// the front on every pass, and a sibling would end up under it.+// the front on every pass, and a sibling would end up under it. Each of the field's layout passes attaches+// it (SGRPlayerMotionFieldLaidOut), so a clip that came in before the player first opened, or a field+// Spotify built again, gets it.+//+// The clip holds still when the moving field does (SGRField.m): out of a window, with the app not in front,+// while the player opens or closes, under Reduce Motion and in Low Power Mode.#import <AVFoundation/AVFoundation.h>#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"#import "Shared/AnimatedArtwork/AnimatedArtwork.h"#import "Shared/Player/PlayerState.h"+#import "Shared/Player/SpeedPitch.h"#import "Player.h"-// Where the clip starts dissolving, as a share of its height.-static const CGFloat kFootFrom = 0.78;+// Where the clip starts dissolving into its foot, as a share of its height.+static const CGFloat kFootFrom = 0.9;+// The share of the poster's height, at its bottom, drawn on down as the foot (one pixel row at least).+static const CGFloat kFootRows = 0.01;// A clip this much taller than wide is a Canvas, drawn to the window's full height.static const CGFloat kCanvasAspect = 1.5;--static void setCoverShown(BOOL shown);+// The blur starts at the seam, or this share of the screen down where that is higher, so it is under the+// controls whatever the clip's shape; it is whole kBlurRamp points below its start.+static const CGFloat kBlurByControls = 0.6, kBlurRamp = 96;@interface SGRPlayerMotionView : UIView-- (void)playFile:(NSURL *)file aspect:(CGFloat)aspect;+@property (nonatomic) CGFloat screenHeight;+- (void)playFile:(NSURL *)file poster:(UIImage *)poster;+- (void)appear:(BOOL)animated;- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated;@end@implementation SGRPlayerMotionView {AVQueuePlayer *_player;AVPlayerLooper *_looper;- CAGradientLayer *_foot;- UIVisualEffectView *_blur;+ UIView *_picture; // the clip over its foot, faded in as one+ AVPlayerLayer *_clip;+ CAGradientLayer *_clipMask, *_seamMask;+ CALayer *_foot;+ UIVisualEffectView *_seamBlur, *_lyricsBlur;CGFloat _aspect;}-+ (Class)layerClass {- return AVPlayerLayer.class;+// What fades is the effect views' effect, never their alpha or an ancestor's: UIKit draws a blur under a+// fading alpha or a mask wrongly or not at all.+static UIBlurEffect *blurEffect(void) {+ return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark];}- (instancetype)initWithFrame:(CGRect)frame {if (!(self = [super initWithFrame:frame])) return nil;self.userInteractionEnabled = NO;self.accessibilityElementsHidden = YES;- ((AVPlayerLayer *)self.layer).videoGravity = AVLayerVideoGravityResizeAspectFill;- _foot = [CAGradientLayer layer];- _foot.colors = @[(id)UIColor.blackColor.CGColor, (id)UIColor.blackColor.CGColor, (id)UIColor.clearColor.CGColor];- _foot.locations = @[@0, @(kFootFrom), @1];- self.layer.mask = _foot;- _blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark]];- _blur.alpha = 0;- _blur.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- [self addSubview:_blur];+ _picture = [[UIView alloc] initWithFrame:frame];+ [self addSubview:_picture];+ _foot = [CALayer layer];+ _foot.contentsGravity = kCAGravityResize;+ [_picture.layer addSublayer:_foot];+ _clip = [AVPlayerLayer layer];+ _clip.videoGravity = AVLayerVideoGravityResizeAspectFill;+ _clipMask = [CAGradientLayer layer];+ _clipMask.colors = @[(id)UIColor.blackColor.CGColor, (id)UIColor.blackColor.CGColor, (id)UIColor.clearColor.CGColor];+ _clipMask.locations = @[@0, @(kFootFrom), @1];+ _clip.mask = _clipMask;+ [_picture.layer addSublayer:_clip];++ _seamBlur = [[UIVisualEffectView alloc] initWithEffect:nil];+ _seamBlur.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ UIView *mask = [UIView new];+ _seamMask = [CAGradientLayer layer];+ _seamMask.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.blackColor.CGColor];+ [mask.layer addSublayer:_seamMask];+ _seamBlur.maskView = mask;+ [self addSubview:_seamBlur];+ _lyricsBlur = [[UIVisualEffectView alloc] initWithEffect:nil];+ _lyricsBlur.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ [self addSubview:_lyricsBlur];++ NSNotificationCenter *center = NSNotificationCenter.defaultCenter;+ for (NSNotificationName name in @[UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification,+ NSProcessInfoPowerStateDidChangeNotification, UIAccessibilityReduceMotionStatusDidChangeNotification]) {+ [center addObserver:self selector:@selector(updateMotionSoon) name:name object:nil];+ }+ SGRObservePlayerTransition(self, ^(id owner) { [owner updateMotion]; }, ^(id owner) { [owner updateMotion]; });return self;}+- (void)dealloc {+ [NSNotificationCenter.defaultCenter removeObserver:self];+}++- (void)setScreenHeight:(CGFloat)height {+ if (height == _screenHeight) return;+ _screenHeight = height;+ [self setNeedsLayout];+}+- (void)layoutSubviews {[super layoutSubviews];+ CGRect bounds = self.bounds;+ CGFloat width = bounds.size.width, total = MAX(1, bounds.size.height);+ CGFloat screen = _screenHeight > 0 ? _screenHeight : total;+ CGFloat height = round(width * _aspect);+ if (_aspect > kCanvasAspect) height = MAX(height, screen);+ CGFloat seam = round(height * kFootFrom), blurFrom = MIN(seam, round(screen * kBlurByControls));+ _picture.frame = bounds;+ _seamBlur.frame = bounds;+ _seamBlur.maskView.frame = bounds;+ _lyricsBlur.frame = bounds;[CATransaction begin];[CATransaction setDisableActions:YES];- _foot.frame = self.bounds;+ _clip.frame = CGRectMake(0, 0, width, height);+ _clipMask.frame = _clip.bounds;+ _foot.frame = CGRectMake(0, seam, width, MAX(0, total - seam));+ _seamMask.frame = bounds;+ _seamMask.locations = @[@(MIN(1, blurFrom / total)), @(MIN(1, (blurFrom + kBlurRamp) / total))];[CATransaction commit];- _blur.frame = self.bounds;}-- (void)playFile:(NSURL *)file aspect:(CGFloat)aspect {- _aspect = aspect;+- (void)playFile:(NSURL *)file poster:(UIImage *)poster {+ _aspect = poster.size.height / poster.size.width;+ // The poster's last rows, stretched from the seam to the bottom: the clip goes on down in its own colour.+ CGFloat rows = MAX(kFootRows, 1 / MAX(1, poster.size.height * poster.scale));+ _foot.contents = (__bridge id)poster.CGImage;+ _foot.contentsRect = CGRectMake(0, 1 - rows, 1, rows);_player = [AVQueuePlayer new];_player.muted = YES;_player.preventsDisplaySleepDuringVideoPlayback = NO;_looper = [AVPlayerLooper playerLooperWithPlayer:_player templateItem:[AVPlayerItem playerItemWithURL:file]];- ((AVPlayerLayer *)self.layer).player = _player;- if (self.window) [_player play];+ _clip.player = _player;+ [self setNeedsLayout];+ [self updateMotion];}-- (CGFloat)aspect {- return _aspect;+- (void)appear:(BOOL)animated {+ _picture.alpha = 0;+ void (^apply)(void) = ^{+ self->_picture.alpha = 1;+ self->_seamBlur.effect = blurEffect();+ };+ if (animated) SGRAnimate(SGRMotionFade, apply, nil);+ else apply();}- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated {- void (^apply)(void) = ^{ self->_blur.alpha = blurred ? 1 : 0; };+ void (^apply)(void) = ^{ self->_lyricsBlur.effect = blurred ? blurEffect() : nil; };if (animated) SGRAnimate(SGRMotionFade, apply, nil);else apply();}-// Off screen, the clip stops decoding. A clip that arrived while the player was closed hides the cover-// once the player opens.+// The power state is reported off the main thread.+- (void)updateMotionSoon {+ dispatch_async(dispatch_get_main_queue(), ^{ [self updateMotion]; });+}++// A locked phone keeps the player in its window, so being in front counts as much as being in one.+- (void)updateMotion {+ BOOL front = UIApplication.sharedApplication.applicationState == UIApplicationStateActive;+ BOOL may = self.window && front && !SGRPlayerIsTransitioning() && !SGRReduceMotion() && !NSProcessInfo.processInfo.lowPowerModeEnabled;+ if (may) [_player play];+ else [_player pause];+}+- (void)didMoveToWindow {[super didMoveToWindow];- if (self.window) {- [_player play];- setCoverShown(NO);- } else {- [_player pause];- }+ [self updateMotion];}@endstatic SGRPlayerMotionView *sg_motion;static NSString *sg_track;+// The list the empty mask went on, so it comes off even while the player is closed and the list cannot+// be found.+static __weak CALayer *sg_maskedCovers;-// The clip from the top of the field, as wide as it is: a Canvas down to the window's foot.+// The clip from the top of the field, as wide as it is, its foot down to the bottom of the field's bleed.static void layOut(void) {SGRArtworkField *field = SGRPlayerField();if (!sg_motion || !field) return;if (sg_motion.superview != field) [field addSubview:sg_motion];- CGFloat width = field.bounds.size.width, aspect = [(id)sg_motion aspect];- CGFloat height = round(width * aspect);- if (aspect > kCanvasAspect) height = MAX(height, field.window.bounds.size.height ?: height);- CGRect frame = CGRectMake(0, 0, width, height);+ CGSize size = field.bounds.size;+ CGFloat screen = field.window.bounds.size.height ?: size.height;+ CGRect frame = CGRectMake(0, 0, size.width, MAX(size.height, screen) + field.bleed.bottom);if (!CGRectEqualToRect(sg_motion.frame, frame)) sg_motion.frame = frame;- // The field's width follows the plane's; the height was set for this clip.- sg_motion.autoresizingMask = UIViewAutoresizingFlexibleWidth;+ sg_motion.screenHeight = screen;}// An empty mask rather than alpha: the covers still take the swipe that changes track, and the lyrics,// which fade the list by its alpha as they come and go, cannot bring the cover back.static void setCoverShown(BOOL shown) {+ if (shown) {+ sg_maskedCovers.mask = nil;+ sg_maskedCovers = nil;+ return;+ }CALayer *covers = SGRPlayerCoverList().layer;- if (!covers || (covers.mask == nil) == shown) return;- covers.mask = shown ? nil : [CALayer layer];+ if (!covers || covers.mask) return;+ covers.mask = [CALayer layer];+ sg_maskedCovers = covers;+}++void SGRPlayerMotionFieldLaidOut(void) {+ layOut();+ setCoverShown(sg_motion == nil);+}++BOOL SGRPlayerMotionShowing(void) {+ return sg_motion != nil;}static void clear(void) {@@ -133,17 +230,11 @@ static void show(NSString *track, NSURL *file) {if (!poster || poster.size.width <= 0 || ![track isEqualToString:sg_track]) return;clear();sg_motion = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];- sg_motion.alpha = 0;- [sg_motion playFile:file aspect:poster.size.height / poster.size.width];+ [sg_motion playFile:file poster:poster];layOut();[sg_motion setBlurred:SGRPlayerLyricsOpen() animated:NO];- BOOL animated = sg_motion.window != nil;- void (^appear)(void) = ^{- sg_motion.alpha = 1;- setCoverShown(NO);- };- if (animated) SGRAnimate(SGRMotionFade, appear, nil);- else appear();+ [sg_motion appear:sg_motion.window != nil];+ setCoverShown(NO);SGLog(@"redesign player: animated artwork %@, %.0fx%.0f", file.lastPathComponent, poster.size.width, poster.size.height);});}@@ -161,6 +252,8 @@ void SGRPlayerMotionLyricsChanged(void) {if (!track || [track isEqualToString:sg_track]) return;sg_track = track;clear();+ // Read on every track, since the ⋯ menu switches it.+ if (SGRPlayerBackground() != SGRPlayerBackgroundAnimated) return;NSDictionary *metadata = [state.track.metadata isKindOfClass:NSDictionary.class] ? state.track.metadata : nil;id type = metadata[@"canvas.type"], address = metadata[@"canvas.url"];BOOL video = [type isKindOfClass:NSString.class] && [type rangeOfString:@"video" options:NSCaseInsensitiveSearch].location != NSNotFound;@@ -183,9 +276,36 @@ void SGRPlayerMotionLyricsChanged(void) {}@end+static SGRPlayerMotionWatcher *sg_watcher;++#pragma mark - the ⋯ menu's switch (Shared/Player/SpeedPitch.h)++// Fluid and Animated share the field, so the menu moves between the two without a restart. The other+// backgrounds are a field of another kind, chosen on the Now playing page.+BOOL SGPlayerMenuOffersAnimatedArtwork(void) {+ if (!sg_watcher) return NO;+ SGRPlayerBackgroundKind background = SGRPlayerBackground();+ return background == SGRPlayerBackgroundFluid || background == SGRPlayerBackgroundAnimated;+}++BOOL SGPlayerMenuAnimatedArtwork(void) {+ return SGRPlayerBackground() == SGRPlayerBackgroundAnimated;+}++void SGPlayerMenuSetAnimatedArtwork(BOOL on) {+ if (!SGPlayerMenuOffersAnimatedArtwork() || on == SGPlayerMenuAnimatedArtwork()) return;+ SGSetInt(SGRKeyPlayerBackground, on ? SGRPlayerBackgroundAnimated : SGRPlayerBackgroundFluid);+ SGLog(@"redesign player: animated artwork switched %@ from the menu", on ? @"on" : @"off");+ // The playing track is let go, and looked up again when switched on.+ sg_track = nil;+ clear();+ [sg_watcher playerStateDidChange:SGPlayerState()];+}+%ctor {- if (!SGRedesignedUI() || SGRPlayerBackground() != SGRPlayerBackgroundAnimated) return;- static SGRPlayerMotionWatcher *watcher;- watcher = [SGRPlayerMotionWatcher new];- SGAddPlayerStateObserver(watcher);+ if (!SGRedesignedUI()) return;+ SGRPlayerBackgroundKind background = SGRPlayerBackground();+ if (background != SGRPlayerBackgroundFluid && background != SGRPlayerBackgroundAnimated) return;+ sg_watcher = [SGRPlayerMotionWatcher new];+ SGAddPlayerStateObserver(sg_watcher);}diff --git a/tweak/Sources/Shared/Player/SpeedPitch.h b/tweak/Sources/Shared/Player/SpeedPitch.hindex 7b09a6fd..a4357202 100644--- a/tweak/Sources/Shared/Player/SpeedPitch.h+++ b/tweak/Sources/Shared/Player/SpeedPitch.h@@ -2,7 +2,8 @@// Nothing here draws on a Spotify screen of its own: the block goes into Spotify's own context menu// sheet, and the rest is audio.//-// SpeedPitchMenu.x the expandable row and its two sliders, put into Spotify's context menu+// SpeedPitchMenu.x the expandable row and its two sliders, put into Spotify's context menu, and under+// the redesign the Animated artwork switch under them// SpeedPitch.x speed and pitch done to Spotify's audio, between its mixer and its speaker unit// SGTimePitch.m Apple's time and pitch unit, pulling the mixer or working in place//@@ -30,3 +31,11 @@ BOOL SGPlayerPitchFollowsSpeed(void);void SGSetPlayerPitchFollowsSpeed(BOOL follows);// Whether the output could be reached to change its pitch.BOOL SGPlayerPitchAvailable(void);++// The redesign's Animated artwork, switched in the same block: whether the player offers the switch (the+// redesign is running and its background is Fluid or Animated, the two that share a field), whether it is+// on, and switching it, which applies at once and is stored as the Background choice. Defined by+// Redesigned/Player/PlayerMotion.x; NO from the first under the native look.+BOOL SGPlayerMenuOffersAnimatedArtwork(void);+BOOL SGPlayerMenuAnimatedArtwork(void);+void SGPlayerMenuSetAnimatedArtwork(BOOL on);diff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.xindex ff83e601..2a29b5c1 100644--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x@@ -21,6 +21,9 @@//// The block keeps whether it was open for the rest of the session; speed and pitch last until Spotify// quits.+//+// Under the redesign, with the player's background Fluid or Animated, a row under the block switches+// Animated artwork (SpeedPitch.h), which the redesign's PlayerMotion.x defines.#import <CoreText/SFNTLayoutTypes.h>#import <objc/runtime.h>#import "Core/SGCore.h"@@ -99,6 +102,10 @@ static char kBlockKey, kDecidedKey, kWatchedKey, kShownAtKey, kRowsInKey;UISlider *_speed, *_pitch, *_reverb;UILabel *_followsName;UISwitch *_follows;+ UIView *_animatedRow;+ UIImageView *_animatedIcon;+ UILabel *_animatedName;+ UISwitch *_animated;float _shownSpeed, _shownPitch, _shownReverb;NSTimeInterval _speedSentAt;BOOL _speedPending;@@ -233,12 +240,26 @@ static void placeTick(UISlider *slider) {for (UIView *view in @[_speedName, _speedValue, _speed, _pitchName, _pitchValue, _pitch, _reverbName, _reverbValue, _reverb,_followsName, _follows]) [_panel addSubview:view];+ if (SGPlayerMenuOffersAnimatedArtwork()) {+ _animatedRow = [UIView new];+ _animatedIcon = [[UIImageView alloc] initWithImage:paintedSymbol(@"play.rectangle.on.rectangle", 18, UIImageSymbolWeightRegular, secondary())];+ _animatedIcon.contentMode = UIViewContentModeCenter;+ _animatedName = makeLabel(font(UIFontTextStyleBody, UIFontWeightRegular, UIContentSizeCategoryExtraLarge), primary());+ _animatedName.text = @"Animated artwork";+ _animated = [UISwitch new];+ _animated.accessibilityLabel = @"Animated artwork";+ [_animated addTarget:self action:@selector(animatedChanged) forControlEvents:UIControlEventValueChanged];+ for (UIView *view in @[_animatedIcon, _animatedName, _animated]) [_animatedRow addSubview:view];+ [self addSubview:_animatedRow];+ }+[self refresh];return self;}+ (CGFloat)heightOpen:(BOOL)open {- return kRowHeight + (open ? 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom : 0);+ return kRowHeight + (open ? 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom : 0)+ + (SGPlayerMenuOffersAnimatedArtwork() ? kRowHeight : 0);}- (void)layoutSubviews {@@ -267,6 +288,13 @@ static void placeTick(UISlider *slider) {CGSize toggle = [_follows sizeThatFits:CGSizeZero];_follows.frame = CGRectMake(width - side - toggle.width, y + (kSwitchRowHeight - toggle.height) / 2, toggle.width, toggle.height);_followsName.frame = CGRectMake(side, y, CGRectGetMinX(_follows.frame) - side - kGrid, kSwitchRowHeight);++ // Under the panel while it is open, under the row while it is closed.+ _animatedRow.frame = CGRectMake(0, sg_open ? CGRectGetMaxY(_panel.frame) : kRowHeight, width, kRowHeight);+ _animatedIcon.frame = _icon.frame;+ toggle = [_animated sizeThatFits:CGSizeZero];+ _animated.frame = CGRectMake(width - side - toggle.width, (kRowHeight - toggle.height) / 2, toggle.width, toggle.height);+ _animatedName.frame = CGRectMake(titleX, 0, MAX(0, CGRectGetMinX(_animated.frame) - kGrid - titleX), kRowHeight);}#pragma mark state@@ -313,6 +341,7 @@ static NSString *pitchText(float pitch) {_follows.on = SGPlayerPitchFollowsSpeed();_follows.enabled = speedAllowed;_follows.alpha = _followsName.alpha = speedAllowed ? 1 : 0.4;+ _animated.on = SGPlayerMenuAnimatedArtwork();[self showValues];}@@ -446,6 +475,11 @@ static NSString *pitchText(float pitch) {[self showValues];}+- (void)animatedChanged {+ SGPlayerMenuSetAnimatedArtwork(_animated.on);+ SGPlayFeedback(SGFeedbackDetent);+}+- (void)followsChanged {SGSetPlayerPitchFollowsSpeed(_follows.on);SGPlayFeedback(SGFeedbackDetent);