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 add to library button shows the first time an album or playlist opens
Vojtěch Škopek4ae246fb58d1
diff --git a/harness/album/README.md b/harness/album/README.mdindex fa378915..f7fb77c5 100644--- a/harness/album/README.md+++ b/harness/album/README.md@@ -29,6 +29,11 @@ Since 2026-09-18 the header is the Kit's `SGRHeaderInfo` over Spotify's blankedlonger tests anything the redesign moves; it still shows Spotify's column staying blank. The metadata row'scells arrive after the header's pass, which is what `AlbumHeader.x`'s re-read answers.+`late` on the launch line (`xcrun simctl launch booted com.vojta.albumharness late`) opens the album the way a+first open has it, with no add in the row, and adds it at 2.5 s as an arranged subview of the row, which lays out+nothing above the row. At 3 s the log says what the row shows on Play's right: "Add" once `AlbumHeader.x` watches+the row, "Download" before it did (issue #19).+At 3.5 s it puts Spotify's own frames back on the title block, its stack and the action row and asksboth groups for a layout pass, which is what the redesign's `SGRObserveLayout` watches have to survive.The log says what the redesign answered with.diff --git a/harness/album/main.m b/harness/album/main.mindex e1ccc3c8..2d218e3a 100644--- a/harness/album/main.m+++ b/harness/album/main.m@@ -135,6 +135,24 @@ static UIView *actionButton(UIView *row, CGRect frame, NSString *identifier, NSS@end+// What the redesign's row shows on Play's right: the label of the Kit's last round button, the trailing one.+static NSString *trailingLabel(UIView *root) {+ NSMutableArray<UIView *> *stack = [NSMutableArray arrayWithObject:root];+ while (stack.count) {+ UIView *v = stack.lastObject;+ [stack removeLastObject];+ if ([NSStringFromClass(v.class) isEqualToString:@"SGRHeaderInfo"]) {+ UIView *trailing = nil;+ for (UIView *sub in v.subviews) {+ if ([NSStringFromClass(sub.class) isEqualToString:@"SGRMirrorButton"]) trailing = sub;+ }+ return trailing && !trailing.hidden ? trailing.accessibilityLabel : @"nothing";+ }+ [stack addObjectsFromArray:v.subviews];+ }+ return @"no header";+}+#pragma mark - the page@interface SGRHarnessDelegate : UIResponder <UIApplicationDelegate>@@ -235,7 +253,10 @@ static UIView *actionButton(UIView *row, CGRect frame, NSString *identifier, NSS@[@"Components.UI.AddToButton", @"plus", @"Add", @62, @0, @48, @48],@[@"DownloadButton.Granular.None", @"arrow.down.circle", @"Download", @110, @0, @48, @48],@[@"Components.UI.ContextMenuButton-3OxfaVgvTxUTy7276t7SPU", @"ellipsis", @"More options", @158, @0, @48, @48]];+ // `late` on the launch line: add is not in the row yet, the way an album opened for the first time has it.+ BOOL late = [NSProcessInfo.processInfo.arguments containsObject:@"late"];for (NSArray *action in actions) {+ if (late && [action[0] isEqualToString:@"Components.UI.AddToButton"]) continue;CGRect frame = CGRectMake([action[3] doubleValue], [action[4] doubleValue], [action[5] doubleValue], [action[6] doubleValue]);[_actionItems addObject:actionButton(_actionRow, frame, action[0], action[1], action[2])];[_actionFrames addObject:[NSValue valueWithCGRect:frame]];@@ -341,6 +362,20 @@ static UIView *actionButton(UIView *row, CGRect frame, NSString *identifier, NSS[self.window makeKeyAndVisible];+ // In `late`, add arrives at 2.5 s, after every pass of the header's and the metadata's re-reads: an arranged+ // subview of the row, which lays out the row and nothing above it.+ if (late) {+ UIStackView *row = (UIStackView *)_actionRow;+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [row insertArrangedSubview:actionButton(row, CGRectMake(62, 0, 48, 48), @"Components.UI.AddToButton", @"plus", @"Add")+ atIndex:0];+ NSLog(@"[harness] late: add arrived in the row");+ });+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ NSLog(@"[harness] late: Play's right shows \"%@\"", trailingLabel(root.view));+ });+ }+// The list is measured the way the page's collection measures it: every cell is asked how tall it wants// to be, which is where AlbumSections.x answers 0 for what the redesign drops, and the answers are// stacked. Done a beat after launch, so the header has laid out at least once first.diff --git a/harness/playlist/README.md b/harness/playlist/README.mdindex c5acf9b9..a962decd 100644--- a/harness/playlist/README.md+++ b/harness/playlist/README.md@@ -28,6 +28,11 @@ What it does not cover: the real element framework's autolayout, and the flags ``other` on the launch line makes it someone else's playlist (save on Play's right instead of download, and adescription with an HTML entity); the header controller's view model is mocked from the device's values (2026-09-18).+`other late` opens it with no save in the row, the way a first open has it, and adds save at 2.5 s as an arranged+subview of HeaderActionsRow, which lays out nothing above the row. At 3 s the log says what the row shows on Play's+right: "Like" once `PlaylistHeader.x` watches the row, "Download" before it did (issue #19). The scripted states+from 4 s on lay the header out and would hide the difference, so read it before then.+`liked` on the launch line (`xcrun simctl launch booted com.vojta.playlistharness liked`) builds Liked Songsinstead, from `trees/continuous/1.txt` (2026-09-18): no cover, a 238pt header, the count in a stack of its own,the play button 80x48, and `LiquidGlass.gradientContainer`, which it fades in at 3 s as a scroll does.diff --git a/harness/playlist/main.m b/harness/playlist/main.mindex eca841e6..b22b06e4 100644--- a/harness/playlist/main.m+++ b/harness/playlist/main.m@@ -154,6 +154,23 @@ static UIView *actionButton(UIView *row, CGRect frame, NSString *identifier, NSSreturn action;}+// What the redesign's row shows on Play's right: the label of the Kit's last round button, the trailing one.+static NSString *trailingLabel(UIView *root) {+ NSMutableArray<UIView *> *stack = [NSMutableArray arrayWithObject:root];+ while (stack.count) {+ UIView *v = stack.lastObject;+ [stack removeLastObject];+ if ([NSStringFromClass(v.class) isEqualToString:@"SGRHeaderInfo"]) {+ UIView *trailing = nil;+ for (UIView *sub in v.subviews) {+ if ([NSStringFromClass(sub.class) isEqualToString:@"SGRMirrorButton"]) trailing = sub;+ }+ return trailing && !trailing.hidden ? trailing.accessibilityLabel : @"nothing";+ }+ [stack addObjectsFromArray:v.subviews];+ }+ return @"no header";+}// Liked Songs (trees/continuous/1.txt, 2026-09-18): the same page with no cover, a 238pt header, a column of// only the title and the count (the count in a stack of its own, 314pt of label and a 56pt spacer), no add or@@ -381,7 +398,21 @@ static void buildLikedSongs(UIViewController *page, CGFloat W) {UIView *rowElement = box(container, _TtGC13Element_UIKit11ElementViewT_P_P__.class, CGRectMake(0, 0, 198, 48), nil);UIStackView *actions = (UIStackView *)box(rowElement, UIStackView.class, rowElement.bounds, @"HeaderActionsRow");actionButton(actions, CGRectMake(0, 4, 58, 40), @"Components.UI.WatchFeedEntityExplorerButton", @"Explore");- actionButton(actions, CGRectMake(58, 0, 48, 48), @"Components.UI.AddToButton", @"Like");+ // `late` on the launch line: save is not in the row yet, the way a playlist opened for the first time has it,+ // and arrives at 2.5 s as an arranged subview of the row, which lays out the row and nothing above it.+ BOOL late = [NSProcessInfo.processInfo.arguments containsObject:@"late"];+ if (late) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [actions insertArrangedSubview:actionButton(actions, CGRectMake(58, 0, 48, 48), @"Components.UI.AddToButton", @"Like")+ atIndex:0];+ NSLog(@"[harness] late: save arrived in the row");+ });+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ NSLog(@"[harness] late: Play's right shows \"%@\"", trailingLabel(page.view));+ });+ } else {+ actionButton(actions, CGRectMake(58, 0, 48, 48), @"Components.UI.AddToButton", @"Like");+ }actionButton(actions, CGRectMake(106, 0, 48, 48), @"DownloadButton.Granular.None", @"Download");actionButton(actions, CGRectMake(154, 2, 44, 44), @"Components.UI.ContextMenuButton", @"More options");diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.xindex 1d2764a6..4ed94ec4 100644--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x@@ -37,6 +37,7 @@ static const CGFloat kMinHero = 120, kMinCover = 80;static char kHeaderKey, kCoverKey, kTitleKey, kParentKey, kMetaKey, kAddKey, kDownloadKey, kPlayKey, kShuffleKey;static char kHeroKey, kHeroHeightKey, kHeaderHeightKey, kInfoKey, kCoverWatchedKey, kHeaderWatchedKey, kRetryKey;+static char kExploreKey, kRowWatchedKey;#pragma mark - moving Spotify's views@@ -92,6 +93,14 @@ static void setFrame(UIView *view, CGRect frame) {if (view && !CGRectIsEmpty(frame) && !CGRectEqualToRect(view.frame, frame)) view.frame = frame;}+// The stack Spotify arranges the header's buttons in: the first one above `button`.+static UIView *rowOf(UIView *button, UIView *header) {+ for (UIView *v = button.superview; v && v != header; v = v.superview) {+ if ([v isKindOfClass:UIStackView.class]) return v;+ }+ return nil;+}+// Installs `laidOut` on the view's own pass once, under `key`.static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view)) {if (!view || objc_getAssociatedObject(view, key)) return;@@ -312,6 +321,17 @@ static SGRHeaderInfo *applyInfo(UIView *header, UIView *page) {if (play) conceal(wrapperFor(play, page));if (shuffle) conceal(wrapperFor(shuffle, page));+ // Add arrives after the header has laid out on an album opened for the first time (the next time its state+ // is cached and it is there from the start), in a row that lays nothing else out (Native/Album/Album.x): the+ // row drew download on Play's right, or nothing, until the page was opened again (issue #19). So the row's+ // own pass is watched, a plain UIStackView, as the artist page's is, found from whichever of Spotify's+ // buttons is in it already.+ UIView *inRow = add ?: download ?: SGRFindByIdentifier(header, @"Components.UI.WatchFeedEntityExplorerButton", &kExploreKey);+ __weak UIView *weakHeader = header, *weakPage = page;+ watch(rowOf(inRow, header), &kRowWatchedKey, ^(UIView *view) {+ if (weakHeader && weakPage) applyHeader(weakHeader, weakPage);+ });+static BOOL logged;if (!logged && header.window && title) {logged = YES;diff --git a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.xindex 1dd1febf..84a696e3 100644--- a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x+++ b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x@@ -37,7 +37,7 @@ static const CGFloat kMinHero = 120, kMinCover = 80;static char kCoverKey, kMetaKey, kPlayKey, kLayoutKey, kToolbarKey, kScrimKey, kBarScrimKey;static char kShuffleKey, kAddKey, kDownloadKey, kInfoKey, kBlockHeightKey, kBlockWatchedKey;-static char kHeroKey, kHeroHeightKey, kCoverWatchedKey;+static char kHeroKey, kHeroHeightKey, kCoverWatchedKey, kRowKey, kRowWatchedKey;#pragma mark - finding things@@ -355,6 +355,21 @@ static void showPlaylist(SGRHeaderInfo *info, UIView *block, UIView *root, id mo}}+static SGRHeaderInfo *applyInfo(UIView *block, UIView *headerRoot, UIViewController *headerVC);++// `view`'s own pass puts the block together again, installed once under `key`.+static void reapplyOnPass(UIView *view, const void *key, UIView *block, UIView *headerRoot, UIViewController *headerVC) {+ if (!view || objc_getAssociatedObject(view, key)) return;+ objc_setAssociatedObject(view, key, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ __weak UIView *weakBlock = block, *weakRoot = headerRoot;+ __weak UIViewController *weakVC = headerVC;+ SGRObserveLayout(view, ^(UIView *laidOut) {+ // A block the view has since left is Spotify's to lay out alone.+ if (!weakBlock || !weakRoot || !weakVC || [objc_getAssociatedObject(weakRoot, &kInfoKey) superview] != weakBlock) return;+ applyInfo(weakBlock, weakRoot, weakVC);+ });+}+// The block's own content goes, whole, and the redesign's takes its place. Spotify adds to the block as the page// loads and shows parts of it again when Play is pressed, so everything of Spotify's in it is concealed on every// pass and again from the block's own pass; concealing is idempotent and costs nothing once done.@@ -380,16 +395,11 @@ static SGRHeaderInfo *applyInfo(UIView *block, UIView *headerRoot, UIViewControlif (!CGRectEqualToRect(info.frame, frame)) info.frame = frame;showPlaylist(info, block, headerRoot, viewModelOf(headerVC));- if (!objc_getAssociatedObject(block, &kBlockWatchedKey)) {- objc_setAssociatedObject(block, &kBlockWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- __weak UIView *weakRoot = headerRoot;- __weak UIViewController *weakVC = headerVC;- SGRObserveLayout(block, ^(UIView *view) {- // A block the view has since left is Spotify's to lay out alone.- if (!weakRoot || !weakVC || [objc_getAssociatedObject(weakRoot, &kInfoKey) superview] != view) return;- applyInfo(view, weakRoot, weakVC);- });- }+ reapplyOnPass(block, &kBlockWatchedKey, block, headerRoot, headerVC);+ // Save arrives after the header has laid out on a playlist opened for the first time, in a row that lays+ // nothing else out: Play's right drew download, or nothing, until the page was opened again (issue #19). The+ // row's own pass is watched too, a plain UIStackView, as the album's and the artist's are.+ reapplyOnPass(SGRFindByIdentifier(block, @"HeaderActionsRow", &kRowKey), &kRowWatchedKey, block, headerRoot, headerVC);return info;}