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 lyrics in the redesigned player itself, the way the Music app shows them, and the player one screen that does not scroll
Vojtěch Škopekd58d811e58ef
diff --git a/.gitignore b/.gitignoreindex 0f9efe8c..ca2b276a 100644--- a/.gitignore+++ b/.gitignore@@ -15,3 +15,4 @@ tweak/packages/tweak/Sources/Shared/Flags/SGFlagList.m/trees/continuous/trees/clean+harness/*/build/diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 889e0f2a..535c6ab9 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -108,7 +108,7 @@ Redesigned:NowPlayingBar/ the glass now playing barPlayer/ the redesigned full screen player (Player.h lists its files)Lyrics/ the full screen lyrics page on glass with Apple Music style lyrics over it, always on (SGRKaraokeView,- also over the card under the player, Player/KaraokeCard.x)+ which the player shows in itself too, Player/PlayerLyrics.x)Home/ Home decluttered to music on black (an allow list of its sections: shortcuts, the DJ without its heading andtranscript, the shelves of cards), a large title where the filter pills were with the avatar at the trailingedge, the shelves' headings at the Music app's size, each shortcut tile's cover run across it blurreddiff --git a/harness/player/README.md b/harness/player/README.mdnew file mode 100644index 00000000..5564080d--- /dev/null+++ b/harness/player/README.md@@ -0,0 +1,28 @@+# Player harness++Spotify's full screen player mocked under its own class names and accessibility identifiers+(from `trees/clean/player/01.txt`), so the redesign's lyrics state can be laid out, animated and+looked at on the Mac without the phone.++ THEOS=$HOME/theos ./build.sh+ xcrun simctl install booted build/PlayerHarness.app+ xcrun simctl launch booted com.vojta.playerharness+ xcrun simctl io booted screenshot shot.png++`build.sh` runs `logos.pl -c generator=internal` over `PlayerLyrics.x`, `PlayerArtwork.x`,+`PlayerFooter.x` and `PlayerScroll.x` and links them with the real `Core/`, `Redesigned/Kit/` and+`SGRKaraokeView`; `stubs.m` stands in for the hooks the harness does not compile (the Kit's bridges+and repaint, the rest of the player, the lyrics store, the haptics) and holds a song of ten timed+lines that plays on from launch.++The mock opens the lyrics two seconds after launch, closes them at six and opens them again at ten,+so a screenshot catches each state and a screen recording catches the move:++ xcrun simctl io booted recordVideo -f run.mp4 # ^C to stop+ ffmpeg -ss 2.9 -t 1.1 -i run.mp4 -vf "fps=10,scale=200:-1,tile=11x1" -frames:v 1 strip.png++It also lays every unit out once a second, which is what the transforms on Spotify's title row and+the narrowed marquee labels have to survive.++What it does not cover: the real element framework's autolayout, Spotify's own scrolled layout, the+player's open and close transition, and the artwork field behind the player (`PlayerField.x`).diff --git a/harness/player/build.sh b/harness/player/build.shnew file mode 100755index 00000000..12910686--- /dev/null+++ b/harness/player/build.sh@@ -0,0 +1,44 @@+#!/bin/sh+set -e+SRC=/Users/vojta/Documents/quick/custom_spotify/custom_spotify/tweak/Sources+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; do+ name=$(basename "$f" .x)+ "$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$name.m"+done++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \+ -I"$SRC" -I"$SRC/Redesigned/Player" -I"$OUT/gen" -isysroot "$SDK" \+ -Wno-deprecated-declarations \+ "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" \+ "$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/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \+ "$SRC"/Redesigned/Kit/SGRedesign.m \+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \+ -o "$OUT/PlayerHarness.app/PlayerHarness"++cat > "$OUT/PlayerHarness.app/Info.plist" <<'PLIST'+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0"><dict>+<key>CFBundleExecutable</key><string>PlayerHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.playerharness</string>+<key>CFBundleName</key><string>PlayerHarness</string>+<key>CFBundleVersion</key><string>1</string>+<key>CFBundleShortVersionString</key><string>1.0</string>+<key>UIUserInterfaceStyle</key><string>Dark</string>+<key>UILaunchScreen</key><dict/>+<key>UIApplicationSceneManifest</key><dict>+ <key>UIApplicationSupportsMultipleScenes</key><false/>+</dict>+</dict></plist>+PLIST+echo "built $OUT/PlayerHarness.app"diff --git a/harness/player/main.m b/harness/player/main.mnew file mode 100644index 00000000..cbf83209--- /dev/null+++ b/harness/player/main.m@@ -0,0 +1,316 @@+// A mock of Spotify's full screen player under its own class names and accessibility identifiers, built+// from trees/clean/player/01.txt, so Redesigned/Player's lyrics state can be laid out, animated and+// looked at on the Mac. Tapping the lyrics glyph in the footer works exactly as it does on the phone;+// the harness also toggles it once by itself so a screenshot catches each state.+#import <UIKit/UIKit.h>+#import "Shared/Lyrics/Lyrics.h"+#import "Redesigned/Player/Player.h"++void SGRHarnessSetArtwork(UIImage *image);+void SGRHarnessPlayFrom(NSInteger ms);++#pragma mark - Spotify's classes, by name++@interface _TtC19NowPlaying_ViewImpl24NowPlayingViewController : UIViewController @end+@implementation _TtC19NowPlaying_ViewImpl24NowPlayingViewController @end++@interface _TtC20NowPlaying_ModesImpl23InformationElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl23InformationElementsUnit @end++@interface _TtC20NowPlaying_ModesImpl19DurationElementUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl19DurationElementUnit @end++@interface _TtC20NowPlaying_ModesImpl20FloatingElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl20FloatingElementsUnit @end++@interface _TtC20NowPlaying_ModesImpl18FooterElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl18FooterElementsUnit @end++@interface _TtC21NowPlaying_ScrollImpl23NPVScrollViewController : UIViewController @end+@implementation _TtC21NowPlaying_ScrollImpl23NPVScrollViewController @end++@interface _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView : UICollectionView @end+@implementation _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView @end++@interface _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl : UIView @end+@implementation _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl @end++@interface _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView : UIView+- (void)handleTap;+@end+@implementation _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView+- (void)handleTap {}+@end++@interface _TtC22Lyrics_NPVContainerKit19LyricsContainerView : UIView @end+@implementation _TtC22Lyrics_NPVContainerKit19LyricsContainerView @end++@interface MockEncoreButton : UIControl @end+@implementation MockEncoreButton @end++#pragma mark - building the tree++static UIView *box(UIView *parent, Class cls, CGRect frame, NSString *identifier) {+ UIView *view = [[cls alloc] initWithFrame:frame];+ view.accessibilityIdentifier = identifier;+ [parent addSubview:view];+ return view;+}++static UILabel *marquee(UIView *parent, CGRect frame, NSString *text, CGFloat size, UIColor *color, NSString *identifier) {+ UIView *clip = box(parent, UIView.class, frame, identifier);+ clip.clipsToBounds = YES;+ UILabel *inner = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 900, frame.size.height)];+ inner.text = text;+ inner.font = [UIFont systemFontOfSize:size weight:UIFontWeightBold];+ inner.textColor = color;+ [inner sizeToFit];+ [clip addSubview:inner];+ return inner;+}++static UIView *glyphButton(UIView *parent, CGRect frame, NSString *symbol, NSString *identifier) {+ UIView *button = box(parent, MockEncoreButton.class, frame, identifier);+ UIImageView *glyph = [[UIImageView alloc] initWithFrame:CGRectInset(button.bounds, 10, 10)];+ glyph.image = [UIImage systemImageNamed:symbol];+ glyph.contentMode = UIViewContentModeScaleAspectFit;+ glyph.tintColor = UIColor.whiteColor;+ [button addSubview:glyph];+ return button;+}++static UIImage *artwork(void) {+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(354, 354)];+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *ctx) {+ CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();+ CGFloat components[] = {0.11, 0.06, 0.35, 1, 0.83, 0.15, 0.62, 1};+ CGGradientRef gradient = CGGradientCreateWithColorComponents(space, components, NULL, 2);+ CGContextDrawLinearGradient(ctx.CGContext, gradient, CGPointZero, CGPointMake(354, 354), 0);+ CGGradientRelease(gradient);+ CGColorSpaceRelease(space);+ [[UIColor colorWithWhite:1 alpha:0.9] set];+ [@"LOOSE\nCANON" drawAtPoint:CGPointMake(28, 28) withAttributes:@{+ NSFontAttributeName: [UIFont systemFontOfSize:44 weight:UIFontWeightHeavy],+ NSForegroundColorAttributeName: [UIColor colorWithRed:1 green:0.92 blue:0.2 alpha:1],+ }];+ }];+}++// A song with words timed inside each line, the shape SGRKaraokeView draws.+static void loadLyrics(void) {+ NSArray<NSString *> *texts = @[+ @"Who got the 808 under the 809",+ @"Making everybody jump?",+ @"Easy, I'm motivated",+ @"I got the feeling this is overrated",+ @"Give me the respect or give me nothing",+ @"Running up the hill with a heavy load",+ @"Tell them that the kid never folded",+ @"Every single verse was a promise kept",+ @"Nobody was there when it started",+ @"Now everybody wanna say they knew",+ ];+ NSMutableArray<SGKaraokeLine *> *lines = [NSMutableArray array];+ NSInteger at = 0;+ for (NSString *text in texts) {+ NSArray<NSString *> *words = [text componentsSeparatedByString:@" "];+ NSMutableArray<SGKaraokeWord *> *built = [NSMutableArray array];+ NSInteger cursor = at;+ for (NSString *word in words) {+ SGKaraokeWord *w = [SGKaraokeWord new];+ w.text = word;+ w.start = cursor;+ cursor += 260 + word.length * 40;+ w.end = cursor;+ [built addObject:w];+ }+ SGKaraokeLine *line = [SGKaraokeLine new];+ line.words = built;+ line.start = at;+ line.end = cursor;+ [lines addObject:line];+ at = cursor + 400;+ }+ SGKaraokeKeepLines(@"harness", lines);+}++#pragma mark - the harness++@interface SGRHarnessDelegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++@implementation SGRHarnessDelegate {+ NSArray<UIViewController *> *_units;+}++- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {+ loadLyrics();+ SGRHarnessPlayFrom(2400);+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ UIViewController *root = [UIViewController new];+ root.view.backgroundColor = [UIColor colorWithRed:0.09 green:0.07 blue:0.17 alpha:1];+ self.window.rootViewController = root;++ CGFloat W = root.view.bounds.size.width, H = root.view.bounds.size.height;+ // The player's own numbers are the tree's 402x874; the simulator's screen is whatever it is, so the+ // rows are placed as shares of it, the way Spotify's layout puts them.+ CGFloat headerTop = 62, headerHeight = 48;+ CGFloat bandTop = headerTop + headerHeight;+ CGFloat bottomHeight = 236 + 44; // the tree's rows plus a volume row, as the phone has it+ CGFloat bottomTop = H - bottomHeight - 61.33;+ CGFloat bandHeight = bottomTop - bandTop;+ CGFloat coverSide = MIN(354, W - 48);++ // NPVScrollViewController: the list the player is the header of.+ UIView *page = box(root.view, UIView.class, root.view.bounds, nil);+ UIScrollView *list = [[UIScrollView alloc] initWithFrame:page.bounds];+ list.accessibilityIdentifier = @"scrolling_npv_collection_view_accessibility_identifier";+ list.contentSize = CGSizeMake(W, H + 326); // the player and a card's worth of cards under it+ [page addSubview:list];+ UIViewController *scrollUnit = [_TtC21NowPlaying_ScrollImpl23NPVScrollViewController new];+ scrollUnit.view = page;++ UIView *host = box(list, UIView.class, CGRectMake(0, 0, W, H), @"SPTNowPlayingView");++ // the content layers: the sideways list of covers+ UIView *layers = box(host, UIView.class, host.bounds, nil);+ UICollectionViewFlowLayout *flow = [UICollectionViewFlowLayout new];+ UICollectionView *covers = [[_TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView alloc]+ initWithFrame:layers.bounds collectionViewLayout:flow];+ covers.accessibilityIdentifier = @"nowplaying-contentlayer-collectionview";+ covers.backgroundColor = UIColor.clearColor;+ [layers addSubview:covers];+ UIView *cell = box(covers, _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl.class, covers.bounds, @"nowplaying-contentlayer-cell-0");+ UIView *band = box(cell, UIView.class, CGRectMake(0, bandTop, W, bandHeight), nil);+ UIView *inner = box(band, UIView.class, CGRectMake(24, 8, W - 48, bandHeight - 16), nil);+ UIView *tilt = box(inner, _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView.class,+ CGRectMake(0, round((inner.bounds.size.height - coverSide) / 2), coverSide, coverSide), nil);+ tilt.accessibilityLabel = @"Inspect cover art";+ UIView *coverElement = box(tilt, UIView.class, tilt.bounds, nil);+ UIImage *picture = artwork();+ SGRHarnessSetArtwork(picture);+ UIImageView *cover = [[UIImageView alloc] initWithFrame:coverElement.bounds];+ cover.image = picture;+ cover.contentMode = UIViewContentModeScaleAspectFill;+ [coverElement addSubview:cover];+ box(inner, _TtC22Lyrics_NPVContainerKit19LyricsContainerView.class, CGRectMake(0, inner.bounds.size.height, coverSide, 0), nil);++ // the header row+ UIView *header = box(host, UIStackView.class, CGRectMake(0, headerTop, W, headerHeight), nil);+ glyphButton(header, CGRectMake(12, 0, 48, 48), @"chevron.down", @"now-playing-minimize-button");+ glyphButton(header, CGRectMake(W - 60, 0, 48, 48), @"ellipsis", @"Context menu");++ // the bottom stack: information, duration, controls, volume, footer+ UIView *bottom = box(host, UIStackView.class, CGRectMake(0, bottomTop, W, bottomHeight), @"npv.bottomStackView");++ UIView *floatingView = box(bottom, UIView.class, CGRectMake(0, -32, W, 32), nil);+ UIView *chip = box(floatingView, UIView.class, CGRectMake(24, 0, 148, 32), nil);+ chip.backgroundColor = [UIColor colorWithWhite:1 alpha:0.16];+ chip.layer.cornerRadius = 16;+ UILabel *chipLabel = [[UILabel alloc] initWithFrame:chip.bounds];+ chipLabel.text = @" \u25B6 Switch to video";+ chipLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];+ chipLabel.textColor = UIColor.whiteColor;+ [chip addSubview:chipLabel];++ UIView *infoView = box(bottom, UIView.class, CGRectMake(0, 0, W, 64), nil);+ UIView *infoRow = box(infoView, UIStackView.class, CGRectMake(12, 8, W - 24, 48), nil);+ UIView *infoInner = box(infoRow, UIStackView.class, infoRow.bounds, nil);+ box(infoInner, UIView.class, CGRectMake(0, 24, 0, 0), nil); // Spotify's own mini cover, unused+ box(infoInner, UIView.class, CGRectMake(0, 24, 12, 0), nil); // the spacer after it+ CGFloat titleWidth = infoInner.bounds.size.width - 12 - 60;+ UIView *titleElement = box(infoInner, UIView.class, CGRectMake(12, 2.33, titleWidth, 43.33), nil);+ UIView *titleContainer = box(titleElement, UIView.class, titleElement.bounds, nil);+ marquee(titleContainer, CGRectMake(0, 0, titleWidth, 25.33), @"We Are The People - southstar Remix (Extended)", 21,+ UIColor.whiteColor, @"now-playing-title-label");+ marquee(titleContainer, CGRectMake(0, 25.33, titleWidth, 18), @"Canon", 13,+ [UIColor colorWithWhite:1 alpha:0.7], @"now-playing-subtitle-label");+ glyphButton(infoInner, CGRectMake(infoInner.bounds.size.width - 48, 0, 48, 48), @"star", @"Components.UI.AddToButton");++ UIView *durationView = box(bottom, UIView.class, CGRectMake(0, 64, W, 40), nil);+ UIView *track = box(durationView, UIView.class, CGRectMake(24, 8, W - 48, 6), nil);+ track.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3];+ track.layer.cornerRadius = 3;+ UIView *played = box(track, UIView.class, CGRectMake(0, 0, (W - 48) * 0.22, 6), nil);+ played.backgroundColor = [UIColor colorWithWhite:1 alpha:0.85];+ played.layer.cornerRadius = 3;++ UIView *controls = box(bottom, UIView.class, CGRectMake(0, 104, W, 88), nil);+ glyphButton(controls, CGRectMake(W / 2 - 130, 20, 48, 48), @"backward.fill", nil);+ glyphButton(controls, CGRectMake(W / 2 - 24, 14, 48, 60), @"pause.fill", nil);+ glyphButton(controls, CGRectMake(W / 2 + 82, 20, 48, 48), @"forward.fill", nil);++ UIView *volume = box(bottom, UIView.class, CGRectMake(0, 192, W, 44), nil);+ UIView *volumeTrack = box(volume, UIView.class, CGRectMake(44, 19, W - 88, 6), nil);+ volumeTrack.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3];+ volumeTrack.layer.cornerRadius = 3;++ UIView *footerView = box(bottom, UIView.class, CGRectMake(0, 236, W, 44), nil);+ UIView *footerRow = box(footerView, UIStackView.class, CGRectMake(12, 0, W - 24, 44), nil);+ UIView *connect = box(footerRow, UIView.class, CGRectMake(0, 4, 153.67, 36), nil);+ UIView *connectHolder = box(connect, UIView.class, connect.bounds, @"Components.ConnectButtonOutputSwitcher");+ UIImageView *connectGlyph = [[UIImageView alloc] initWithFrame:CGRectMake(0, 8, 19, 19)];+ connectGlyph.image = [UIImage systemImageNamed:@"airpods.pro"];+ connectGlyph.tintColor = UIColor.whiteColor;+ [connectHolder addSubview:connectGlyph];+ glyphButton(footerRow, CGRectMake(279, 0, 44, 44), @"square.and.arrow.up", @"ShareButtonNowPlayingView");+ glyphButton(footerRow, CGRectMake(323, 6, 47, 32), @"list.bullet", @"QueueButtonNowPlaying");++ [self.window makeKeyAndVisible];++ UIViewController *info = [_TtC20NowPlaying_ModesImpl23InformationElementsUnit new];+ info.view = infoView;+ UIViewController *duration = [_TtC20NowPlaying_ModesImpl19DurationElementUnit new];+ duration.view = durationView;+ UIViewController *floating = [_TtC20NowPlaying_ModesImpl20FloatingElementsUnit new];+ floating.view = floatingView;+ UIViewController *footer = [_TtC20NowPlaying_ModesImpl18FooterElementsUnit new];+ footer.view = footerView;+ UIViewController *player = [_TtC19NowPlaying_ViewImpl24NowPlayingViewController new];+ player.view = host;+ _units = @[info, duration, floating, footer, scrollUnit, player];+ [self layOut];+ // Spotify lays its units out again as a track's elements arrive, which is what the redesign's+ // transforms and narrowed labels have to survive.+ [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer *t) { [self layOut]; }];++ NSLog(@"[harness] lyrics available: %d", SGRPlayerLyricsAvailable());+ // With the lines up, the row that rose into them must still be Spotify's to touch, and the lines+ // themselves must take the tap that seeks.+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ UIView *star = nil;+ for (UIView *v in infoInner.subviews) if ([v.accessibilityIdentifier isEqualToString:@"Components.UI.AddToButton"]) star = v;+ CGPoint onStar = [self.window convertPoint:CGPointMake(CGRectGetMidX(star.bounds), CGRectGetMidY(star.bounds)) fromView:star];+ CGPoint onTitle = [self.window convertPoint:CGPointMake(40, 12) fromView:titleElement];+ CGPoint onLines = CGPointMake(W / 2, H * 0.45);+ NSLog(@"[harness] hit on the star: %@", NSStringFromClass([self.window hitTest:onStar withEvent:nil].class));+ NSLog(@"[harness] hit on the title: %@", NSStringFromClass([self.window hitTest:onTitle withEvent:nil].class));+ NSLog(@"[harness] hit on the lines: %@", NSStringFromClass([self.window hitTest:onLines withEvent:nil].class));+ });+ // Opened, closed and opened again, so a screenshot can be taken of each state and of the move itself.+ 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(), ^{+ NSLog(@"[harness] %@ the lyrics", SGRPlayerLyricsOpen() ? @"closing" : @"opening");+ SGRPlayerToggleLyrics();+ });+ }+ return YES;+}++- (void)layOut {+ for (UIViewController *unit in _units) [unit viewDidLayoutSubviews];+}++@end++// Before every %ctor, so the redesign's gate reads on.+__attribute__((constructor(101))) static void sgr_harnessDefaults(void) {+ [NSUserDefaults.standardUserDefaults setBool:YES forKey:@"spotifyglass.redesign"];+}++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGRHarnessDelegate.class));+ }+}diff --git a/harness/player/stubs.m b/harness/player/stubs.mnew file mode 100644index 00000000..dd89b667--- /dev/null+++ b/harness/player/stubs.m@@ -0,0 +1,85 @@+// What the player harness does not compile: the Kit's hooks (SGRAccent.x, SGRRepaint.x, SGRBridges.x),+// the rest of the player's hooks, the lyrics store and the haptics. Everything here answers the way the+// phone would for one paused track with lyrics, so the redesign's own code is what is being looked at.+#import <UIKit/UIKit.h>+#import "Shared/Lyrics/Lyrics.h"+#import "Headers/SPTPlayer.h"++#pragma mark - SGRAccent.x, SGRRepaint.x++UIColor *SGRAccentColor(void) { return nil; }+__weak UIView *sgr_nowPlayingRoot = nil;+__weak UIView *sgr_nowPlayingCard = nil;+__weak UIView *sgr_lyricsPageRoot = nil;+__weak UIView *sgr_playlistRoot = nil;++#pragma mark - Shared/Player/PlayerEvents.x++NSString *const SGPlayerTransitionNotification = @"spotifyglass.playerTransition";+NSString *const SGPlayerTransitionEndedNotification = @"spotifyglass.playerTransitionEnded";+CFTimeInterval SGPlayerTransitionEnds(void) { return 0; }++#pragma mark - Redesigned/Kit/SGRBridges.x++NSNotificationName const SGRNowPlayingArtworkDidChangeNotification = @"spotifyglass.redesign.artwork";+static UIImage *sg_artwork;++NSString *SGRURIString(id uri) {+ if ([uri isKindOfClass:NSString.class]) return uri;+ if ([uri isKindOfClass:NSURL.class]) return ((NSURL *)uri).absoluteString;+ return nil;+}+void SGRAddPlayerStateObserver(id observer) {}+SPTPlayerState *SGRPlayerState(void) { return nil; }+void SGRSetNowPlayingArtwork(UIImage *image, NSString *trackURI, NSInteger quality) { sg_artwork = image; }+UIImage *SGRNowPlayingArtwork(NSString **trackURI, NSString **identity) {+ if (trackURI) *trackURI = @"spotify:track:harness";+ if (identity) *identity = @"harness";+ return sg_artwork;+}+void SGRHarnessSetArtwork(UIImage *image) { sg_artwork = image; }+BOOL SGRPlayerIsTransitioning(void) { return NO; }+void SGRObservePlayerTransition(id owner, void (^began)(id owner), void (^ended)(id owner)) {}++#pragma mark - Redesigned/Player/PlayerControls.x++void SGRPlayerVanish(UIView *view) {+ view.alpha = 0;+ view.userInteractionEnabled = NO;+ view.accessibilityElementsHidden = YES;+}++#pragma mark - Redesigned/Haptics++void SGRPlayFeedback(NSInteger feedback) {}+void SGRPrepareFeedback(NSInteger feedback) {}++#pragma mark - Shared/LyricsSources++NSString *SGLyricsCreditFor(NSString *trackID) { return @"the harness"; }++#pragma mark - Shared/Lyrics/KaraokeSource.x++static NSArray<SGKaraokeLine *> *sg_lines;+static NSString *sg_track = @"harness";+static NSInteger sg_position;+static CFTimeInterval sg_started;++NSString *SGKaraokePlayingTrack(void) { return sg_track; }+NSArray<SGKaraokeLine *> *SGKaraokeLinesForTrack(NSString *trackID) { return sg_lines; }+void SGKaraokeKeepLines(NSString *trackID, NSArray<SGKaraokeLine *> *lines) { sg_lines = lines; }+void SGKaraokeRequestLyrics(NSString *trackID) {}+id SGKaraokePlayer(void) { return nil; }+SPTPlayerTrack *SGKaraokeTrackFor(NSString *trackID) { return nil; }+void SGKaraokeRememberTrack(SPTPlayerTrack *track) {}++// The song runs on from the moment the harness started it, so the sweep is alive in a screenshot.+NSInteger SGKaraokePositionMs(void) {+ if (!sg_started) return sg_position;+ return sg_position + (NSInteger)((CACurrentMediaTime() - sg_started) * 1000);+}+void SGKaraokeSeek(NSInteger ms) {+ sg_position = ms;+ sg_started = CACurrentMediaTime();+}+void SGRHarnessPlayFrom(NSInteger ms) { SGKaraokeSeek(ms); }diff --git a/tweak/Sources/Redesigned/Kit/SGRGlyph.m b/tweak/Sources/Redesigned/Kit/SGRGlyph.mindex f81e1627..6bcb61c8 100644--- a/tweak/Sources/Redesigned/Kit/SGRGlyph.m+++ b/tweak/Sources/Redesigned/Kit/SGRGlyph.m@@ -57,7 +57,10 @@ static const CGFloat kMinTouch = 44, kPressAlpha = 0.5, kPressScale = 0.9, kDisabutton.largeContentTitle = accessibilityTitle;button.largeContentImage = button->_glyph.image;[button addInteraction:[UILargeContentViewerInteraction new]];- [button addTarget:button action:@selector(tapped) forControlEvents:UIControlEventPrimaryActionTriggered];+ // Touch up inside, not the primary action: UIKit sends the primary action from UIButton and the+ // controls built on it, never from a UIControl of one's own, so a handler registered for it is never+ // called and the button is dead to every tap (device, 2026-09-17, and the player harness).+ [button addTarget:button action:@selector(tapped) forControlEvents:UIControlEventTouchUpInside];return button;}@@ -69,6 +72,13 @@ static const CGFloat kMinTouch = 44, kPressAlpha = 0.5, kPressScale = 0.9, kDisaif (self.onTap) self.onTap();}+// VoiceOver's double tap, which reaches a UIControl of one's own no other way.+- (BOOL)accessibilityActivate {+ if (!self.enabled) return NO;+ [self tapped];+ return YES;+}+- (CGSize)intrinsicContentSize {CGSize glyph = _glyph.intrinsicContentSize;return CGSizeMake(MAX(kMinTouch, glyph.width), MAX(kMinTouch, glyph.height));diff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.h b/tweak/Sources/Redesigned/Kit/SGRRepaint.hindex 533f1270..70a9df01 100644--- a/tweak/Sources/Redesigned/Kit/SGRRepaint.h+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.h@@ -4,5 +4,4 @@extern __weak UIView *sgr_nowPlayingRoot; // Redesigned/NowPlayingBar/NowPlayingBar.x, the barextern __weak UIView *sgr_nowPlayingCard; // the bar's painted card, learnt from the album-colour paint-extern __weak UIView *sgr_lyricsCardRoot; // Redesigned/Player/PlayerCards.x, the cell of the lyrics cardextern __weak UIView *sgr_lyricsPageRoot; // Redesigned/Lyrics/LyricsPage.xdiff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.x b/tweak/Sources/Redesigned/Kit/SGRRepaint.xindex bda641e7..afd4d3f0 100644--- a/tweak/Sources/Redesigned/Kit/SGRRepaint.x+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.x@@ -5,12 +5,11 @@__weak UIView *sgr_nowPlayingRoot = nil;__weak UIView *sgr_nowPlayingCard = nil;-__weak UIView *sgr_lyricsCardRoot = nil;__weak UIView *sgr_lyricsPageRoot = nil;%hook CALayer- (void)setBackgroundColor:(CGColorRef)color {- if (color && (sgr_nowPlayingRoot || sgr_lyricsCardRoot || sgr_lyricsPageRoot)) {+ if (color && (sgr_nowPlayingRoot || sgr_lyricsPageRoot)) {UIView *view = (UIView *)self.delegate;if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {if (SGIsInside(view, sgr_nowPlayingRoot)) {@@ -20,7 +19,7 @@ __weak UIView *sgr_lyricsPageRoot = nil;dispatch_async(dispatch_get_main_queue(), ^{ [bar.superview setNeedsLayout]; });}color = NULL;- } else if (SGIsInside(view, sgr_lyricsCardRoot) || SGIsInside(view, sgr_lyricsPageRoot)) {+ } else if (SGIsInside(view, sgr_lyricsPageRoot)) {color = NULL;}}diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.hindex 1599a577..4bff6a04 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h@@ -1,14 +1,14 @@// The redesign's Apple Music style lyrics view, always on, over Spotify's full screen lyrics page-// (KaraokePage.x) and, compact, over the card under the redesigned player (Redesigned/Player/KaraokeCard.x).-// A track without synced lyrics keeps Spotify's own lines. The lines and the clock are-// Shared/Lyrics/Lyrics.h's.+// (KaraokePage.x) and in the redesigned player itself (Redesigned/Player/PlayerLyrics.x). A track+// without synced lyrics keeps Spotify's own lines, where there are any next to it. The lines and the+// clock are Shared/Lyrics/Lyrics.h's.+//+// It takes the whole of whatever it is put in and dims every other view in there while it has lines+// to show, so a host it shares with anything else needs a view of its own for it.#import <UIKit/UIKit.h>#import "Shared/Lyrics/Lyrics.h"@interface SGRKaraokeView : UIView-// Compact is the card under the player: Spotify's own type size, no seeking by tap and no margin of-// its own, since the card already insets what it holds. initWithFrame: is the full screen page.-- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact;// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.- (void)syncSiblings;@enddiff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mindex 16e3a9b1..27636aea 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -7,10 +7,6 @@#import "Redesigned/Haptics/Haptics.h"static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;-// The card under the player is a seventh of the page's height, so it gets Spotify's own card type-// size and the spacing its rows sit on, and no blur: at that size the dimming does the work, and a-// blur filter on every line in sight, under the card's glass, made the player stutter as it opened.-static const CGFloat kCardFontSize = 21, kCardMargin = 0, kCardLineGap = 16;static const CGFloat kDimAlpha = 0.3, kFillEdge = 22, kLift = 2.5, kDimScale = 0.97;static const CGFloat kAnchor = 0.28; // where the sung line rests, as a share of the heightstatic const CGFloat kEdgeFade = 0.1; // the lines fade out over this share at the top and bottom@@ -23,10 +19,9 @@ static const NSTimeInterval kBrowseHold = 3; // after scrolling by hand, how lstatic const double kFloatMinMs = 700, kFloatLeadMs = 80; // a short word still floats up this slowlystatic const double kClockSnapMs = 250, kClockPull = 0.08;// Lines get views this far outside the visible part, in screen heights: half a screen above it-// and below, and a quarter more before a view is let go. The card under the player is in the tree-// for every open and close of the player, and every view it holds is one more for the window to-// take in and let go; a line comes into view about once in three seconds, and a page flung by-// hand fills in at a few lines a frame.+// and below, and a quarter more before a view is let go. Every view held is one more for the window+// to take in and let go when the lyrics come up; a line comes into view about once in three seconds,+// and a page flung by hand fills in at a few lines a frame.static const CGFloat kSightBehind = 0.5, kSightAhead = 0.5, kSightSlack = 0.25;static const NSTimeInterval kTransitionSlack = 0.05; // after the player's animation, before the link is backstatic NSString *const kBlurPath = @"filters.gaussianBlur.inputRadius";@@ -371,7 +366,6 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {CAGradientLayer *_fade;UILabel *_credit;CGFloat _fontSize, _margin, _lineGap, _blurPerLine, _maxBlur;- BOOL _compact;BOOL _crediting; // the switch is read once: the page asks for the source on every frame until it has onedouble _clock;NSInteger _reported;@@ -379,20 +373,15 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {}- (instancetype)initWithFrame:(CGRect)frame {- return [self initWithFrame:frame compact:NO];-}--- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact {self = [super initWithFrame:frame];if (!self) return nil;self.hidden = YES;_active = -1;- _compact = compact;- _fontSize = compact ? kCardFontSize : kFontSize;- _margin = compact ? kCardMargin : kMargin;- _lineGap = compact ? kCardLineGap : kLineGap;- _blurPerLine = compact ? 0 : kBlurPerLine;- _maxBlur = compact ? 0 : kMaxBlur;+ _fontSize = kFontSize;+ _margin = kMargin;+ _lineGap = kLineGap;+ _blurPerLine = kBlurPerLine;+ _maxBlur = kMaxBlur;_shown = [NSMutableDictionary dictionary];_sightActive = -2;_fade = [CAGradientLayer layer];@@ -412,11 +401,9 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {_credit.font = [UIFont systemFontOfSize:kCreditSize weight:UIFontWeightSemibold];_credit.textColor = [UIColor colorWithWhite:1 alpha:kCreditAlpha];_credit.hidden = YES;- _crediting = !compact && SGFlag(SGKeyLyricsCredit, NO); // the card has no room to name a source+ _crediting = SGFlag(SGKeyLyricsCredit, NO);[self addSubview:_credit];- // A tap on the card is Spotify's, and opens the full screen page; seeking by tap is the page's.- if (compact) self.userInteractionEnabled = NO;- else [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];+ [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionNotification object:nil];[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionEndedNotification object:nil];return self;@@ -482,8 +469,8 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {// for 30 to 60, the range Apple's ProMotion guide says Core Animation gives priority to, those// animations ran rough; the player and the lyrics themselves were smooth throughout. The card's// link now asks for 60 but takes 120, and is put down for as long as the player animates, which-// NowPlayingBar.x announces as each animation starts and again as it ends; the card holds still-// under it, where nobody sees it. The timer is for an end that is never announced.+// NowPlayingBar.x announces as each animation starts and again as it ends. The timer is for an end+// that is never announced.- (void)scheduleLink {[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startLink) object:nil];[_link invalidate];@@ -497,9 +484,7 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {- (void)startLink {if (!self.window || _link) return;_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick)];- // The card stays in the window behind the full screen page, so both sweep at once; the card is- // a few lines tall and is content with 60, the page keeps the high refresh rate.- _link.preferredFrameRateRange = _compact ? CAFrameRateRangeMake(30, 120, 60) : CAFrameRateRangeMake(80, 120, 120);+ _link.preferredFrameRateRange = CAFrameRateRangeMake(80, 120, 120);[_link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];}diff --git a/tweak/Sources/Redesigned/Player/KaraokeCard.x b/tweak/Sources/Redesigned/Player/KaraokeCard.xdeleted file mode 100644index f461f451..00000000--- a/tweak/Sources/Redesigned/Player/KaraokeCard.x+++ /dev/null@@ -1,43 +0,0 @@-// The same Apple Music style lyrics on the card under the player, so the card sweeps word by word-// rather than scrolling whole lines while the page it expands into sweeps. It is the page's view in-// compact: the card is a seventh of the height, so it takes Spotify's own type size and spacing.-//-// The host is Lyrics_CardElementImpl.CardContentView, the card's own content view. The table inside-// it, Lyrics_TextElementImpl.LyricsTextView, is the wrong thing to hook: the full screen page is-// built from that same class, and KaraokePage.x is already over it there. CardContentView belongs-// to the card alone, and is still in the tree while the page is open, behind it.-//-// The view is laid over rather than swapped in, as on the page: Spotify's table keeps running-// underneath and comes back the moment a track has no synced lyrics. It takes no touches, so the-// tap that opens the full screen page is still Spotify's to answer.-#import "Core/SGCore.h"-#import "Redesigned/Lyrics/SGRKaraokeView.h"--// Below this the card is collapsed, by PlayerCards.x or while it is still being laid out.-static const CGFloat kLivingHeight = 40;--static char kKaraokeKey;--%hook _TtC22Lyrics_CardElementImpl15CardContentView-- (void)layoutSubviews {- %orig;- UIView *host = (UIView *)self;- if (host.bounds.size.height < kLivingHeight) return;- SGRKaraokeView *view = objc_getAssociatedObject(host, &kKaraokeKey);- if (!view) {- SGLog(@"karaoke: card laid out, playing %@", SGKaraokePlayingTrack());- view = [[SGRKaraokeView alloc] initWithFrame:host.bounds compact:YES];- objc_setAssociatedObject(host, &kKaraokeKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- }- if (view.superview == host) [host bringSubviewToFront:view];- else [host addSubview:view];- view.frame = host.bounds;- [view syncSiblings];-}-%end--%ctor {- if (!SGRedesignedUI()) return;- %init;- SGRequireClasses(@[@"_TtC22Lyrics_CardElementImpl15CardContentView"]);-}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 44d61e34..2598a77a 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -1,16 +1,18 @@// The player redesign (screen key "player"): Spotify's full screen player kept, with its controller,// units, controls and card list, and restyled from the Kit. Every control stays Spotify's own, so its// action, state and accessibility do too; the redesign adds the artwork field behind it, glass behind-// the header buttons, bare glyphs for previous, play and next, a lyrics glyph in the-// footer, and collapses every card under the player except lyrics.+// the header buttons, bare glyphs for previous, play and next, a lyrics glyph in the footer, and one+// screen with nothing under it: every card is collapsed and the player does not scroll. The lyrics+// come to the player itself, the way the Music app shows them, when the lyrics glyph is tapped.//// PlayerField.x the switch's flags and rows, the field in the background plane, the cover it reads// PlayerArtwork.x the cover's corners, shadow and paused shrink, the lyric preview under it hidden// PlayerHeader.x glass behind the close and more buttons// PlayerControls.x previous, play and next as bare glyphs, monospaced times// PlayerFooter.x share gone, lyrics, Connect and queue as one row of three glyphs-// PlayerCards.x the lyrics card kept, clear on the field, every other card collapsed-// KaraokeCard.x Apple Music style lyrics on that card+// PlayerCards.x every card under the player collapsed, so the list closes up+// PlayerScroll.x the list pinned to the top, so the player is one screen and cannot be scrolled+// PlayerLyrics.x the lyrics in the player: the cover as a thumbnail, the title up beside it// PlayerGestures.x the gestures' hookup//// Every hook installs only while Redesigned UI is on (SGRedesignedUI); the native look's do not then.@@ -22,10 +24,28 @@// The field behind the player, nil until the player has laid out once (PlayerField.x).SGRArtworkField *SGRPlayerField(void);-// The lyrics card under the player while it is in a window, else nil (PlayerCards.x).-UIView *SGRPlayerLyricsCard(void);-// Called by PlayerCards.x when the card comes or goes, so the footer's lyrics glyph follows (PlayerFooter.x).-void SGRPlayerLyricsCardChanged(void);+#pragma mark - the cover (PlayerArtwork.x)++// The sideways list of covers behind the player, nil until one has laid out.+UIView *SGRPlayerCoverList(void);+// The cover on screen as it is drawn, its paused shrink included, in `host`'s coordinates; CGRectNull+// when no cover has laid out.+CGRect SGRPlayerCoverFrameIn(UIView *host);+// The band that cover sits in -- the room the player gives its artwork, between the header row and the+// title -- in `host`'s coordinates; CGRectNull when no cover has laid out.+CGRect SGRPlayerArtworkAreaIn(UIView *host);++#pragma mark - the lyrics in the player (PlayerLyrics.x)++// Whether the playing track has lyrics the player can show.+BOOL SGRPlayerLyricsAvailable(void);+// Whether the player is showing them.+BOOL SGRPlayerLyricsOpen(void);+// Shows them, or puts the cover back; does nothing when there are none to show.+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);// 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/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.xindex bbc26436..b386e525 100644--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x@@ -61,6 +61,48 @@ static void scaleCover(UIView *tilt, CGFloat scale) {plate.transform = transform;}+#pragma mark - where the cover is++// The tilt view of the cover on screen: the queue is a cover per cell and the cells out of view are+// kept hidden (player/02.txt:521), so the one showing is the one in a window with nothing hidden over it.+static UIView *showingTilt(void) {+ for (UIView *tilt in sg_tilts) {+ if (!tilt.window) continue;+ BOOL hidden = NO;+ for (UIView *v = tilt; v && !hidden; v = v.superview) hidden = v.hidden;+ if (!hidden) return tilt;+ }+ return nil;+}++UIView *SGRPlayerCoverList(void) {+ for (UIView *v = showingTilt(); v; v = v.superview) {+ if ([v isKindOfClass:UICollectionView.class]) return v;+ }+ return nil;+}++CGRect SGRPlayerCoverFrameIn(UIView *host) {+ UIView *tilt = showingTilt();+ UIView *cover = coverIn(tilt);+ // The cover's own transform is the paused shrink, which is what the eye sees it at.+ return cover && host ? [host convertRect:cover.bounds fromView:cover] : CGRectNull;+}++CGRect SGRPlayerArtworkAreaIn(UIView *host) {+ UIView *tilt = showingTilt();+ if (!tilt || !host) return CGRectNull;+ // The band is the first view over the cover as wide as the player: the cover sits inset inside it+ // (01.txt:33-36, CoverArtCellImpl > UIView {0, 110, 402, 466.67} > UIView {24, 8, ...} > the tilt view).+ for (UIView *v = tilt.superview; v; v = v.superview) {+ if (v == host) break;+ if (v.bounds.size.width >= host.bounds.size.width - 1) return [host convertRect:v.bounds fromView:v];+ }+ return CGRectNull;+}++#pragma mark - the paused shrink+static void scaleEveryCover(BOOL animated) {CGFloat scale = currentScale();NSArray<UIView *> *tilts = sg_tilts.allObjects;diff --git a/tweak/Sources/Redesigned/Player/PlayerCards.x b/tweak/Sources/Redesigned/Player/PlayerCards.xindex b729d71e..8b01a5f1 100644--- a/tweak/Sources/Redesigned/Player/PlayerCards.x+++ b/tweak/Sources/Redesigned/Player/PlayerCards.x@@ -1,45 +1,22 @@-// Player redesign: of the cards under the player only lyrics is kept, with no card of its own: the Apple-// Music style lines sit straight on the field, with no edge where the card was;-// every other card (about the artist, videos, SongDNA, events, explore, credits, merch, anything Spotify-// adds later) reports no height, so the list closes up around it.+// Player redesign: nothing is kept under the player. Every card (about the artist, videos, SongDNA,+// events, explore, credits, merch, the lyrics card, anything Spotify adds later) reports no height, so+// the list closes up around it and the player is one screen; PlayerScroll.x closes off the gaps the+// list leaves between them, and the lyrics come to the player itself (PlayerLyrics.x) instead of+// waiting on a card below it.//-// An allow list rather than Declutter's block list: the server decides which cards a track gets, and a-// new kind should not turn up under a redesigned player. The collapse is the one Native/Player/PlayerDeclutter.x-// has shipped (the 24pt gaps between cards stay until the card list is filtered at the network, phase 2).+// A block on everything rather than a list of what to drop: the server decides which cards a track+// gets, and a new kind should not turn up under a redesigned player. The collapse is the one+// Native/Player/PlayerDeclutter.x has shipped.//// Tree (trees/clean/player/01.txt:385, lyrics/01.txt:996-999): every card is an Element_List.CollectionViewCell// whose first subview is an ElementContentView naming NowPlaying_ScrollAPI, then an ElementView, then-// the card's own root: Lyrics_CardElementImpl.CardView id=lyrics-card-view for lyrics,-// CreatorBiographyCardLayout, song-dna-npv-card and so on for the rest (all ten player snapshots). The-// cells of lists inside a card (WatchFeed's) name WatchFeed_ComponentAPI instead, so they are left to-// their card. The card's share button is id=lyrics-share-button (lyrics/01.txt:1009).+// the card's own root: CreatorBiographyCardLayout, song-dna-npv-card, Lyrics_CardElementImpl.CardView+// id=lyrics-card-view and so on (all ten player snapshots). The cells of lists inside a card+// (WatchFeed's) name WatchFeed_ComponentAPI instead, so they are left to their card.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"-#import "Redesigned/Kit/SGRRepaint.h"#import "Player.h"-// Below this a cell is collapsed, or still being laid out.-static const CGFloat kLivingHeight = 40;--static char kShareKey, kRevalidatedKey;-static __weak UIView *sg_lyricsCard;--// In a window and not in a hidden cell: the list keeps the cells it has put aside for reuse in it, hidden-// (player/02.txt:521), each with the card it last held.-static BOOL showing(UIView *card) {- if (!card.window) return NO;- for (UIView *v = card; v; v = v.superview) {- if (v.hidden) return NO;- if ([v isKindOfClass:UICollectionView.class]) break;- }- return YES;-}--UIView *SGRPlayerLyricsCard(void) {- UIView *card = sg_lyricsCard;- return showing(card) ? card : nil;-}-// Whether the cell's content is the player's card list, remembered per content class.static BOOL isPlayerCard(UIView *content) {static NSMutableSet<Class> *yes, *no;@@ -55,34 +32,18 @@ static BOOL isPlayerCard(UIView *content) {return player;}-static Class cardViewClass(void) {- static Class cls;- if (!cls) cls = NSClassFromString(@"_TtC22Lyrics_CardElementImpl8CardView");- return cls;-}--static UIView *cellAround(UIView *view) {- static Class cell;- if (!cell) cell = NSClassFromString(@"_TtC12Element_List18CollectionViewCell");- for (UIView *v = view.superview; v; v = v.superview) {- if ([v isKindOfClass:cell]) return v;- }- return nil;-}-%hook _TtC12Element_List18CollectionViewCell- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)attributes {UICollectionViewLayoutAttributes *result = %orig;UIView *cell = (UIView *)self;UIView *content = cell.subviews.firstObject;if (!content || !isPlayerCard(content)) return result;- UIView *root = content.subviews.firstObject.subviews.firstObject;- if ([root isKindOfClass:cardViewClass()]) return result;result.size = CGSizeMake(result.size.width, 0);cell.clipsToBounds = YES;static NSMutableSet<NSString *> *logged;if (!logged) logged = [NSMutableSet set];+ UIView *root = content.subviews.firstObject.subviews.firstObject;NSString *name = root ? NSStringFromClass(root.class) : @"nothing yet";if (![logged containsObject:name]) {[logged addObject:name];@@ -92,81 +53,8 @@ static UIView *cellAround(UIView *view) {}%end-%hook _TtC22Lyrics_CardElementImpl8CardView-- (void)layoutSubviews {- %orig;- UIView *card = (UIView *)self;- UIView *cell = cellAround(card);- if (!cell || !isPlayerCard(cell.subviews.firstObject)) return;- // A card in a cell put aside never replaces one showing; a cell taken back from reuse keeps its card,- // so the glyph is told on every pass (it returns at once when nothing changed).- if (sg_lyricsCard != card && (showing(card) || !showing(sg_lyricsCard))) sg_lyricsCard = card;- SGRPlayerLyricsCardChanged();-- UIView *share = SGRFindByIdentifier(card, @"lyrics-share-button", &kShareKey);- SGRPlayerVanish(share);-- if (cell.bounds.size.height >= kLivingHeight) {- objc_setAssociatedObject(cell, &kRevalidatedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- // Spotify paints the cell the album colour again at every track change, which is no layout pass- // of the card's; as the root of the lyrics card, Redesigned/Kit/SGRRepaint.x keeps it clear in between.- // Spotify draws the lines still to come in black for that colour (lyrics/01.txt:1054); the Apple- // Music style lyrics drawn over them (KaraokeCard.x) are what read on the field.- sgr_lyricsCardRoot = cell;- SGStripBackgrounds(cell);- static dispatch_once_t once;- dispatch_once(&once, ^{ SGLog(@"redesign player: lyrics card cleared onto the field"); });- return;- }- // Sized before its card was in it, so it was collapsed as an unknown card: the list is asked once to- // size it again, and not again until it has been seen at its height.- if (objc_getAssociatedObject(cell, &kRevalidatedKey)) return;- UICollectionView *list = (UICollectionView *)cell.superview;- NSIndexPath *path = [list isKindOfClass:UICollectionView.class] ? [list indexPathForCell:(UICollectionViewCell *)cell] : nil;- if (!path) return;- objc_setAssociatedObject(cell, &kRevalidatedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- UICollectionViewLayoutInvalidationContext *context = [[list.collectionViewLayout.class invalidationContextClass] new];- [context invalidateItemsAtIndexPaths:@[path]];- [list.collectionViewLayout invalidateLayoutWithContext:context];- SGLog(@"redesign player: lyrics cell sized again at %@", path);-}--- (void)didMoveToWindow {- %orig;- if ((UIView *)self == sg_lyricsCard) SGRPlayerLyricsCardChanged();-}-%end--// A track without lyrics puts the card's cell aside without laying the card out or taking it out of-// the window, so the footer's glyph looks again while the next track's cards come in (the player-// waits up to 5 s for them).-@interface SGRPlayerCardsWatcher : NSObject <SGRPlayerStateObserver>-@end--@implementation SGRPlayerCardsWatcher {- NSString *_track;-}--- (void)playerStateDidChange:(SPTPlayerState *)state {- NSString *track = SGRURIString(state.track.URI);- if (!track || [track isEqualToString:_track]) return;- _track = track;- for (NSNumber *delay in @[@1, @3, @6]) {- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ SGRPlayerLyricsCardChanged(); });- }-}--@end--static SGRPlayerCardsWatcher *sg_cardsWatcher;-%ctor {if (!SGRedesignedUI()) return;%init;- sg_cardsWatcher = [SGRPlayerCardsWatcher new];- SGRAddPlayerStateObserver(sg_cardsWatcher);- SGRequireClasses(@[- @"_TtC12Element_List18CollectionViewCell",- @"_TtC22Lyrics_CardElementImpl8CardView",- ]);+ SGRequireClasses(@[@"_TtC12Element_List18CollectionViewCell"]);}diff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.xindex 799b5cf5..338e042a 100644--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x@@ -6,26 +6,27 @@// tint, the Jam avatars) and are only moved, by a translation of the arranged view that holds each: a// transform survives the stack view laying them out again, and moving the holder keeps its touches// inside its own bounds. The device name goes transparent, since the glyph alone sits in the middle.-// Spotify has no lyrics control down here, so that one is the Kit's glyph button, which fires the-// lyrics card's own expand button, or opens spotify:lyrics:fullscreen when there is no card.+// Spotify has no lyrics control down here, so that one is the Kit's glyph button, and it turns the+// lyrics in the player on and off (PlayerLyrics.x): filled while they are up, dimmed and dead for a+// track that has none.//// Tree (trees/clean/player/01.txt:295-320): FooterElementsUnit's view 402x44 > UIStackView 382x44 >// ElementView > ConnectButtonOutputSwitcherViewHolder id=Components.ConnectButtonOutputSwitcher 153x36// (a 19x19 UIImageView glyph and a MarqueeLabel with the device name), a spacer, a hidden media trimmer,// ElementView > EncoreButton id=ShareButtonNowPlayingView 44x44, ElementView > Queue control-// id=QueueButtonNowPlaying 47x32. The card's button is id=lyrics-expand-button, an EncoreButton, which-// is a UIButton (trees/clean/lyrics/01.txt:1013, objc-meta-Spotify.txt:216095).+// id=QueueButtonNowPlaying 47x32.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"-#import "Shared/Navigation/Links.h"#import "Player.h"static const CGFloat kLyricsGlyphSize = 20;+// Filled and at full strength while the lyrics are up, the way the Music app marks the control that is on.+static NSString *const kLyricsSymbol = @"quote.bubble", *const kLyricsSymbolOpen = @"quote.bubble.fill";// Where the three glyphs sit, as parts of the footer's width.static const CGFloat kLeading = 0.2, kMiddle = 0.5, kTrailing = 0.8;static const CGFloat kGlyphMaxWidth = 30;-static char kConnectKey, kShareKey, kTrimmerKey, kQueueKey, kLyricsGlyphKey, kExpandKey;+static char kConnectKey, kShareKey, kTrimmerKey, kQueueKey, kLyricsGlyphKey;static __weak SGRGlyphButton *sg_lyricsGlyph;// The view the footer's stack view arranges around `view`.@@ -53,31 +54,30 @@ static CGFloat moveTo(UIView *arranged, UIView *view, CGPoint point, UIView *hos#pragma mark - lyrics-static void openLyrics(void) {- UIView *card = SGRPlayerLyricsCard();- UIControl *expand = (UIControl *)SGRFindByIdentifier(card, @"lyrics-expand-button", &kExpandKey);- NSString *how = @"nothing";- if ([expand isKindOfClass:UIControl.class] && SGRFire(expand)) how = @"the card's expand button";- else if (SGOpenSpotifyURI([NSURL URLWithString:@"spotify:lyrics:fullscreen"])) how = @"spotify:lyrics:fullscreen";- SGLog(@"redesign player: lyrics glyph opened the page by %@", how);-}--void SGRPlayerLyricsCardChanged(void) {+void SGRPlayerLyricsChanged(void) {SGRGlyphButton *glyph = sg_lyricsGlyph;- BOOL enabled = SGRPlayerLyricsCard() != nil;- if (!glyph || glyph.enabled == enabled) return;- // The card turns up once the player has fetched it, well after the footer laid out: a fade, not a- // pop. While the player opens or closes the two come and go together, so nothing is animated then.- if (!glyph.window || SGRPlayerIsTransitioning()) glyph.enabled = enabled;- else SGRAnimate(SGRMotionFade, ^{ glyph.enabled = enabled; }, nil);+ if (!glyph) return;+ BOOL enabled = SGRPlayerLyricsAvailable() || SGRPlayerLyricsOpen(), open = SGRPlayerLyricsOpen();+ BOOL wasOpen = [glyph.glyph.symbol isEqualToString:kLyricsSymbolOpen];+ if (glyph.enabled == enabled && wasOpen == open) return;+ // Lyrics turn up once the player has fetched them, well after the footer laid out: a fade, not a pop.+ // While the player opens or closes the glyph and the lyrics come and go together, so nothing animates.+ BOOL animated = glyph.window && !SGRPlayerIsTransitioning();+ [glyph.glyph setSymbol:open ? kLyricsSymbolOpen : kLyricsSymbol animated:animated];+ void (^mark)(void) = ^{+ glyph.enabled = enabled;+ glyph.glyph.tintColor = open ? SGRPrimary() : SGRSecondary();+ };+ if (animated) SGRAnimate(SGRMotionFade, mark, nil);+ else mark();}static SGRGlyphButton *lyricsGlyphIn(UIView *host) {SGRGlyphButton *glyph = objc_getAssociatedObject(host, &kLyricsGlyphKey);if (!glyph) {- glyph = [SGRGlyphButton buttonWithSymbol:@"quote.bubble" pointSize:kLyricsGlyphSize title:@"Lyrics"];+ glyph = [SGRGlyphButton buttonWithSymbol:kLyricsSymbol pointSize:kLyricsGlyphSize title:@"Lyrics"];glyph.glyph.tintColor = SGRSecondary();- glyph.onTap = ^{ openLyrics(); };+ glyph.onTap = ^{ SGRPlayerToggleLyrics(); };objc_setAssociatedObject(host, &kLyricsGlyphKey, glyph, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}if (glyph.superview != host) [host addSubview:glyph];@@ -117,7 +117,7 @@ static UIView *connectGlyphIn(UIView *holder) {SGRGlyphButton *lyrics = lyricsGlyphIn(host);lyrics.bounds = CGRectMake(0, 0, 44, 44);lyrics.center = CGPointMake(round(width * (rtl ? kTrailing : kLeading)), middleY);- SGRPlayerLyricsCardChanged();+ SGRPlayerLyricsChanged();UIView *connect = SGRFindByIdentifier(host, @"Components.ConnectButtonOutputSwitcher", &kConnectKey);UIView *glyph = connectGlyphIn(connect);diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xnew file mode 100644index 00000000..2de4571f--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -0,0 +1,489 @@+// Player redesign: the lyrics come to the player itself, the way the Music app shows them. The player+// is one screen and does not scroll (PlayerScroll.x), so the footer's lyrics glyph is the only way to+// them: it shrinks the cover into a thumbnail at the top of the artwork band, lifts the track's title+// up beside it, and fades the Apple Music style lines (Redesigned/Lyrics/SGRKaraokeView.h) into the+// room that frees between the title and the progress bar. Tapping it again puts the cover back.+//+// Nothing of Spotify's is taken apart for it. The cover is the Kit's now playing artwork drawn again+// in a view of the redesign's own, flown from where Spotify's cover is drawn to where the thumbnail+// belongs, while Spotify's list of covers goes to alpha 0 underneath: one view to move instead of a+// paging list of them, and the two pictures are the same one, so the swap is not seen. The title row+// is Spotify's own unit translated, the way PlayerFooter.x moves the footer's controls -- a transform+// survives the stack view laying its arranged views out again -- with a mask over it where the controls+// it moved towards begin, so a long title fades out before them instead of running under them. The row+// of chips over it (Switch to video) goes while the lines are up, since they take the room it sits in.+//+// Tree (trees/clean/player/01.txt): SPTNowPlayingView (:26) holds the content layers, the header row+// (:91), and id=npv.bottomStackView {0, 576.67, 402, 236} (:127) whose arranged views are the+// information unit {0, 0, 402, 64} (:160, the title, the artist and the add button), the duration unit+// {0, 64, 402, 40} (:209), the controls (:240) and the footer (:295). The title is+// id=now-playing-title-label and the artist id=now-playing-subtitle-label (:174, :185), both inside one+// arranged element view {12, 2.33, 304, 43.33} of the unit's row. Every measurement here is taken from+// the views themselves, since a player with a volume row or another mode's units has other numbers.+//+// The geometry is re-applied on every layout pass of the units, since a new track rebuilds the+// elements inside them, and it is undone before the player closes: the bar morphs back into a full+// size cover, which a thumbnail would not match.+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Redesigned/Lyrics/SGRKaraokeView.h"+#import "Shared/Lyrics/Lyrics.h"+#import "Player.h"++static const CGFloat kThumbSide = 72; // the cover once the lyrics are up+static const CGFloat kThumbGap = 16; // between the thumbnail and the title beside it+static const CGFloat kTitleGap = 12; // between the title and the controls at the trailing edge+static const CGFloat kTitleFade = 20; // over how much of its end a title too long to fit fades out+static const CGFloat kThumbTop = 8; // below the top of the artwork band+static const CGFloat kLyricsTop = 20; // between the title row and the first line+static const CGFloat kLyricsBottom = 8; // above the progress bar+// The lines are a surface arriving, not something moving: they come up from just under full size as the+// room for them opens, and go at once when it closes. An exit the eye waits through reads as a stall.+static const CGFloat kLyricsEnterScale = 0.96;+static const NSTimeInterval kLyricsIn = 0.3, kLyricsInDelay = 0.12, kLyricsOut = 0.16;+// A track that changes while the lines are up has this long to bring its own before they are put away.+static const NSTimeInterval kLyricsGrace = 3;+// Below this the player has not laid out yet and nothing can be measured from it.+static const CGFloat kLivingHeight = 200;++static char kOverlayKey, kPlateKey, kTitleKey;+static BOOL sg_open;+static BOOL sg_moving; // the transition is in flight, so no layout pass may re-place it+static __weak UIView *sg_host; // SPTNowPlayingView+static __weak UIViewController *sg_info, *sg_duration, *sg_floating;+static __weak UIView *sg_titleElement; // the arranged element view holding the title and the artist++#pragma mark - the overlay++// The thumbnail and the lines, side by side under one view so the lines' own view has no sibling of+// ours to hide: SGRKaraokeView takes the whole of whatever it is put in and dims what is next to it.+@interface SGRPlayerLyricsOverlay : UIView+@property (nonatomic, readonly) UIView *thumb; // the cover, at full size, moved by its transform+@property (nonatomic, readonly) UIImageView *cover;+@property (nonatomic, readonly) UIView *stage; // holds the lines' view alone+@property (nonatomic, readonly) SGRKaraokeView *lyrics;+@end++@implementation SGRPlayerLyricsOverlay {+ UIView *_thumb, *_stage;+ UIImageView *_cover;+ SGRKaraokeView *_lyrics;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ _thumb = [[UIView alloc] initWithFrame:CGRectZero];+ _thumb.userInteractionEnabled = NO;+ _cover = [[UIImageView alloc] initWithFrame:CGRectZero];+ _cover.contentMode = UIViewContentModeScaleAspectFill;+ _cover.clipsToBounds = YES;+ _cover.layer.cornerCurve = kCACornerCurveContinuous;+ _cover.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [_thumb addSubview:_cover];+ _stage = [[UIView alloc] initWithFrame:CGRectZero];+ [self addSubview:_stage];+ [self addSubview:_thumb];+ return self;+}++- (UIView *)thumb { return _thumb; }+- (UIImageView *)cover { return _cover; }+- (UIView *)stage { return _stage; }++// The lines seek when they are tapped and the thumbnail takes no touches, so everywhere else the+// overlay would only swallow them: a view that takes touches does, even with nothing on it.+//+// What it hands them to instead is the title row. Translated to the top of the player it is drawn well+// outside the stack view it is arranged in, and UIKit stops looking at a view whose bounds the touch is+// not in, so the add button and the menu that rode up with it are past Spotify's own reach. Asked here+// directly, the row answers for where it is drawn.+- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {+ UIView *hit = [super hitTest:point withEvent:event];+ if (hit != self) return hit;+ UIView *row = SGRPlayerLyricsOpen() ? sg_info.viewIfLoaded : nil;+ UIView *inRow = row ? [row hitTest:[row convertPoint:point fromView:self] withEvent:event] : nil;+ return inRow == row ? nil : inRow;+}++// Made on the first tap and kept afterwards: it measures the song for its width before it can place a+// line, so a view built again on every tap would show nothing for the first frames. Out of the window+// it costs nothing -- its display link only runs while it is in one.+- (SGRKaraokeView *)lyrics {+ if (!_lyrics) {+ _lyrics = [[SGRKaraokeView alloc] initWithFrame:_stage.bounds];+ _lyrics.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ }+ if (_lyrics.superview != _stage) [_stage addSubview:_lyrics];+ _lyrics.frame = _stage.bounds;+ return _lyrics;+}++@end++static SGRPlayerLyricsOverlay *overlayIn(UIView *host) {+ SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(host, &kOverlayKey);+ if (!overlay) {+ overlay = [[SGRPlayerLyricsOverlay alloc] initWithFrame:host.bounds];+ objc_setAssociatedObject(host, &kOverlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ // On top of the player: it reaches from under the header row down to the progress bar, so it is over+ // the covers and the gradients and clear of every control. Under them instead, the mixing background+ // Spotify keeps between the two (01.txt:72) would be free to draw over the lines.+ if (overlay.superview != host) [host addSubview:overlay];+ return overlay;+}++#pragma mark - the measurements++typedef struct {+ BOOL ok;+ CGRect cover; // where Spotify draws the cover now, in the player+ CGRect thumb; // where it goes+ CGRect stage; // where the lines go+ CGFloat lift; // how far the title row rises+ CGFloat shift; // how far the title slides right to clear the thumbnail, 0 when it sits under it+} SGRLyricsLayout;++// What a view's frame would be with the translation this file put on it left out.+static CGRect untransformed(UIView *view, UIView *host) {+ CGRect frame = SGFrameIn(view, host);+ CGAffineTransform t = view.transform;+ return CGRectOffset(frame, -t.tx, -t.ty);+}++static SGRLyricsLayout layoutIn(UIView *host) {+ SGRLyricsLayout l = {0};+ UIView *info = sg_info.viewIfLoaded, *duration = sg_duration.viewIfLoaded, *title = sg_titleElement;+ if (!host || host.bounds.size.height < kLivingHeight || !info || !duration) return l;+ CGRect area = SGRPlayerArtworkAreaIn(host), cover = SGRPlayerCoverFrameIn(host);+ if (CGRectIsNull(area) || CGRectIsNull(cover)) return l;+ CGRect row = untransformed(info, host), bar = untransformed(duration, host);+ // The thumbnail takes the title's own leading edge, so the two line up down the page.+ CGFloat leading = title ? CGRectGetMinX(untransformed(title, host)) : CGRectGetMinX(area) + SGRSideMargin;+ l.cover = cover;+ l.thumb = CGRectMake(leading, CGRectGetMinY(area) + kThumbTop, kThumbSide, kThumbSide);+ // Beside the thumbnail when the title can be moved clear of it, under it when it cannot be found.+ CGFloat top = title ? CGRectGetMidY(l.thumb) - row.size.height / 2 : CGRectGetMaxY(l.thumb) + SGRGrid;+ l.lift = top - CGRectGetMinY(row);+ l.shift = title ? kThumbSide + kThumbGap : 0;+ CGFloat lines = MAX(CGRectGetMaxY(l.thumb), top + row.size.height) + kLyricsTop;+ l.stage = CGRectMake(CGRectGetMinX(area), lines, area.size.width, CGRectGetMinY(bar) - kLyricsBottom - lines);+ l.ok = l.stage.size.height > kLivingHeight / 2 && l.lift < 0;+ return l;+}++#pragma mark - the title row++// Where the row's trailing controls start, in the unit's coordinates: the nearest arranged view on the+// trailing side of the title that is still there to be seen. The title may not reach it.+static CGFloat trailingEdgeIn(UIView *info) {+ UIView *title = sg_titleElement, *row = title.superview;+ if (!title || !row) return CGFLOAT_MAX;+ CGFloat titleLeft = CGRectGetMinX(untransformed(title, info));+ CGFloat limit = CGRectGetMaxX(SGFrameIn(row, info));+ for (UIView *view in row.subviews) {+ if (view == title || view.hidden || view.alpha < 0.01 || view.bounds.size.width < 1) continue;+ CGFloat x = CGRectGetMinX(SGFrameIn(view, info));+ if (x > titleLeft && x < limit) limit = x;+ }+ return limit;+}++// The title moved right by the thumbnail would run into the add button beside it, and it cannot simply+// be narrowed: Spotify lays its marquee labels out with constraints, which put the width back the next+// time anything in the row lays out -- and a long title, being a marquee, lays out often. A mask on the+// element takes no part in that, so it holds between passes, and it fades the title out where Spotify's+// own fade would have been rather than cutting it.+static void clipTitle(UIView *element, CGFloat width) {+ CGRect bounds = element.bounds;+ if (width >= bounds.size.width - 0.5 || bounds.size.height < 1) {+ element.layer.mask = nil;+ return;+ }+ CAGradientLayer *mask = [element.layer.mask isKindOfClass:CAGradientLayer.class] ? (CAGradientLayer *)element.layer.mask : nil;+ if (!mask) {+ mask = [CAGradientLayer layer];+ mask.colors = @[(id)UIColor.whiteColor.CGColor, (id)UIColor.whiteColor.CGColor, (id)UIColor.clearColor.CGColor];+ mask.startPoint = CGPointMake(0, 0.5);+ mask.endPoint = CGPointMake(1, 0.5);+ element.layer.mask = mask;+ }+ CGFloat fade = MIN(kTitleFade, width);+ CGRect frame = CGRectMake(0, 0, MAX(0, width), bounds.size.height);+ if (CGRectEqualToRect(frame, mask.frame)) return;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ mask.frame = frame;+ mask.locations = @[@0, @(width > 0 ? (width - fade) / width : 0), @1];+ [CATransaction commit];+}++// The unit's row lays its arranged views out after the unit's own pass, so the transforms go on after it.+static void placeTitleRow(SGRLyricsLayout l) {+ UIView *info = sg_info.viewIfLoaded;+ if (!info) return;+ [SGRowIn(info) layoutIfNeeded];+ CGFloat lift = sg_open ? l.lift : 0, shift = sg_open ? l.shift : 0;+ CGAffineTransform rise = CGAffineTransformMakeTranslation(0, round(lift));+ if (!CGAffineTransformEqualToTransform(info.transform, rise)) info.transform = rise;+ UIView *title = sg_titleElement;+ if (!title) return;+ CGAffineTransform slide = CGAffineTransformMakeTranslation(round(shift), 0);+ if (!CGAffineTransformEqualToTransform(title.transform, slide)) title.transform = slide;+ // Closed it reaches as far as Spotify meant it to; moved, only as far as the controls it moved towards.+ CGFloat room = CGFLOAT_MAX;+ if (sg_open) room = trailingEdgeIn(info) - kTitleGap - (CGRectGetMinX(untransformed(title, info)) + shift);+ clipTitle(title, room);+}++#pragma mark - opening and closing++BOOL SGRPlayerLyricsAvailable(void) {+ NSString *track = SGKaraokePlayingTrack();+ return track != nil && SGKaraokeLinesForTrack(track) != nil;+}++BOOL SGRPlayerLyricsOpen(void) {+ return sg_open;+}++// Puts the overlay's own views where the measurements say, without animating. The thumbnail is laid out+// at the size and place Spotify draws its cover at and moved by its transform alone, so a pass that+// runs while it is up leaves it exactly where the eye has it: the two are worked out from one+// measurement. Bounds and a centre, not a frame, since both views can be under a transform.+static void place(SGRPlayerLyricsOverlay *overlay, UIView *host, SGRLyricsLayout l) {+ overlay.frame = CGRectUnion(l.cover, CGRectUnion(l.thumb, l.stage));+ CGRect cover = [overlay convertRect:l.cover fromView:host], stage = [overlay convertRect:l.stage fromView:host];+ overlay.thumb.bounds = (CGRect){CGPointZero, cover.size};+ overlay.thumb.center = CGPointMake(CGRectGetMidX(cover), CGRectGetMidY(cover));+ overlay.cover.frame = overlay.thumb.bounds;+ SGRShadowPlate *plate = SGRShadowPlateIn(overlay.thumb, &kPlateKey);+ plate.bounds = overlay.thumb.bounds;+ plate.center = CGPointMake(CGRectGetMidX(overlay.thumb.bounds), CGRectGetMidY(overlay.thumb.bounds));+ overlay.stage.bounds = (CGRect){CGPointZero, stage.size};+ overlay.stage.center = CGPointMake(CGRectGetMidX(stage), CGRectGetMidY(stage));+}++// Where the thumbnail's view has to go to land on `l.thumb`, as a transform about its own centre: the+// shadow and the corners travel with it that way, instead of a shadow redrawn on every frame.+static CGAffineTransform thumbTransform(SGRLyricsLayout l) {+ CGFloat scale = l.cover.size.width > 0 ? l.thumb.size.width / l.cover.size.width : 1;+ CGAffineTransform move = CGAffineTransformMakeTranslation(round(CGRectGetMidX(l.thumb) - CGRectGetMidX(l.cover)),+ round(CGRectGetMidY(l.thumb) - CGRectGetMidY(l.cover)));+ return CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale), move);+}++// The corners as they will be drawn: a radius under a scale is drawn scaled, so the thumbnail asks for+// the radius it wants divided by the shrink, and the two ends of the animation are 12pt and 8pt corners.+static CGFloat thumbRadius(SGRLyricsLayout l, BOOL open) {+ if (!open) return SGRRadiusArtwork;+ CGFloat scale = l.cover.size.width > 0 ? l.thumb.size.width / l.cover.size.width : 1;+ return scale > 0 ? SGRRadiusCover / scale : SGRRadiusArtwork;+}++static void setOpen(BOOL open, BOOL animated) {+ UIView *host = sg_host;+ if (open == sg_open) return;+ if (!host) {+ SGLog(@"redesign player: the lyrics were asked for before the player laid out");+ return;+ }+ SGRLyricsLayout l = layoutIn(host);+ if (open && !l.ok) {+ SGLog(@"redesign player: the lyrics have nowhere to go (stage %.0fx%.0f, lift %.0f)", l.stage.size.width, l.stage.size.height, l.lift);+ return;+ }+ // The thumbnail is the Kit's picture drawn again, and Spotify's cover goes as it appears: without a+ // picture there would be a hole where the cover was, so the cover stays and the lyrics wait.+ UIImage *picture = SGRNowPlayingArtwork(NULL, NULL);+ if (open && !picture) {+ SGLog(@"redesign player: no artwork read yet, the lyrics stay down");+ return;+ }+ sg_open = open;+ SGRPlayerLyricsChanged();++ SGRPlayerLyricsOverlay *overlay = overlayIn(host);+ place(overlay, host, l);+ CGAffineTransform away = thumbTransform(l);+ // 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);+ if (open) {+ overlay.cover.image = SGRNowPlayingArtwork(NULL, NULL);+ overlay.stage.alpha = 0;+ overlay.stage.transform = CGAffineTransformMakeScale(kLyricsEnterScale, kLyricsEnterScale);+ [overlay lyrics];+ // Spotify's cover goes the moment the redesign's own takes its place: the same picture at the+ // same size with the same corners, so there is nothing to see in the swap. Coming back it waits+ // for the thumbnail to land on it, or the two would be on screen at once, one of them half size.+ SGRPlayerCoverList().alpha = 0;+ }++ void (^move)(void) = ^{+ overlay.thumb.transform = open ? away : CGAffineTransformIdentity;+ overlay.cover.layer.cornerRadius = thumbRadius(l, open);+ placeTitleRow(l);+ sg_floating.viewIfLoaded.alpha = open ? 0 : 1;+ };+ void (^show)(void) = ^{+ overlay.stage.alpha = open ? 1 : 0;+ overlay.stage.transform = open ? CGAffineTransformIdentity+ : CGAffineTransformMakeScale(kLyricsEnterScale, kLyricsEnterScale);+ };+ void (^settled)(BOOL) = ^(BOOL finished) {+ sg_moving = NO;+ if (sg_open) return; // opened again while it was going away+ SGRPlayerCoverList().alpha = 1;+ [overlay removeFromSuperview];+ };++ if (!animated) {+ move();+ show();+ settled(YES);+ } else {+ sg_moving = YES;+ SGRAnimate(SGRMotionLayout, move, settled);+ // The lines come in behind the cover leaving, and go before it comes back.+ [UIView animateWithDuration:open ? kLyricsIn : kLyricsOut delay:open ? kLyricsInDelay : 0+ options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState+ animations:show completion:nil];+ }+ SGLog(@"redesign player: lyrics %@, thumbnail %.0fx%.0f at %.0f,%.0f, title row up %.0f and right %.0f, lines %.0fx%.0f",+ open ? @"up" : @"away", l.thumb.size.width, l.thumb.size.height, l.thumb.origin.x, l.thumb.origin.y,+ -l.lift, l.shift, l.stage.size.width, l.stage.size.height);+}++void SGRPlayerToggleLyrics(void) {+ if (!sg_open && !SGRPlayerLyricsAvailable()) return;+ setOpen(!sg_open, YES);+}++// A layout pass, a new track or a turn of the phone: the state is put back where it belongs without+// animating, since the frames it is measured from have just changed.+static void replace(void) {+ UIView *host = sg_host;+ if (!host || sg_moving) return; // a pass in the middle of the transition would cut it short+ SGRLyricsLayout l = layoutIn(host);+ if (sg_open && !l.ok) return;+ placeTitleRow(l);+ sg_floating.viewIfLoaded.alpha = sg_open ? 0 : 1;+ if (!sg_open) return;+ SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(host, &kOverlayKey);+ if (!overlay.superview) return;+ place(overlay, host, l);+ overlay.thumb.transform = thumbTransform(l);+ overlay.cover.layer.cornerRadius = thumbRadius(l, YES);+ overlay.lyrics.frame = overlay.stage.bounds;+ SGRPlayerCoverList().alpha = 0;+}++#pragma mark - the units++%hook _TtC19NowPlaying_ViewImpl24NowPlayingViewController+- (void)viewDidLayoutSubviews {+ %orig;+ UIView *host = ((UIViewController *)self).viewIfLoaded;+ if (!host || host.bounds.size.height < kLivingHeight) return;+ if (sg_host != host) {+ sg_host = host;+ SGLog(@"redesign player: the lyrics have the player's view %.0fx%.0f", host.bounds.size.width, host.bounds.size.height);+ }+ replace();+}++// The bar morphs back out of a full size cover as the player closes, so the thumbnail is put away first.+- (void)viewWillDisappear:(BOOL)animated {+ if (sg_open) setOpen(NO, NO);+ %orig;+}+%end++%hook _TtC20NowPlaying_ModesImpl23InformationElementsUnit+- (void)viewDidLayoutSubviews {+ %orig;+ UIViewController *unit = (UIViewController *)self;+ sg_info = unit;+ UIView *host = unit.viewIfLoaded;+ // The title and the artist are two labels of one arranged element view, which is what moves.+ UIView *label = SGRFindByIdentifier(host, @"now-playing-title-label", &kTitleKey);+ UIView *element = nil;+ for (UIView *v = label; v && v != host; v = v.superview) {+ if ([v.superview isKindOfClass:UIStackView.class]) { element = v; break; }+ }+ if (element && sg_titleElement != element) {+ sg_titleElement = element;+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"redesign player: the title rides on %@ %@", NSStringFromClass(element.class), NSStringFromCGRect(element.frame)); });+ }+ replace();+}+%end++%hook _TtC20NowPlaying_ModesImpl19DurationElementUnit+- (void)viewDidLayoutSubviews {+ %orig;+ sg_duration = (UIViewController *)self;+ replace();+}+%end++// The chips over the title (Switch to video and whatever else a track brings) sit in the middle of the+// room the lines take, so they go while the lines are up. The row keeps its height: the rest of the+// bottom stack stays where it was, which is the whole point of lifting only the title out of it.+%hook _TtC20NowPlaying_ModesImpl20FloatingElementsUnit+- (void)viewDidLayoutSubviews {+ %orig;+ sg_floating = (UIViewController *)self;+ replace();+}+%end++#pragma mark - the track changing under them++@interface SGRPlayerLyricsWatcher : NSObject <SGRPlayerStateObserver>+@end++@implementation SGRPlayerLyricsWatcher {+ NSString *_track;+}++- (void)playerStateDidChange:(SPTPlayerState *)state {+ NSString *track = SGRURIString(state.track.URI);+ if (!track || [track isEqualToString:_track]) return;+ _track = track;+ // Lyrics arrive a moment after the track does, and nothing announces them: the glyph is asked again+ // while they would be coming, and the lines already up wait out the same grace before they go.+ for (NSNumber *delay in @[@1, @(kLyricsGrace)]) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ SGRPlayerLyricsChanged();+ if (sg_open && delay.doubleValue >= kLyricsGrace && !SGRPlayerLyricsAvailable()) {+ SGLog(@"redesign player: no lyrics for the track that came on, the cover is back");+ setOpen(NO, YES);+ }+ });+ }+}++@end++static SGRPlayerLyricsWatcher *sg_watcher;++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ sg_watcher = [SGRPlayerLyricsWatcher new];+ SGRAddPlayerStateObserver(sg_watcher);+ [NSNotificationCenter.defaultCenter addObserverForName:SGRNowPlayingArtworkDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {+ if (!sg_open) return;+ SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(sg_host, &kOverlayKey);+ overlay.cover.image = SGRNowPlayingArtwork(NULL, NULL);+ }];+ SGRequireClasses(@[+ @"_TtC19NowPlaying_ViewImpl24NowPlayingViewController",+ @"_TtC20NowPlaying_ModesImpl23InformationElementsUnit",+ @"_TtC20NowPlaying_ModesImpl19DurationElementUnit",+ @"_TtC20NowPlaying_ModesImpl20FloatingElementsUnit",+ ]);+}diff --git a/tweak/Sources/Redesigned/Player/PlayerScroll.x b/tweak/Sources/Redesigned/Player/PlayerScroll.xnew file mode 100644index 00000000..78c5237f--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerScroll.x@@ -0,0 +1,72 @@+// Player redesign: the player is one screen. Spotify's is a list with the player as its header and the+// cards under it, and the Music app's player does not scroll at all -- the lyrics arrive in the player+// itself (PlayerLyrics.x), from the footer's glyph, rather than from under it. Every card is collapsed+// already (PlayerCards.x), so all that is left below is the gaps the list leaves between them.+//+// The list is not switched off: the pull that dismisses the player rides on its own pan recogniser.+// -[SPTBarInteractivePresentationController scrollViewDidAppear:] takes the list's panGestureRecognizer,+// adds dismissPanWithGestureRecognizer: to it and makes its own dismiss recogniser wait for it to fail,+// and that handler starts the dismissal only while the list is at or above its top (Spotify 9.1.78,+// 0x109814898 and 0x109814400). Turning scrolling off takes that recogniser out with it and the player+// can no longer be swiped away.+//+// So the range is closed instead: the bottom inset is set to whatever makes the furthest the list can+// scroll its own top. A drag upward then only stretches and springs back, a drag downward still carries+// the offset below zero, and the dismissal is untouched. It is worked out again on every layout pass+// and on every scroll, since the cards arrive long after the player does and change the content's height.+//+// Tree (trees/clean/player/01.txt:20): UICollectionView 402x874 id=scrolling_npv_collection_view_accessibility_identifier,+// with the player as an Element_List.SupplementaryItemView the size of the screen and a cell per card+// under it. NPVScrollViewController is its delegate (:567).+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"++static NSString *const kListIdentifier = @"scrolling_npv_collection_view_accessibility_identifier";+// Insets are never compared for equality, only for being a point or so out.+static const CGFloat kSlack = 0.5;++static char kListKey;++static void pinToTop(UIScrollView *list) {+ if (!list || list.bounds.size.height < 1) return;+ UIEdgeInsets own = list.contentInset, adjusted = list.adjustedContentInset;+ // What the safe area adds on top of the inset of its own, which has to be left in place.+ CGFloat safeArea = adjusted.bottom - own.bottom;+ CGFloat over = list.contentSize.height - list.bounds.size.height;+ // The furthest it may scroll is where it rests: -adjusted.top, its own top.+ CGFloat want = -adjusted.top - over - safeArea;+ if (want >= 0 || fabs(want - own.bottom) < kSlack) return;+ own.bottom = want;+ list.contentInset = own;++ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"redesign player: the list pinned to its top, %.0fpt of cards closed off", -want); });+}++%hook _TtC21NowPlaying_ScrollImpl23NPVScrollViewController+- (void)viewDidLayoutSubviews {+ %orig;+ UIView *page = ((UIViewController *)self).viewIfLoaded;+ UIView *list = SGRFindByIdentifier(page, kListIdentifier, &kListKey);+ if ([list isKindOfClass:UIScrollView.class]) pinToTop((UIScrollView *)list);+}++// A card arriving, or one of them settling on its height, grows the content without a pass of the page's.+- (void)collectionView:(UICollectionView *)list willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)path {+ %orig;+ pinToTop(list);+ // The height a cell reports is asked for after this, so the last word on the content is a runloop away.+ dispatch_async(dispatch_get_main_queue(), ^{ pinToTop(list); });+}++- (void)scrollViewDidScroll:(UIScrollView *)list {+ pinToTop(list);+ %orig;+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[@"_TtC21NowPlaying_ScrollImpl23NPVScrollViewController"]);+}