Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: the native player's cover fills the room a hidden lyric preview left
My-Name-Is-Jeff84af91e99248
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex d25863f9..9d316dd2 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -252,9 +252,11 @@ Native:keeps what the native tweaks stripped transparentNavbar/ Spotify's tab bar composed (Navbar.x, NavbarLayout.m, hooked from TabBarHooks.x), the Navbar and Add a tab pagesNowPlayingBar/ the device button hidden, the bar's flags- Player/ the full screen player (Player.x), its cards and buttons hidden (PlayerDeclutter.x), the glass lyrics card- (LyricsCard.x), the gestures' hookup and the hold on either side of the cover that plays at 2x until- the finger lifts (PlayerGestures.x), the Queue & devices flags+ Player/ the full screen player (Player.x), its cards and buttons hidden and a hidden lyric preview's room given+ to the cover (PlayerDeclutter.x), the glass lyrics card (LyricsCard.x), the gestures' hookup and the hold+ on either side of the cover that plays at 2x until the finger lifts (PlayerGestures.x), the list's pull+ held off while the progress bar is scrubbed (PlayerScrub.x), the Queue & devices flags. The scrub and+ the cover's room are checked in the simulator against harness/native-player/Lyrics/ the full screen lyrics page on glass (LyricsPage.x)LocalFiles/ a lyrics button on the player's footer for a local file with an LRC file linked to it, a fifth of theway in from the leading edge, which opens a page of the lines on black that follows the songdiff --git a/harness/native-player/README.md b/harness/native-player/README.mdnew file mode 100644index 00000000..e3932fbf--- /dev/null+++ b/harness/native-player/README.md@@ -0,0 +1,28 @@+# Native player harness++The native look's player fixes on the simulator, without the phone: `Native/Player/PlayerScrub.x` and+`PlayerDeclutter.x` run through `logos.pl -c generator=internal` over mocks under Spotify's class names,+linked with the real `Core/`.++ THEOS=$HOME/theos ./build.sh+ xcrun simctl install <udid> build/NativePlayerHarness.app+ xcrun simctl launch <udid> com.vojta.nativeplayerharness+ xcrun simctl spawn <udid> log show --last 1m --style compact --predicate 'process == "NativePlayerHarness"' | grep harness++`SRC=<another checkout>/tweak/Sources OUT=<dir> ./build.sh` builds it against other sources, for example+main before the fixes, to see the checks fail.++It checks, a line each with `ok` or `WRONG`:++- the scrub (issue #172): the player list's pan off while a mock of the progress bar's slider tracks, back+ at its end, at a cancel and when the slider leaves the window, a pan off already left off, and a sideways+ list between the slider and the player's list left alone.+- the cover's room (issue #77): with Lyrics preview shown nothing moves; with it hidden the preview takes+ no room and the cover is the centred square of the view it sits in, again after a later pass of+ Spotify's; a small cover and a tilt view outside the player's cover cell are left alone.++The log ends with `native player checks: n of 11 right -- PASS` or `FAIL`. On main before the fixes it+reads 7 of 11.++What it does not cover: Spotify's real Auto Layout in the cover cell, its open and close transition, and+a real touch on the slider.diff --git a/harness/native-player/build.sh b/harness/native-player/build.shnew file mode 100755index 00000000..5b5e2154--- /dev/null+++ b/harness/native-player/build.sh@@ -0,0 +1,45 @@+#!/bin/sh+set -e+# SRC may point at another checkout of tweak/Sources (an older commit, to see a bug before its fix).+SRC=${SRC:-$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)}+OUT=${OUT:-$(dirname "$0")/build}+rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/NativePlayerHarness.app"++for f in Native/Player/PlayerScrub.x Native/Player/PlayerDeclutter.x; do+ [ -f "$SRC/$f" ] || continue+ 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/Native/Player" -isysroot "$SDK" -Wno-deprecated-declarations \+ "$(dirname "$0")/main.m" "$(dirname "$0")/../scene.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 \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation \+ -o "$OUT/NativePlayerHarness.app/NativePlayerHarness"++cat > "$OUT/NativePlayerHarness.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>NativePlayerHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.nativeplayerharness</string>+<key>CFBundleName</key><string>NativePlayerHarness</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/>+ <key>UISceneConfigurations</key><dict>+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>+ <key>UISceneConfigurationName</key><string>Default</string>+ <key>UISceneDelegateClassName</key><string>SGRHarnessScene</string>+ </dict></array>+ </dict>+</dict>+</dict></plist>+PLIST+echo "built $OUT/NativePlayerHarness.app"diff --git a/harness/native-player/main.m b/harness/native-player/main.mnew file mode 100644index 00000000..6aec8d2c--- /dev/null+++ b/harness/native-player/main.m@@ -0,0 +1,194 @@+// The native player's scrub and cover room on the simulator: Native/Player/PlayerScrub.x and+// PlayerDeclutter.x run over mocks under Spotify's class names, and each check logs ok or WRONG. The log+// ends with `native player checks: n of m right -- PASS` or `FAIL`.+//+// scrub a mock of the progress bar's slider tracked in code (issue #172): the player list's pan off+// while it tracks, back at its end, at a cancel and when the slider leaves the window, a pan+// that was off already left off, and a sideways list between them left alone+// cover Spotify's layout for a track with lyrics, a smaller cover over the preview (issue #77):+// untouched with Lyrics preview shown, the cover a centred square of its room with it hidden,+// and a small cover and a tilt view outside the cover cell untouched+#import <UIKit/UIKit.h>+#import "Native/Player/NowPlaying.h"++#pragma mark - Spotify's classes, mocked++// Hooked by PlayerDeclutter.x but not looked at here.+@interface _TtC12Element_List18CollectionViewCell : UICollectionViewCell @end+@implementation _TtC12Element_List18CollectionViewCell @end+@interface _TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit @end+@interface _TtC20NowPlaying_ModesImpl18FooterElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl18FooterElementsUnit @end+@interface _TtC20NowPlaying_ModesImpl23InformationElementsUnit : UIViewController @end+@implementation _TtC20NowPlaying_ModesImpl23InformationElementsUnit @end++@interface _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl : UIView @end+@implementation _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl @end+@interface _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView : UIView @end+@implementation _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView @end+@interface _TtC22Lyrics_NPVContainerKit19LyricsContainerView : UIView @end+@implementation _TtC22Lyrics_NPVContainerKit19LyricsContainerView+- (CGSize)intrinsicContentSize { return CGSizeMake(UIViewNoIntrinsicMetric, 64); }+- (CGSize)sizeThatFits:(CGSize)size { return CGSizeMake(size.width, 64); }+@end++// The progress bar's slider, tracking without a touch so it can be scrubbed in code.+@interface _TtCO17NowPlaying_ECMKit11ProgressBar6Slider : UISlider @end+@implementation _TtCO17NowPlaying_ECMKit11ProgressBar6Slider+- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { return YES; }+- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {}+- (void)cancelTrackingWithEvent:(UIEvent *)event {}+@end++#pragma mark - checks++static NSUInteger sg_right, sg_checks;++static void check(NSString *step, BOOL ok, NSString *detail) {+ sg_checks++;+ if (ok) sg_right++;+ NSLog(@"[harness] %@: %@ -- %@", step, detail ?: @"", ok ? @"ok" : @"WRONG");+}++static void hideLyricsPreview(BOOL hidden) {+ [NSUserDefaults.standardUserDefaults setBool:hidden forKey:SGHideLyricsInline];+}++static void runScrubChecks(UIWindow *window) {+ UIScrollView *list = [[UIScrollView alloc] initWithFrame:window.bounds];+ list.accessibilityIdentifier = @"scrolling_npv_collection_view_accessibility_identifier";+ list.contentSize = CGSizeMake(window.bounds.size.width, window.bounds.size.height * 3);+ [window addSubview:list];+ // A sideways list between the slider and the player's, which the scrub must not take for it.+ UIScrollView *sideways = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 500, window.bounds.size.width, 60)];+ sideways.contentSize = CGSizeMake(window.bounds.size.width * 2, 60);+ [list addSubview:sideways];+ UISlider *slider = [[_TtCO17NowPlaying_ECMKit11ProgressBar6Slider alloc] initWithFrame:CGRectMake(24, 20, 300, 20)];+ [sideways addSubview:slider];+ UIPanGestureRecognizer *pan = list.panGestureRecognizer;+ UITouch *none = nil;++ [slider beginTrackingWithTouch:none withEvent:nil];+ check(@"scrub held while scrubbing", !pan.enabled && sideways.panGestureRecognizer.enabled,+ [NSString stringWithFormat:@"list pan %d, sideways pan %d", pan.enabled, sideways.panGestureRecognizer.enabled]);+ [slider endTrackingWithTouch:none withEvent:nil];+ check(@"scrub back at the end", pan.enabled, nil);+ [slider beginTrackingWithTouch:none withEvent:nil];+ [slider cancelTrackingWithEvent:nil];+ check(@"scrub back at a cancel", pan.enabled, nil);+ [slider beginTrackingWithTouch:none withEvent:nil];+ [slider removeFromSuperview];+ check(@"scrub back when the slider left the window", pan.enabled, nil);+ [sideways addSubview:slider];+ pan.enabled = NO;+ [slider beginTrackingWithTouch:none withEvent:nil];+ [slider endTrackingWithTouch:none withEvent:nil];+ check(@"scrub, a pan off already left off", !pan.enabled, nil);+ [list removeFromSuperview];+}++// CoverArtCellImpl > a plain view (the room) > the tilt view and the preview under it, the tilt view+// holding the cover pinned to its size, as Spotify's ElementView is.+static UIView *coverCell(UIWindow *window, Class cellClass, CGRect roomFrame, UIView **tiltOut, UIView **previewOut) {+ UIView *cell = [[cellClass alloc] initWithFrame:window.bounds];+ [window addSubview:cell];+ UIView *room = [[UIView alloc] initWithFrame:roomFrame];+ [cell addSubview:room];+ CGFloat side = roomFrame.size.width;+ CGFloat small = round(side * 0.8);+ UIView *tilt = [[_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView alloc]+ initWithFrame:CGRectMake(round((side - small) / 2), 0, small, small)];+ UIView *cover = [[UIView alloc] initWithFrame:tilt.bounds];+ cover.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [tilt addSubview:cover];+ [room addSubview:tilt];+ UIView *preview = [[_TtC22Lyrics_NPVContainerKit19LyricsContainerView alloc] initWithFrame:CGRectMake(0, small + 8, side, 64)];+ [room addSubview:preview];+ *tiltOut = tilt;+ *previewOut = preview;+ return cell;+}++static void runCoverChecks(UIWindow *window) {+ Class cellClass = _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl.class;+ CGRect roomFrame = CGRectMake(24, 120, 354, 430);+ CGRect square = CGRectMake(0, round((430 - 354) / 2.0), 354, 354);+ UIView *tilt, *preview;++ hideLyricsPreview(NO);+ UIView *cell = coverCell(window, cellClass, roomFrame, &tilt, &preview);+ CGRect before = tilt.frame, previewBefore = preview.frame;+ [cell setNeedsLayout];+ [cell layoutIfNeeded];+ [tilt setNeedsLayout];+ [tilt layoutIfNeeded];+ check(@"cover, preview shown, untouched", CGRectEqualToRect(tilt.frame, before) && CGRectEqualToRect(preview.frame, previewBefore)+ && !preview.hidden, [NSString stringWithFormat:@"cover %@, preview %@", NSStringFromCGRect(tilt.frame), NSStringFromCGRect(preview.frame)]);+ [cell removeFromSuperview];++ hideLyricsPreview(YES);+ cell = coverCell(window, cellClass, roomFrame, &tilt, &preview);+ [cell setNeedsLayout];+ [cell layoutIfNeeded];+ check(@"cover, preview hidden takes no room", preview.hidden && CGSizeEqualToSize(preview.frame.size, CGSizeZero)+ && CGSizeEqualToSize(preview.intrinsicContentSize, CGSizeZero) && CGSizeEqualToSize([preview sizeThatFits:roomFrame.size], CGSizeZero),+ [NSString stringWithFormat:@"frame %@, intrinsic %@", NSStringFromCGRect(preview.frame), NSStringFromCGSize(preview.intrinsicContentSize)]);+ UIView *picture = tilt.subviews.firstObject;+ check(@"cover, preview hidden, fills its room", CGRectEqualToRect(tilt.frame, square) && CGSizeEqualToSize(picture.bounds.size, square.size),+ [NSString stringWithFormat:@"cover %@, picture %@", NSStringFromCGRect(tilt.frame), NSStringFromCGSize(picture.bounds.size)]);+ // Spotify sizing the tilt view again on a pass of its own, without the cell laying out.+ tilt.frame = CGRectMake(40, 0, 280, 280);+ [tilt setNeedsLayout];+ [tilt layoutIfNeeded];+ check(@"cover, a later pass of Spotify's", CGRectEqualToRect(tilt.frame, square), NSStringFromCGRect(tilt.frame));+ [cell removeFromSuperview];++ // The bar's 40pt cover, and a tilt view outside the player's cover cell (an album header), stay as they are.+ cell = coverCell(window, cellClass, CGRectMake(16, 16, 40, 52), &tilt, &preview);+ before = tilt.frame;+ [cell setNeedsLayout];+ [cell layoutIfNeeded];+ check(@"cover, a small one untouched", CGRectEqualToRect(tilt.frame, before), NSStringFromCGRect(tilt.frame));+ [cell removeFromSuperview];+ cell = coverCell(window, UIView.class, roomFrame, &tilt, &preview);+ before = tilt.frame;+ [tilt setNeedsLayout];+ [tilt layoutIfNeeded];+ check(@"cover, outside the cover cell untouched", CGRectEqualToRect(tilt.frame, before), NSStringFromCGRect(tilt.frame));+ [cell removeFromSuperview];+ hideLyricsPreview(NO);+}++#pragma mark - app++@interface Delegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++@implementation Delegate+- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options {+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ self.window.rootViewController = [UIViewController new];+ self.window.backgroundColor = UIColor.blackColor;+ [self.window makeKeyAndVisible];+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ runScrubChecks(self.window);+ runCoverChecks(self.window);+ NSLog(@"[harness] native player checks: %lu of %lu right -- %@", (unsigned long)sg_right, (unsigned long)sg_checks,+ sg_right == sg_checks ? @"PASS" : @"FAIL");+ });+ return YES;+}+@end++// Before every %ctor, so the native look's gate reads on.+__attribute__((constructor(101))) static void sg_harnessDefaults(void) {+ [NSUserDefaults.standardUserDefaults setBool:NO forKey:@"spotifyglass.redesign"];+}++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(Delegate.class));+ }+}diff --git a/tweak/Sources/Native/Player/PlayerDeclutter.x b/tweak/Sources/Native/Player/PlayerDeclutter.xindex 04de969a..a0172325 100644--- a/tweak/Sources/Native/Player/PlayerDeclutter.x+++ b/tweak/Sources/Native/Player/PlayerDeclutter.x@@ -1,7 +1,7 @@// Player declutter: hides parts of the full screen player, one switch each on the Player page. Cards// under the player are Element_List cells; a hidden one reports zero height when the list sizes it,// so the list closes up around it (the 24pt gap between cards stays). Player buttons go invisible but-// keep their place, so their row stays centred.+// keep their place, so their row stays centred. A hidden lyric preview gives its room to the cover.//// Trees (trees/now-playing*.txt): every card is a CollectionViewCell whose content view names the// page (NowPlaying_ScrollAPI) and whose subtree names the card. Player rows are the UIStackView of each NowPlaying_ModesImpl unit: playback controls@@ -119,6 +119,9 @@ static void finish(UIViewController *unit, BOOL changed) {}%end+// Hidden, the preview takes no room either, whatever size it is asked for or given: Spotify's cell kept+// room under the cover for it, so a track with lyrics had a smaller cover pushed up over a blank band+// (issue #77). With the switch off the preview shows and its room is its own.%hook _TtC22Lyrics_NPVContainerKit19LyricsContainerView- (void)setHidden:(BOOL)hidden {%orig(SGHidden(SGHideLyricsInline) ? YES : hidden);@@ -127,6 +130,76 @@ static void finish(UIViewController *unit, BOOL changed) {%orig;if (SGHidden(SGHideLyricsInline)) ((UIView *)self).hidden = YES;}+- (CGSize)intrinsicContentSize {+ return SGHidden(SGHideLyricsInline) ? CGSizeZero : %orig;+}+- (CGSize)sizeThatFits:(CGSize)size {+ return SGHidden(SGHideLyricsInline) ? CGSizeZero : %orig;+}+- (void)setFrame:(CGRect)frame {+ if (SGHidden(SGHideLyricsInline)) frame.size = CGSizeZero;+ %orig(frame);+}+%end++#pragma mark - the cover in the preview's room++// The bar's cover has a tilt view of its own, 40pt; the player's is about 354.+static const CGFloat kCoverMinWidth = 200;++// The tilt view takes the largest square of the plain view it sits in with the preview, centred on whole+// points, the way the Music app's cover fills its square. Bounds and a centre, not a frame, since the tilt+// view carries Spotify's tilt while the cover is inspected. A square under kCoverMinWidth is left alone.+static void fillRoom(UIView *tilt) {+ CGRect room = tilt.superview.bounds;+ CGFloat side = MIN(room.size.width, room.size.height);+ if (side < kCoverMinWidth) return;+ CGPoint middle = CGPointMake(round(CGRectGetMinX(room) + (room.size.width - side) / 2) + side / 2,+ round(CGRectGetMinY(room) + (room.size.height - side) / 2) + side / 2);+ CGRect bounds = (CGRect){tilt.bounds.origin, CGSizeMake(side, side)};+ if (CGRectEqualToRect(tilt.bounds, bounds) && CGPointEqualToPoint(tilt.center, middle)) return;+ tilt.bounds = bounds;+ tilt.center = middle;+ [tilt setNeedsLayout];+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"native player: the cover fills its room, %.0fpt in %@", side, NSStringFromCGRect(room)); });+}++static Class tiltClass(void) {+ static Class tilt;+ if (!tilt) tilt = NSClassFromString(@"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView");+ return tilt;+}++// Only the player's own cover cell; the legacy and listening party cells are left as Spotify lays them out.+static BOOL inCoverCell(UIView *tilt) {+ static Class cell;+ if (!cell) cell = NSClassFromString(@"_TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl");+ for (UIView *v = tilt.superview; v; v = v.superview) {+ if ([v isKindOfClass:cell]) return YES;+ }+ return NO;+}++%hook _TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl+- (void)layoutSubviews {+ %orig;+ if (!SGHidden(SGHideLyricsInline)) return;+ SGForEachView((UIView *)self, ^(UIView *view) {+ if ([view isKindOfClass:tiltClass()]) fillRoom(view);+ });+}+%end++// Again before the tilt view lays out, for a pass of Spotify's that sizes it without the cell laying out.+// Before %orig, so the cover inside follows, and Player.x's corners and shadow and PlayerGestures.x's hold,+// which hook the same method and work after it, see the new size.+%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView+- (void)layoutSubviews {+ UIView *tilt = (UIView *)self;+ if (SGHidden(SGHideLyricsInline) && inCoverCell(tilt)) fillRoom(tilt);+ %orig;+}%end%ctor {@@ -138,5 +211,7 @@ static void finish(UIViewController *unit, BOOL changed) {@"_TtC20NowPlaying_ModesImpl18FooterElementsUnit",@"_TtC20NowPlaying_ModesImpl23InformationElementsUnit",@"_TtC22Lyrics_NPVContainerKit19LyricsContainerView",+ @"_TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl",+ @"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView",]);}