Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: the redesigned player offers Fluid and Animated backgrounds
My-Name-Is-Jeff882765da6bac
diff --git a/harness/album/build.sh b/harness/album/build.shindex f85c5deb..b1dfa6c2 100755--- a/harness/album/build.sh+++ b/harness/album/build.sh@@ -17,11 +17,11 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar"$OUT"/gen/*.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \- "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m \+ "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \"$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \"$SRC"/Redesigned/Kit/SGRedesign.m \- -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \-o "$OUT/AlbumHarness.app/AlbumHarness"cat > "$OUT/AlbumHarness.app/Info.plist" <<'PLIST'diff --git a/harness/artist/build.sh b/harness/artist/build.shindex ef18810f..f8be9ae4 100755--- a/harness/artist/build.sh+++ b/harness/artist/build.sh@@ -17,11 +17,11 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar"$OUT"/gen/*.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \- "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m \+ "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \"$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \"$SRC"/Redesigned/Kit/SGRedesign.m \- -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \-o "$OUT/ArtistHarness.app/ArtistHarness"cat > "$OUT/ArtistHarness.app/Info.plist" <<'PLIST'diff --git a/harness/artist/main.m b/harness/artist/main.mindex a67c6e85..0fa883d6 100644--- a/harness/artist/main.m+++ b/harness/artist/main.m@@ -289,7 +289,7 @@ static NSArray<NSArray *> *musicList(void) {wash.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];UIView *titleBox = box(header, UIView.class, CGRectMake(16, 334.67, 370, 54), nil);- label(titleBox, CGRectMake(0, 0, 370, 54), @"Shawn Mendes", 45, UIColor.whiteColor, @"Encore.AdaptiveTitle");+ label(titleBox, CGRectMake(0, 0, 370, 54), NSProcessInfo.processInfo.environment[@"HARNESS_ARTIST"] ?: @"Shawn Mendes", 45, UIColor.whiteColor, @"Encore.AdaptiveTitle");UIView *badge = box(header, UIStackView.class, CGRectMake(16, 390.67, 114.67, 24), @"ImageHeaderView.VerifiedBadge");label(badge, CGRectMake(20, 4, 94, 15), @"Verified by Spotify", 11, UIColor.whiteColor, @"Encore.Label");UIView *meta = box(header, UIView.class, CGRectMake(16, 432.67, 370, 15.33), nil);diff --git a/harness/player/build.sh b/harness/player/build.shindex 8a1becb5..20d2be99 100755--- a/harness/player/build.sh+++ b/harness/player/build.sh@@ -6,7 +6,7 @@ OUT=${OUT:-$(dirname "$0")/build}rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/PlayerHarness.app"for f in Redesigned/Player/PlayerLyrics.x Redesigned/Player/PlayerArtwork.x Redesigned/Player/PlayerFooter.x \- Redesigned/Player/PlayerScroll.x Redesigned/Player/PlayerField.x Redesigned/Kit/SGRBridges.x; do+ Redesigned/Player/PlayerScroll.x Redesigned/Player/PlayerField.x Redesigned/Player/PlayerMotion.x Redesigned/Kit/SGRBridges.x; doname=$(basename "$f" .x)"$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$name.m"done@@ -19,11 +19,11 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar"$OUT"/gen/*.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \- "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m \+ "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \"$SRC"/Redesigned/Kit/SGRedesign.m \"$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \- -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \-o "$OUT/PlayerHarness.app/PlayerHarness"cat > "$OUT/PlayerHarness.app/Info.plist" <<'PLIST'diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex f1c7790e..166579d9 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -61,6 +61,14 @@ void SGRHarnessSetTrack(NSString *uri, NSString *imageURI, BOOL paused) {metadata[@"image_url"] = [@"spotify:image:ab67616d00001e02" stringByAppendingString:hash];metadata[@"image_small_url"] = [@"spotify:image:ab67616d00004851" stringByAppendingString:hash];}+ // HARNESS_ARTIST, HARNESS_ALBUM and HARNESS_CANVAS (a video URL) give Animated artwork something to find.+ NSDictionary<NSString *, NSString *> *env = NSProcessInfo.processInfo.environment;+ if (env[@"HARNESS_ARTIST"]) [track setValue:env[@"HARNESS_ARTIST"] forKey:@"artistName"];+ if (env[@"HARNESS_ALBUM"]) metadata[@"album_title"] = env[@"HARNESS_ALBUM"];+ if (env[@"HARNESS_CANVAS"]) {+ metadata[@"canvas.type"] = @"VIDEO_LOOPING_RANDOM";+ metadata[@"canvas.url"] = env[@"HARNESS_CANVAS"];+ }[track setValue:metadata forKey:@"metadata"];SPTPlayerState *state = [SPTPlayerState new];[state setValue:track forKey:@"track"];@@ -112,3 +120,9 @@ void SGKaraokeSeek(NSInteger ms) {sg_started = CACurrentMediaTime();}void SGRHarnessPlayFrom(NSInteger ms) { SGKaraokeSeek(ms); }++// Line meanings: Genius is not asked in the harness.+#import "Shared/LyricsMeanings/Meanings.h"+void SGLyricsMeaningsFor(NSString *trackID, NSArray<SGKaraokeLine *> *lines,+ void (^done)(NSDictionary<NSNumber *, NSArray<SGLyricsMeaning *> *> *byLine)) {}+void SGRShowMeanings(NSString *lineText, NSArray<SGLyricsMeaning *> *meanings) {}diff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.hindex 4b7110f3..67ec6e6a 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.h+++ b/tweak/Sources/Redesigned/Kit/SGRField.h@@ -26,6 +26,9 @@ extern NSNotificationName const SGRFieldColorDidChangeNotification;// the app is in front, the player is not opening or closing, Reduce Motion and Low Power Mode are off// and nothing holds it (motionHeld); otherwise it stays still where it was.@property (nonatomic) BOOL flows;+// Fluid artwork instead (SGRFluid.h): the cover itself blurred and slowly turning over the whole of the+// bounds, under the same conditions for moving as `flows`. Setting one turns the other off.+@property (nonatomic) BOOL fluid;// Held still by the owner (the player while playback is paused).@property (nonatomic) BOOL motionHeld;// The backdrop's height in points from the top of the bounds; 0 is the window's height.diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.mindex 4c9062c3..40e4c546 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.m+++ b/tweak/Sources/Redesigned/Kit/SGRField.m@@ -1,6 +1,7 @@#import "Core/SGCore.h"#import "SGRField.h"#import "SGRFlow.h"+#import "SGRFluid.h"#import "SGRBridges.h"#import "SGRPalette.h"#import "SGRTokens.h"@@ -35,6 +36,7 @@ static NSDictionary *noActions(void) {CAGradientLayer *_black;CALayer *_backdrop;SGRFlowLayer *_flow;+ SGRFluidLayer *_fluidLayer;BOOL _watching;UIColor *_color;UIColor *_preferred; // the page's own colour, made fit; wins over the artwork's@@ -102,14 +104,36 @@ static NSDictionary *noActions(void) {_black.locations = @[@(MIN(1, from / total)), @(MIN(1, to / total))];_backdrop.frame = CGRectMake(0, 0, bounds.size.width, [self backdropHeightNow]);_flow.frame = CGRectMake(0, 0, bounds.size.width, [self backdropHeightNow]);+ _fluidLayer.frame = painted;+ // The screen's part of it, so the copies turn about it and the shade ends at the screen's foot.+ _fluidLayer.visibleRect = CGRectMake(bleed.left, bleed.top, bounds.size.width, height);[CATransaction commit];}#pragma mark - the moving field+- (void)setFluid:(BOOL)fluid {+ if (fluid == _fluid) return;+ _fluid = fluid;+ if (fluid) self.flows = NO;+ if (fluid && !_fluidLayer) {+ _fluidLayer = [SGRFluidLayer layer];+ [self.layer insertSublayer:_fluidLayer above:_solid];+ }+ // The fluid field is the whole picture, as the moving one is.+ _fluidLayer.hidden = !fluid;+ _black.hidden = fluid || _flows;+ if (fluid) _backdrop.hidden = YES;+ if (fluid && _image) [_fluidLayer setArtwork:_image animated:NO];+ [self watch];+ [self updateMotion];+ [self setNeedsLayout];+}+- (void)setFlows:(BOOL)flows {if (flows == _flows) return;_flows = flows;+ if (flows) self.fluid = NO;if (flows && !_flow) {_flow = [SGRFlowLayer layer];_flow.hidden = YES;@@ -131,7 +155,7 @@ static NSDictionary *noActions(void) {}- (void)watch {- if (_watching || !_flows) return;+ if (_watching || (!_flows && !_fluid)) return;_watching = YES;NSNotificationCenter *center = NSNotificationCenter.defaultCenter;for (NSNotificationName name in @[UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification,@@ -151,12 +175,14 @@ static NSDictionary *noActions(void) {}- (void)updateMotion {- if (!_flow) return;+ if (!_flow && !_fluidLayer) return;// A locked phone keeps the player in its window, so being in front counts as much as being in one.BOOL front = UIApplication.sharedApplication.applicationState == UIApplicationStateActive;- BOOL moving = _flows && !_flow.hidden && self.window && front && !SGRPlayerIsTransitioning() && !SGRReduceMotion()- && !NSProcessInfo.processInfo.lowPowerModeEnabled && !_motionHeld;- if (moving == _flow.moving) return;+ BOOL may = self.window && front && !SGRPlayerIsTransitioning() && !SGRReduceMotion()+ && !NSProcessInfo.processInfo.lowPowerModeEnabled && !_motionHeld;+ _fluidLayer.moving = may && _fluid;+ BOOL moving = may && _flows && !_flow.hidden;+ if (!_flow || moving == _flow.moving) return;_flow.moving = moving;static NSUInteger logged;if (logged++ < 6) SGLog(@"redesign kit: moving field %@", moving ? @"moves" : @"holds still");@@ -205,9 +231,10 @@ static NSDictionary *noActions(void) {if (!image || image == _image || (identity && [identity isEqualToString:_identity])) return;_image = image;_identity = [identity copy];+ if (_fluid) [_fluidLayer setArtwork:image animated:animated && self.window != nil];NSUInteger generation = ++_generation;SGRPaletteRequest request = {CGSizeZero, NO, YES, _flows};- if (_showsBackdrop && !_flows) request.backdropSize = CGSizeMake(self.bounds.size.width > 0 ? self.bounds.size.width : 402, [self backdropHeightNow]);+ if (_showsBackdrop && !_flows && !_fluid) request.backdropSize = CGSizeMake(self.bounds.size.width > 0 ? self.bounds.size.width : 402, [self backdropHeightNow]);__weak SGRArtworkField *weakSelf = self;[SGRPalette paletteForImage:image request:request completion:^(SGRPalette *palette) {SGRArtworkField *field = weakSelf;@@ -226,7 +253,7 @@ static NSDictionary *noActions(void) {[self applyColor:_preferred ?: _flow.baseColor animated:animated];return;}- if (_showsBackdrop && !_flows && palette.backdrop) {+ if (_showsBackdrop && !_flows && !_fluid && palette.backdrop) {[CATransaction begin];[CATransaction setDisableActions:YES];if (animated) {diff --git a/tweak/Sources/Redesigned/Kit/SGRFluid.h b/tweak/Sources/Redesigned/Kit/SGRFluid.hnew file mode 100644index 00000000..9ccff2bc--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRFluid.h@@ -0,0 +1,20 @@+// Fluid artwork: the cover itself, blurred and slowly warped behind the player. Four copies of a+// blurred, saturated cover, each far larger than the screen, turn about different centres at different+// speeds, two each way; where they overlap the picture seems to flow. A shade over the bottom keeps the+// controls legible.+//+// Like SGRFlow.h it is all Core Animation: repeating rotations the render server plays, nothing drawn+// per frame by the app. Stopping holds every copy where it is, and starting again carries on from there.+//+// Threading: main thread only; the blur runs off it.+#import <UIKit/UIKit.h>++@interface SGRFluidLayer : CALayer+// The cover, blurred off the main thread and crossfaded in. The same image again is a no-op.+- (void)setArtwork:(UIImage *)image animated:(BOOL)animated;+// Turning, or held still where it is. Off to begin with.+@property (nonatomic) BOOL moving;+// The part of the layer on screen, in its own coordinates: the copies turn about points in it and the+// shade darkens its bottom, whatever the layer bleeds past it. The whole layer while empty.+@property (nonatomic) CGRect visibleRect;+@enddiff --git a/tweak/Sources/Redesigned/Kit/SGRFluid.m b/tweak/Sources/Redesigned/Kit/SGRFluid.mnew file mode 100644index 00000000..8e43c6ad--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRFluid.m@@ -0,0 +1,178 @@+#import <CoreImage/CoreImage.h>+#import "Core/SGCore.h"+#import "SGRFluid.h"+#import "SGRTokens.h"++// Each copy: its side as a share of the visible rect's longer side, its centre as shares of that rect, and+// one turn's length in seconds (negative turns the other way).+static const struct { CGFloat side, x, y; CFTimeInterval turn; } kCopy[] = {+ {2.2, 0.25, 0.20, 46},+ {2.0, 0.80, 0.35, -61},+ {2.4, 0.30, 0.75, 73},+ {1.8, 0.70, 0.85, -54},+};+enum { kCopies = sizeof(kCopy) / sizeof(kCopy[0]) };+// The blurred cover is small: it is drawn several times the screen's size, so detail is lost anyway.+static const CGFloat kBlurSide = 128, kBlurRadius = 10, kSaturation = 1.5, kBrightness = -0.08;+// The shade over the bottom of the visible rect, where the controls are.+static const CGFloat kShadeFrom = 0.45, kShadeAlpha = 0.55;++static UIImage *blurred(UIImage *image) {+ CGImageRef source = image.CGImage;+ if (!source) return nil;+ CIImage *input = [CIImage imageWithCGImage:source];+ CGFloat scale = kBlurSide / MAX(input.extent.size.width, input.extent.size.height);+ input = [input imageByApplyingTransform:CGAffineTransformMakeScale(scale, scale)];+ CGRect extent = input.extent;+ CIImage *output = [[[input imageByClampingToExtent]+ imageByApplyingFilter:@"CIGaussianBlur" withInputParameters:@{kCIInputRadiusKey: @(kBlurRadius)}]+ imageByApplyingFilter:@"CIColorControls" withInputParameters:@{kCIInputSaturationKey: @(kSaturation), kCIInputBrightnessKey: @(kBrightness)}];+ static CIContext *context;+ static dispatch_once_t once;+ dispatch_once(&once, ^{ context = [CIContext contextWithOptions:nil]; });+ CGImageRef cg = [context createCGImage:[output imageByCroppingToRect:extent] fromRect:extent];+ if (!cg) return nil;+ UIImage *result = [UIImage imageWithCGImage:cg];+ CGImageRelease(cg);+ return result;+}++@implementation SGRFluidLayer {+ CALayer *_copies[kCopies];+ CAGradientLayer *_shade;+ UIImage *_source;+ NSUInteger _generation;+ BOOL _moving;+ CFTimeInterval _since, _elapsed;+ CGRect _laidOutFor;+}++- (instancetype)init {+ if (!(self = [super init])) return nil;+ self.masksToBounds = YES;+ self.backgroundColor = UIColor.blackColor.CGColor;+ for (int i = 0; i < kCopies; i++) {+ _copies[i] = [CALayer layer];+ _copies[i].contentsGravity = kCAGravityResizeAspectFill;+ _copies[i].opacity = i == 0 ? 1 : 0.7;+ [self addSublayer:_copies[i]];+ }+ _shade = [CAGradientLayer layer];+ _shade.colors = @[(id)[UIColor colorWithWhite:0 alpha:0].CGColor, (id)[UIColor colorWithWhite:0 alpha:kShadeAlpha].CGColor];+ [self addSublayer:_shade];+ return self;+}++- (BOOL)moving {+ return _moving;+}++- (void)setVisibleRect:(CGRect)rect {+ if (CGRectEqualToRect(rect, _visibleRect)) return;+ _visibleRect = rect;+ [self setNeedsLayout];+}++- (void)layoutSublayers {+ [super layoutSublayers];+ CGRect bounds = self.bounds;+ CGRect visible = CGRectIsEmpty(_visibleRect) ? bounds : _visibleRect;+ CGFloat total = MAX(1, bounds.size.height);+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _shade.frame = bounds;+ _shade.locations = @[@(MIN(1, (CGRectGetMinY(visible) + visible.size.height * kShadeFrom) / total)),+ @(MIN(1, CGRectGetMaxY(visible) / total))];+ if (!CGRectEqualToRect(visible, _laidOutFor) && visible.size.width >= 1) {+ _laidOutFor = visible;+ BOOL moving = _moving;+ if (moving) [self stop];+ CGFloat longer = MAX(visible.size.width, visible.size.height);+ for (int i = 0; i < kCopies; i++) {+ CGFloat side = round(longer * kCopy[i].side);+ _copies[i].bounds = CGRectMake(0, 0, side, side);+ _copies[i].position = CGPointMake(CGRectGetMinX(visible) + visible.size.width * kCopy[i].x,+ CGRectGetMinY(visible) + visible.size.height * kCopy[i].y);+ }+ if (moving) [self start];+ }+ [CATransaction commit];+}++- (void)setArtwork:(UIImage *)image animated:(BOOL)animated {+ if (!image || image == _source) return;+ _source = image;+ NSUInteger generation = ++_generation;+ __weak SGRFluidLayer *weakSelf = self;+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{+ UIImage *blur = blurred(image);+ dispatch_async(dispatch_get_main_queue(), ^{+ SGRFluidLayer *layer = weakSelf;+ if (!blur || !layer || generation != layer->_generation) return;+ [layer show:blur animated:animated];+ });+ });+}++- (void)show:(UIImage *)blur animated:(BOOL)animated {+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ for (int i = 0; i < kCopies; i++) {+ if (animated) {+ CATransition *fade = [CATransition animation];+ fade.type = kCATransitionFade;+ fade.duration = SGRCrossfade;+ [_copies[i] addAnimation:fade forKey:@"contents"];+ }+ _copies[i].contents = (__bridge id)blur.CGImage;+ }+ [CATransaction commit];+}++#pragma mark - moving++- (void)setMoving:(BOOL)moving {+ if (moving == _moving) return;+ _moving = moving;+ if (moving) [self start];+ else [self stop];+}++- (void)start {+ if (self.bounds.size.width < 1) return;+ _since = CACurrentMediaTime();+ CAFrameRateRange rate = CAFrameRateRangeMake(15, 60, 30);+ for (int i = 0; i < kCopies; i++) {+ CFTimeInterval length = fabs(kCopy[i].turn);+ // The turn's offset carries the angle it stopped at, so the resting angle goes back to none.+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _copies[i].transform = CATransform3DIdentity;+ [CATransaction commit];+ CABasicAnimation *turn = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];+ turn.byValue = @(kCopy[i].turn > 0 ? 2 * M_PI : -2 * M_PI);+ turn.duration = length;+ turn.repeatCount = HUGE_VALF;+ turn.additive = YES;+ turn.timeOffset = fmod(_elapsed, length);+ turn.preferredFrameRateRange = rate;+ [_copies[i] addAnimation:turn forKey:@"turn"];+ }+}++// Every copy held at the angle it is drawn at now.+- (void)stop {+ if (_since > 0) _elapsed += CACurrentMediaTime() - _since;+ _since = 0;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ for (int i = 0; i < kCopies; i++) {+ CFTimeInterval length = fabs(kCopy[i].turn);+ CGFloat angle = (kCopy[i].turn > 0 ? 1 : -1) * 2 * M_PI * fmod(_elapsed, length) / length;+ [_copies[i] removeAnimationForKey:@"turn"];+ _copies[i].transform = CATransform3DMakeRotation(angle, 0, 0, 1);+ }+ [CATransaction commit];+}++@enddiff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.mindex 2aa63228..35a92f68 100644--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m@@ -96,6 +96,12 @@ static const CGFloat kLogoWidthShare = 0.8, kLogoMaxHeight = 64;[self setNeedsLayout];}+// The space under a line: a picture needs more room under it than a line of text does.+- (CGFloat)sgr_gapAfter:(UILabel *)label {+ if (label == _title && _logo.image) return 8;+ return label == _creator ? 4 : 2;+}+// The title's line: the picture's fitted height where there is a picture, the label's otherwise.- (CGSize)sgr_sizeOf:(UILabel *)label width:(CGFloat)text {if (label != _title || !_logo.image) return [label sizeThatFits:CGSizeMake(text, CGFLOAT_MAX)];@@ -179,7 +185,7 @@ static const CGFloat kLogoWidthShare = 0.8, kLogoMaxHeight = 64;UILabel *previous = nil;for (UILabel *label in @[_title, _creator, _length]) {if (label.hidden) continue;- if (previous) height += previous == _creator ? 4 : 2;+ if (previous) height += [self sgr_gapAfter:previous];height += ceil([self sgr_sizeOf:label width:text].height);previous = label;}@@ -197,7 +203,7 @@ static const CGFloat kLogoWidthShare = 0.8, kLogoMaxHeight = 64;UILabel *previous = nil;for (UILabel *label in @[_title, _creator, _length]) {if (label.hidden) continue;- if (previous) y += previous == _creator ? 4 : 2;+ if (previous) y += [self sgr_gapAfter:previous];CGSize size = [self sgr_sizeOf:label width:text];CGFloat height = ceil(size.height);label.frame = CGRectMake(kSide, y, text, height);diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.mindex 64f96a8d..ac7f36ae 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m@@ -11,7 +11,8 @@ UIViewController *SGRNowPlayingBarSettingsPage(void) {SGHideRow(@"Hide the device button", nil, SGRHideBarConnect),]),SGSection(nil, @[- SGSwitchRow(@"Moving background", nil, SGRKeyPlayerMotion),+ SGChoiceRow(@"Background", @"Animated plays the Canvas or Apple Music's animated cover, over Fluid",+ SGRKeyPlayerBackground, SGRPlayerBackgroundNames(), SGRPlayerBackground()),]),] footer:nil];}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 8335ae86..909f51e2 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -25,9 +25,19 @@@class SGRArtworkField;-// The artwork's colours moving behind the player (on until switched off), or the blurred artwork held-// still; the row is on the Now playing page (Redesigned/NowPlayingBar/NowPlayingBarSettings.m).+// What is behind the player, chosen on the Now playing page (Redesigned/NowPlayingBar/NowPlayingBarSettings.m).+// SGRKeyPlayerMotion is the switch the choice replaced: until a choice is stored, it picks Still or Colours.+#define SGRKeyPlayerBackground @"spotifyglass.redesign.player.background"#define SGRKeyPlayerMotion @"spotifyglass.redesign.player.movingBackground"+typedef NS_ENUM(NSInteger, SGRPlayerBackgroundKind) {+ SGRPlayerBackgroundStill, // the artwork blurred and held still+ SGRPlayerBackgroundColours, // 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)+};+SGRPlayerBackgroundKind SGRPlayerBackground(void);+// The names of the choices, in order.+NSArray<NSString *> *SGRPlayerBackgroundNames(void);// The field behind the player, nil until the player has laid out once (PlayerField.x).SGRArtworkField *SGRPlayerField(void);@@ -57,6 +67,8 @@ void SGRPlayerToggleLyrics(void);// Called by PlayerLyrics.x whenever either of those two changed, so the footer's lyrics glyph follows// (PlayerFooter.x). It returns at once when nothing changed.void SGRPlayerLyricsChanged(void);+// The animated artwork follows the lyrics: blurred behind them (PlayerMotion.x).+void SGRPlayerMotionLyricsChanged(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 dd16708d..9201ca9d 100644--- a/tweak/Sources/Redesigned/Player/PlayerField.x+++ b/tweak/Sources/Redesigned/Player/PlayerField.x@@ -41,6 +41,15 @@ SGRArtworkField *SGRPlayerField(void) {return sg_field;}+SGRPlayerBackgroundKind SGRPlayerBackground(void) {+ NSInteger kind = SGInt(SGRKeyPlayerBackground, SGEnabled(SGRKeyPlayerMotion) ? SGRPlayerBackgroundColours : SGRPlayerBackgroundStill);+ return kind >= SGRPlayerBackgroundStill && kind <= SGRPlayerBackgroundAnimated ? kind : SGRPlayerBackgroundColours;+}++NSArray<NSString *> *SGRPlayerBackgroundNames(void) {+ return @[@"Still", @"Colours", @"Fluid", @"Animated"];+}+#pragma mark - the fieldstatic void showArtwork(SGRArtworkField *field, BOOL animated) {@@ -54,7 +63,9 @@ static SGRArtworkField *fieldIn(UIView *plane) {if (field) return field;field = [[SGRArtworkField alloc] initWithFrame:plane.bounds];field.showsBackdrop = YES;- field.flows = SGEnabled(SGRKeyPlayerMotion);+ SGRPlayerBackgroundKind background = SGRPlayerBackground();+ field.flows = background == SGRPlayerBackgroundColours;+ field.fluid = background >= SGRPlayerBackgroundFluid;// A paused song holds the colours still, the way it rests the cover (PlayerArtwork.x).field.motionHeld = SGPlayerState().isPaused;field.bleed = kBleed;diff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.xindex 6ef196e4..8ca1f5a6 100644--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x@@ -68,6 +68,7 @@ static CGFloat moveTo(UIView *arranged, UIView *view, CGPoint point, UIView *hos#pragma mark - lyricsvoid SGRPlayerLyricsChanged(void) {+ SGRPlayerMotionLyricsChanged();SGRGlyphButton *glyph = sg_lyricsGlyph;if (!glyph) return;BOOL enabled = SGRPlayerLyricsAvailable() || SGRPlayerLyricsOpen(), open = SGRPlayerLyricsOpen();diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xnew file mode 100644index 00000000..9865c7f7--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -0,0 +1,191 @@+// 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.+//+// 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.+#import <AVFoundation/AVFoundation.h>+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"+#import "Shared/Player/PlayerState.h"+#import "Player.h"++// Where the clip starts dissolving, as a share of its height.+static const CGFloat kFootFrom = 0.78;+// 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);++@interface SGRPlayerMotionView : UIView+- (void)playFile:(NSURL *)file aspect:(CGFloat)aspect;+- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated;+@end++@implementation SGRPlayerMotionView {+ AVQueuePlayer *_player;+ AVPlayerLooper *_looper;+ CAGradientLayer *_foot;+ UIVisualEffectView *_blur;+ CGFloat _aspect;+}+++ (Class)layerClass {+ return AVPlayerLayer.class;+}++- (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];+ return self;+}++- (void)layoutSubviews {+ [super layoutSubviews];+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _foot.frame = self.bounds;+ [CATransaction commit];+ _blur.frame = self.bounds;+}++- (void)playFile:(NSURL *)file aspect:(CGFloat)aspect {+ _aspect = aspect;+ _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];+}++- (CGFloat)aspect {+ return _aspect;+}++- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated {+ void (^apply)(void) = ^{ self->_blur.alpha = blurred ? 1 : 0; };+ 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.+- (void)didMoveToWindow {+ [super didMoveToWindow];+ if (self.window) {+ [_player play];+ setCoverShown(NO);+ } else {+ [_player pause];+ }+}++@end++static SGRPlayerMotionView *sg_motion;+static NSString *sg_track;++// The clip from the top of the field, as wide as it is: a Canvas down to the window's foot.+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);+ 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;+}++// 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) {+ CALayer *covers = SGRPlayerCoverList().layer;+ if (!covers || (covers.mask == nil) == shown) return;+ covers.mask = shown ? nil : [CALayer layer];+}++static void clear(void) {+ [sg_motion removeFromSuperview];+ sg_motion = nil;+ setCoverShown(YES);+}++static void show(NSString *track, NSURL *file) {+ if (!file || ![track isEqualToString:sg_track]) return;+ SGMotionPoster(file, ^(UIImage *poster) {+ 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];+ 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();+ SGLog(@"redesign player: animated artwork %@, %.0fx%.0f", file.lastPathComponent, poster.size.width, poster.size.height);+ });+}++void SGRPlayerMotionLyricsChanged(void) {+ [sg_motion setBlurred:SGRPlayerLyricsOpen() animated:sg_motion.window != nil];+}++@interface SGRPlayerMotionWatcher : NSObject <SGPlayerStateObserver>+@end++@implementation SGRPlayerMotionWatcher+- (void)playerStateDidChange:(SPTPlayerState *)state {+ NSString *track = SGURIString(state.track.URI);+ if (!track || [track isEqualToString:sg_track]) return;+ sg_track = track;+ clear();+ 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;+ 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();+ });+}+@end++%ctor {+ if (!SGRedesignedUI() || SGRPlayerBackground() != SGRPlayerBackgroundAnimated) return;+ static SGRPlayerMotionWatcher *watcher;+ watcher = [SGRPlayerMotionWatcher new];+ SGAddPlayerStateObserver(watcher);+}diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.hindex e3340d3f..9a846bf0 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h@@ -21,6 +21,10 @@ void SGMotionAlbumCover(NSString *artist, NSString *album, SGMotionShape shape,// The artist's logo from Apple Music, a transparent PNG `pixels` wide, or nil. Main queue.void SGMotionArtistLogo(NSString *artist, CGFloat pixels, void (^done)(UIImage *logo));+// The width a full-screen clip is downloaded at: three quarters of the screen's pixels. A tall cover at the+// screen's full width ran to 29 MB a song; at this width it was 7 MB and looks the same in motion.+CGFloat SGMotionPixels(void);+// Any remote video (a Canvas) as a local file, or nil. Main queue.void SGMotionFile(NSURL *remote, void (^done)(NSURL *file));diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.mindex 10994bc4..1e000666 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtworkSettings.m@@ -7,7 +7,7 @@ NSArray *SGLockScreenMotionRows(void) {if (@available(iOS 26.0, *)) {return @[SGOptionRow(@"Moving artwork", @"The track's Canvas, else Apple Music's animated cover", SGKeyLockScreenMotion),- SGOptionRow(@"Download in Low Data Mode", @"About 2 to 6 MB a song", SGKeyMotionLowData),+ SGOptionRow(@"Download in Low Data Mode", @"Up to about 7 MB a song", SGKeyMotionLowData),];}return @[];diff --git a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.xindex 84c076ec..eb434425 100644--- a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x+++ b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x@@ -67,7 +67,7 @@ static void show(NSString *uri, NSURL *file) {id type = metadata[@"canvas.type"], address = metadata[@"canvas.url"];BOOL video = [type isKindOfClass:NSString.class] && [type rangeOfString:@"video" options:NSCaseInsensitiveSearch].location != NSNotFound;NSURL *canvas = video && [address isKindOfClass:NSString.class] ? [NSURL URLWithString:address] : nil;- CGFloat pixels = UIScreen.mainScreen.nativeBounds.size.width;+ CGFloat pixels = SGMotionPixels();void (^apple)(void) = ^{SGMotionAlbumCover(artist, album, SGMotionTall, pixels, ^(NSURL *file) { show(uri, file); });};diff --git a/tweak/Sources/Shared/AnimatedArtwork/SGMotionStore.m b/tweak/Sources/Shared/AnimatedArtwork/SGMotionStore.mindex 54440895..c1f7b2f7 100644--- a/tweak/Sources/Shared/AnimatedArtwork/SGMotionStore.m+++ b/tweak/Sources/Shared/AnimatedArtwork/SGMotionStore.m@@ -37,6 +37,10 @@ static void trim(void) {for (NSUInteger i = 0; i + kFiles < oldestFirst.count; i++) [NSFileManager.defaultManager removeItemAtURL:oldestFirst[i] error:nil];}+CGFloat SGMotionPixels(void) {+ return round(UIScreen.mainScreen.nativeBounds.size.width * 0.75);+}+static NSMutableDictionary<NSURL *, NSMutableArray *> *sg_waiting;void SGMotionFile(NSURL *remote, void (^done)(NSURL *file)) {@@ -61,7 +65,12 @@ void SGMotionFile(NSURL *remote, void (^done)(NSURL *file)) {NSInteger status = [response isKindOfClass:NSHTTPURLResponse.class] ? ((NSHTTPURLResponse *)response).statusCode : 0;// The temporary file is gone once this handler returns, so it moves before the hop to main.BOOL kept = temporary && status == 200 && [NSFileManager.defaultManager moveItemAtURL:temporary toURL:local error:nil];- if (kept) trim();+ if (kept) {+ trim();+ NSNumber *bytes = nil;+ [local getResourceValue:&bytes forKey:NSURLFileSizeKey error:nil];+ SGLog(@"motion: %@ kept, %.1f MB", local.lastPathComponent, bytes.doubleValue / 1e6);+ }else SGLog(@"motion: %@ not downloaded (%ld, %@)", remote.lastPathComponent, (long)status, error.localizedDescription);dispatch_async(dispatch_get_main_queue(), ^{NSArray *waiting = sg_waiting[remote];