Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: a tab you added lights up on the glass bar while its page is up, and a second tap goes back to it
My-Name-Is-Jefff9bf6098ca56
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 4180519e..8aa60a42 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -556,8 +556,9 @@ Spotify's router cannot open is refused there), and an icon picked from Encore'ssearchable. Split tabs sets chosen tabs apart at the right end of the bar: after a gap in the native look,on a glass bar of their own in the redesign, like Search in the Music app. Spotify's own tabs are kept by thename under their icon, so they can be hidden but never removed, and switching the app's language-starts the order over. A tab of the mod's own opens its link through Spotify's link dispatcher, so it-never lights up as the tab you are on. In the redesign (Redesigned/Navbar/NavbarSettings.m) the page leads+starts the order over. A tab of the mod's own opens its link through Spotify's link dispatcher. In the native+look it never lights up as the tab you are on; on the redesign's glass bar it does while the page it opened is+up, and a second tap goes back to that page. In the redesign (Redesigned/Navbar/NavbarSettings.m) the page leadswith a preview of the glass bar, drawn by the same system UITabBar as the bar itself from the list as itstands, the split tabs on a bar of their own, and changing with every change on the page; then Custom tabbar (off, the bar is Spotify's own tabs in Spotify's order, the list kept); two picture cards for the labels,diff --git a/harness/tabbar/README.md b/harness/tabbar/README.mdindex 1dbb9047..5e582969 100644--- a/harness/tabbar/README.md+++ b/harness/tabbar/README.md@@ -40,6 +40,9 @@ half way through a slide what the screen shows of the message bar, the tab bar astands on a glass bar of its own, and the platters of both bars are logged. `pick` picks Search at 2 s andHome at 4 s through the system bar's delegate, the mock tab repainting its label white as Spotify's does,and logs which bar selects what after each: `xcrun simctl launch <udid> com.vojta.tabbarharness pick split`.+`lit` has Your Library stand in for a tab of the mod's own whose page is up (stubs.m answers `SGRNavbarLitTab`+with it) at 2 s, while Home's label stays white: the selection logged at 2.5 s should be Your Library. Home is+picked at 3.5 s, which forgets the lit tab, and the selection at 4.5 s should be Home.xcrun simctl spawn <udid> log show --last 1m --style compact --predicate 'eventMessage CONTAINS "[harness]" OR eventMessage CONTAINS "tab bar:"'diff --git a/harness/tabbar/main.m b/harness/tabbar/main.mindex 177ea48e..0ef1cddc 100644--- a/harness/tabbar/main.m+++ b/harness/tabbar/main.m@@ -2,6 +2,7 @@// screen, laid out with the constraints 9.1.78 makes (see the README for the addresses), under Spotify's// class names, with Spotify's message bar (Offline, Private Session) able to come in under the tab bar.#import <UIKit/UIKit.h>+#import "Core/SGViewTree.h"#pragma mark - Spotify's classes, by the names the hooks look for@@ -401,6 +402,18 @@ static NSArray<UITabBar *> *systemBarsIn(UIView *root) {return bars;}+extern __weak UIView *sgHarnessLitTab;++// The item of the stock row named `title`.+static UIView *stockItem(SGHarnessChrome *chrome, NSString *title) {+ for (UIView *item in SGRowIn(chrome.tabs.bar).arrangedSubviews) {+ for (UIView *sub in item.subviews) {+ if ([sub isKindOfClass:UILabel.class] && [((UILabel *)sub).text isEqualToString:title]) return item;+ }+ }+ return nil;+}+// A tab picked on whichever system bar shows it, the calls a finger ends in.static void pick(SGHarnessChrome *chrome, NSString *title) {for (UITabBar *bar in systemBarsIn(chrome.tabs.bar)) {@@ -518,6 +531,18 @@ static void after(double seconds, dispatch_block_t block) {after(3.5, ^{ SGRSetTabBarMinimized(NO, YES); });after(5.0, ^{ report(chrome, @"expanded again"); });}+ // `lit`: Library stands in for a tab of the mod's own whose page is up at 2 s, while Spotify still paints+ // Home white: the glass bar selects Library. Home picked at 3.5 s takes the light back.+ if ([mode isEqualToString:@"lit"]) {+ after(2.0, ^{+ sgHarnessLitTab = stockItem(chrome, @"Your Library");+ [chrome.tabs.bar setNeedsLayout];+ [chrome.tabs.bar layoutIfNeeded];+ });+ after(2.5, ^{ reportSelection(chrome, @"with Library lit"); });+ after(3.5, ^{ pick(chrome, @"Home"); });+ after(4.5, ^{ reportSelection(chrome, @"after Home"); });+ }// `pick`: Search picked at 2 s and Home at 4 s, which bar selects what logged after each.if ([mode isEqualToString:@"pick"]) {after(2.0, ^{ pick(chrome, @"Search"); });diff --git a/harness/tabbar/stubs.m b/harness/tabbar/stubs.mindex 68144f1c..e34ffffc 100644--- a/harness/tabbar/stubs.m+++ b/harness/tabbar/stubs.m@@ -21,6 +21,13 @@ BOOL SGRTabIsApart(UIView *item) {return NO;}void SGRLogTabBarRow(UIView *tabBar) {}+// The tab of the mod's own whose page is up (Navbar.x), which the `lit` launch word sets by hand.+__weak UIView *sgHarnessLitTab = nil;+UIView *SGRNavbarLitTab(void) { return sgHarnessLitTab; }+void SGRNavbarForgetTab(void) {+ if (sgHarnessLitTab) NSLog(@"[harness] the lit tab forgotten");+ sgHarnessLitTab = nil;+}void SGOpenModSettings(UIView *source) {}// Shared/Player/PlayerEvents.x, which TabBarMinimize.x listens to.NSString *const SGPlayerTransitionNotification = @"spotifyglass.playerTransition";diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hindex 4c5098b1..9a3119dc 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.h+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -34,6 +34,10 @@ void SGRLogTabBarRow(UIView *tabBar);void SGRRefreshTabBar(void);// Whether a tab of the composed row is one of the split tabs at its trailing end, for TabBar.x's second bar.BOOL SGRTabIsApart(UIView *item);+// The tab of the mod's own whose page is on screen, which the glass bar shows selected; nil when none is.+UIView *SGRNavbarLitTab(void);+// A tap on one of Spotify's tabs: no tab of the mod's own is lit any more.+void SGRNavbarForgetTab(void);// The glass bar minimizes as a page scrolls down (TabBarMinimize.x): it shrinks to two of its tabs, the// now playing card coming down between them. On unless switched off; read as each scroll goes.diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.x b/tweak/Sources/Redesigned/Navbar/Navbar.xindex 2d260fa9..5b5af6ae 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.x+++ b/tweak/Sources/Redesigned/Navbar/Navbar.x@@ -11,6 +11,10 @@// the stack, past that count, and take a slot with the rest. A tap on one goes through Spotify's// link dispatcher, the same route the app takes for a link it opens itself, so any URI works.//+// The page that link pushes is the tab's: the glass bar lights the tab while that page is on its stack and+// the stack is on screen, and a second tap goes back to the page rather than opening the link again, the+// way a second tap on one of Spotify's tabs goes back to its root.+//// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView// 402x49 of four ElementContentView<TabBarItemElement> 100x49, each an SPTEncoreIconView 24x24// at y 12.5 over an SPTEncoreLabel at y 35.@@ -45,6 +49,18 @@ static NSUInteger sg_apartCount;static UIColor *itemColor(void) { return [UIColor colorWithWhite:0xB3 / 255.0 alpha:1]; }+// A page pushed this soon after a tap on a tab of the mod's own is the page the tab opened.+static const CFTimeInterval kTabPush = 1;+static __weak UIView *sg_tappedTab, *sg_pageTab;+static CFTimeInterval sg_tappedAt;+static __weak UIViewController *sg_tabPage;++static BOOL tabPageShowing(void) {+ UIViewController *page = sg_tabPage;+ UINavigationController *nav = page.navigationController;+ return sg_pageTab && nav.viewIfLoaded.window && [nav.viewControllers containsObject:page];+}+#pragma mark - the mod's own items// Drawn the way Spotify's own are, an Encore glyph or an SF Symbol at the glyphs' size@@ -117,6 +133,19 @@ static UIView *iconView(NSDictionary *entry) {// Through the app's own link dispatcher (Shared/Navigation/Links.h). What the dispatcher makes of the// URI goes to the log first, so a tab that ends in Spotify's "Couldn't open link" says why.- (void)open {+ UIViewController *page = sg_tabPage;+ if (sg_pageTab == self && tabPageShowing()) {+ UINavigationController *nav = page.navigationController;+ if (nav.topViewController != page) [nav popToViewController:page animated:YES];+ SGLog(@"navbar: back to the tab's page %@", NSStringFromClass(page.class));+ return;+ }+ sg_tappedTab = self;+ sg_tappedAt = CACurrentMediaTime();+ // A link that pushes no page leaves the light where Spotify has it.+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((kTabPush + 0.05) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ SGRRefreshTabBar();+ });NSURL *url = SGRNavbarTabURL(self.uri);NSString *via = nil;SGLinkRoute route = SGSpotifyURIRoute(url, &via);@@ -325,6 +354,36 @@ static CGFloat slotCentreX(UIView *view) {}%end+UIView *SGRNavbarLitTab(void) {+ if (tabPageShowing()) return sg_pageTab;+ // From the tap until its page comes, so the bar does not go back to Spotify's tab in between.+ return CACurrentMediaTime() - sg_tappedAt < kTabPush ? sg_tappedTab : nil;+}++void SGRNavbarForgetTab(void) {+ sg_tappedTab = sg_pageTab = nil;+ sg_tabPage = nil;+}++%hook SPNavigationController+- (void)pushViewController:(UIViewController *)page animated:(BOOL)animated {+ UIView *tab = sg_tappedTab;+ if (tab && CACurrentMediaTime() - sg_tappedAt < kTabPush) {+ sg_pageTab = tab;+ sg_tabPage = page;+ sg_tappedTab = nil;+ SGLog(@"navbar: %@ is the tab's page", NSStringFromClass(page.class));+ }+ %orig;+}++// A push, a pop or a swipe back: the bar looks again at whether the tab's page is still up.+- (void)navigationController:(UINavigationController *)controller didShowViewController:(UIViewController *)page animated:(BOOL)animated {+ %orig;+ if (sg_pageTab) SGRRefreshTabBar();+}+%end+BOOL SGRTabIsApart(UIView *item) {return objc_getAssociatedObject(item, &kApartKey) != nil;}@@ -383,6 +442,7 @@ void SGRLogTabBarRow(UIView *tabBar) {if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[+ @"SPNavigationController",@"SPTEncoreIcon",@"SPTEncoreIconView",@"SPTEncoreLabel",diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex 41ae48b1..ea91b23d 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -5,7 +5,8 @@// bar is taller than Spotify's, Spotify is made to leave it the room (see "room for the glass bar").//// A tab picked on the system bar is passed on as a tap on the hidden Spotify item it mirrors, and the-// system bar's selection follows whichever Spotify label is painted white. Navbar.x composes the+// system bar's selection follows whichever Spotify label is painted white, or the tab of the mod's own whose+// page is up (SGRNavbarLitTab), which Spotify does not know of. Navbar.x composes the// hidden row, so its order, hidden tabs and tabs of the mod's own carry over. Always on in the redesign.//// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView of@@ -223,8 +224,11 @@ static void forwardTap(UIView *item) {SGRSetTabBarMinimized(NO, YES);return;}+ // One of Spotify's own takes the light back from a tab of the mod's own.+ UIView *source = self.sources[index];+ if (![NSStringFromClass(source.class) isEqualToString:@"SGRTabItemView"]) SGRNavbarForgetTab();// Home tapped while on Home pops Spotify's stack, which would take Mod Settings straight off it.- if (!self.holding) forwardTap(self.sources[index]);+ if (!self.holding) forwardTap(source);self.partner.selectedItem = nil;self.partner.shown = nil;// Spotify repaints its labels a moment later; a tap it did not take snaps the selection back.@@ -506,7 +510,8 @@ static void syncBar(UIView *stockBar) {// An item with no title is drawn by UIKit as its glyph alone, centred, on a bar of the same height.BOOL hideLabels = SGHidden(SGRKeyNavbarHideLabels);SGRSystemTabBar *apartBar = objc_getAssociatedObject(stockBar, &kApartBarKey);- UIView *active = nil;+ UIView *active = SGRNavbarLitTab();+ if (![sources containsObject:active]) active = nil;for (UIView *source in sources) if (!active && isActive(source)) active = source;active = active ?: selectedSource(bar) ?: selectedSource(apartBar);