Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: add lockscreen settings
Vojtěch Škopek7fc3685c8439
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 710eefe5..4eed0a87 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -25,13 +25,14 @@ are read out of Spotify's own binary and belong to whoever built them.## Mod Settings-Settings → Mod Settings has four pages of switches: UI Tweaks (tab bar, search field, Spotify's own+Settings → Mod Settings has five pages of switches: UI Tweaks (tab bar, search field, Spotify's ownglass, AMOLED), Home (a gradient background, hide sections of the Home tab), Playlist (hide the-cover, the header's text and buttons, the curation pills) and Now Playing (glass, a few of Spotify's-player flags, hide buttons and cards of the full screen player). Then Privacy, telemetry blocking-with a count of what it has stopped; Navbar, the tab bar's own composition; and All flags, Spotify's-remote-config flags with a search field and an Auto / Off / On control per flag (a text field for the-number and text ones). A change shows after Spotify restarts.+cover, the header's text and buttons, the curation pills), Now Playing (glass, a few of Spotify's+player flags, hide buttons and cards of the full screen player) and Lock screen widget (the like and+dislike buttons and the rest of Spotify's lock screen flags). Then Privacy, telemetry blocking with a count of what+it has stopped; Navbar, the tab bar's own composition; and All flags, Spotify's remote-config flags+with a search field and an Auto / Off / On control per flag (a text field for the number and text+ones). A change shows after Spotify restarts.Navbar is the exception and applies as soon as the bar lays out again. It lists the tabs in the orderthe bar shows them: drag to reorder, tap to hide or show, and Add a tab puts a page of Spotify's ordiff --git a/tweak/src/ui/Navbar.x b/tweak/src/ui/Navbar.xindex cfab01ae..fd02a145 100644--- a/tweak/src/ui/Navbar.x+++ b/tweak/src/ui/Navbar.x@@ -4,11 +4,11 @@// the left, not by asking the item what it is: moved in the stack, an item takes the tap of// whatever used to stand there. So the stack's own order is left exactly as Spotify built it.//-// The row is split into equal slots instead, and the wanted order is a translation per item:-// hit testing goes by frame, so the touch follows the icon, while Spotify still counts its items-// off in the order it put them in. Items of the mod's own go on the end of the stack, past that-// count, and are translated into place 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 row is split into equal slots instead, and each item is given the frame of its slot after+// the stack's own pass: hit testing goes by frame, so the touch follows the icon, while Spotify+// still counts its items off in the order it put them in. Items of the mod's own go on the end of+// 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.//// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView// 402x49 of four ElementContentView<TabBarItemElement> 100x49, each an SPTEncoreIconView 24x24@@ -30,7 +30,7 @@ static const CGFloat kIconSize = 24;static const CGFloat kIconTop = 12.5;static const CGFloat kLabelTop = 35;static const CGFloat kLabelHeight = 14;-static char kCustomKey;+static char kCustomKey, kOrderKey;// Where Spotify's own items keep their icon and label, read off one of them every pass. ui/TabBar.x// moves the icons when the glass bar is on, and this follows a pass later, so an item of the mod's@@ -40,6 +40,8 @@ static CGRect sg_labelBox = {{0, kLabelTop}, {0, kLabelHeight}};static __weak SGLinkDispatcher *sg_linkDispatcher;static __weak UIView *sg_navbarRoot;+// The bar's row of items, given its frames by placeRow after each of its own passes.+static __weak UIStackView *sg_row;static UIFont *sg_tabFont;// Spotify's own tabs in Spotify's order, from the first layout pass of this launch, before// anything below has moved them.@@ -241,25 +243,77 @@ void SGComposeTabBar(UIView *tabBar) {for (UIView *item in wanted) {if ([item isKindOfClass:SGTabItemView.class] && item.superview != stack) [stack addArrangedSubview:item];}- // Spotify sizes the row for the four items it ships; equal slots for whatever is on it now- // keeps a fifth from running off the right edge, and makes the order a whole slot's shift.- if (stack.distribution != UIStackViewDistributionFillEqually) stack.distribution = UIStackViewDistributionFillEqually;-- NSMutableArray<UIView *> *slots = [NSMutableArray array];- for (UIView *item in stack.arrangedSubviews) if (!item.hidden) [slots addObject:item];NSMutableArray<UIView *> *order = [NSMutableArray array];- for (UIView *item in wanted) if (!item.hidden && [slots containsObject:item]) [order addObject:item];- CGFloat slotWidth = slots.count ? stack.bounds.size.width / slots.count : 0;-- for (UIView *item in stack.arrangedSubviews) {- NSUInteger from = [slots indexOfObject:item], to = [order indexOfObject:item];- CGAffineTransform shift = from == NSNotFound || to == NSNotFound- ? CGAffineTransformIdentity- : CGAffineTransformMakeTranslation(((CGFloat)to - (CGFloat)from) * slotWidth, 0);- if (!CGAffineTransformEqualToTransform(item.transform, shift)) item.transform = shift;+ for (UIView *item in wanted) if (!item.hidden && item.superview == stack) [order addObject:item];+ sg_row = stack;+ if (![order isEqualToArray:objc_getAssociatedObject(stack, &kOrderKey)]) {+ objc_setAssociatedObject(stack, &kOrderKey, order, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ [stack setNeedsLayout];}}+// Equal slots across the bar, in the order composed above. The frames go on after the stack's+// own pass, so Spotify's own widths never decide whether a fifth item fits.+static void placeRow(UIStackView *stack) {+ NSArray<UIView *> *order = objc_getAssociatedObject(stack, &kOrderKey);+ UIView *bar = sg_navbarRoot;+ if (!order.count || !bar) return;+ CGFloat width = bar.bounds.size.width / order.count;+ CGFloat height = stack.bounds.size.height;+ [order enumerateObjectsUsingBlock:^(UIView *item, NSUInteger i, BOOL *stop) {+ CGFloat x = [bar convertPoint:CGPointMake(i * width, 0) toView:stack].x;+ CGRect frame = CGRectMake(x, 0, width, height);+ if (!CGAffineTransformIsIdentity(item.transform)) item.transform = CGAffineTransformIdentity;+ if (!CGRectEqualToRect(item.frame, frame)) item.frame = frame;+ }];+}++%hook UIStackView+- (void)layoutSubviews {+ %orig;+ if ((UIStackView *)self == sg_row) placeRow((UIStackView *)self);+}+%end++// Spotify's element layout places the icon and the label from the width it measured, not from+// the slot above (trees/test5.txt: x 38 in a 134pt element in a 126pt slot), and a view placed by+// its parent gets no layout pass of its own. So the placement itself is bent: on the bar, whatever+// x Spotify sets, the view lands centred on its slot.+static CGFloat slotCentreX(UIView *view) {+ UIStackView *row = sg_row;+ if (!row) return NAN;+ UIView *slot = nil;+ for (UIView *v = view; v.superview; v = v.superview) if (v.superview == row) { slot = v; break; }+ if (!slot) return NAN;+ return [slot convertPoint:CGPointMake(CGRectGetMidX(slot.bounds), 0) toView:view.superview].x;+}++%hook SPTEncoreIconView+- (void)setFrame:(CGRect)frame {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) frame.origin.x = centre - frame.size.width / 2;+ %orig(frame);+}+- (void)setCenter:(CGPoint)center {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) center.x = centre;+ %orig(center);+}+%end++%hook SPTEncoreLabel+- (void)setFrame:(CGRect)frame {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) frame.origin.x = centre - frame.size.width / 2;+ %orig(frame);+}+- (void)setCenter:(CGPoint)center {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) center.x = centre;+ %orig(center);+}+%end+void SGRefreshTabBar(void) {[sg_navbarRoot setNeedsLayout];}@@ -276,8 +330,8 @@ void SGLogTabBarRow(UIView *tabBar) {!stack.translatesAutoresizingMaskIntoConstraints];NSUInteger index = 0;for (UIView *item in stack.arrangedSubviews) {- [out appendFormat:@"\n %lu %@ %@%@ shift %.1f autolayout %d", (unsigned long)index++, NSStringFromClass(item.class),- NSStringFromCGRect(item.frame), item.hidden ? @" hidden" : @"", item.transform.tx,+ [out appendFormat:@"\n %lu %@ %@%@ autolayout %d", (unsigned long)index++, NSStringFromClass(item.class),+ NSStringFromCGRect(item.frame), item.hidden ? @" hidden" : @"",!item.translatesAutoresizingMaskIntoConstraints];for (NSLayoutConstraint *c in item.constraints) {if (c.firstAttribute == NSLayoutAttributeWidth || c.secondAttribute == NSLayoutAttributeWidth) [out appendFormat:@"\n %@", c];@@ -324,6 +378,7 @@ void SGLogTabBarRow(UIView *tabBar) {@"SPTLinkDispatcherImplementation",@"SPTEncoreIcon",@"SPTEncoreIconView",+ @"SPTEncoreLabel",@"_TtC28NavigationUI_TabBarItemsImpl29TabBarItemsNavigationListImpl",]);}diff --git a/tweak/src/ui/Settings.x b/tweak/src/ui/Settings.xindex 5081a3b6..8cd2126f 100644--- a/tweak/src/ui/Settings.x+++ b/tweak/src/ui/Settings.x@@ -945,6 +945,9 @@ static UIViewController *nowPlayingPage(void) {flagRow(@"Picture in picture", @"ios-feature-nowplaying.picture_in_picture"),flagRow(@"Video in the mini player", @"ios-feature-nowplaying.video_in_miniplayer"),]),+ section(@"Lock screen", @[+ flagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled"),+ ]),section(@"Hide buttons", @[hideRow(@"Shuffle", @"Left of the playback controls", SGHideShuffle),hideRow(@"Repeat", @"Right of the playback controls", SGHideRepeat),@@ -970,6 +973,20 @@ static UIViewController *nowPlayingPage(void) {] footer:nil];}+static UIViewController *lockScreenPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Lock screen widget" intro:kRestart sections:@[+ section(@"Spotify's flags", @[+ flagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled"),+ flagRow(@"Animated artwork", @"ios-feature-lockscreen.animated_artwork_enabled"),+ flagRow(@"Video artwork", @"ios-feature-lockscreen.vit_artwork_enabled"),+ flagRow(@"Companion content", @"ios-feature-lockscreen.companion_content_enabled"),+ flagRow(@"Burst skip", @"ios-feature-lockscreen.burst_skip_enabled"),+ flagRow(@"Chapter skip controls", @"ios-feature-lockscreen.enable_chapter_skip_controls"),+ flagRow(@"Skip button on podcasts", @"ios-feature-lockscreen.skip_button_on_podcasts"),+ ]),+ ] footer:nil];+}+static UIViewController *privacyPage(void) {NSMutableArray<SGModRow *> *counts = [NSMutableArray array];for (NSString *label in SGBlockedLabels()) {@@ -1017,6 +1034,7 @@ static UIViewController *modSettingsPage(void) {pageRow(@"Home", @"Gradient background, hide sections of the Home tab", ^UIViewController *{ return homePage(); }),pageRow(@"Playlist", @"Hide the cover, the header buttons and the pills", ^UIViewController *{ return playlistPage(); }),pageRow(@"Now Playing", @"Glass, Spotify's player flags, hide buttons and cards", ^UIViewController *{ return nowPlayingPage(); }),+ pageRow(@"Lock screen widget", @"The like and dislike buttons on the lock screen", ^UIViewController *{ return lockScreenPage(); }),pageRow(@"Privacy", @"Block telemetry, and what it has blocked so far", ^UIViewController *{ return privacyPage(); }),pageRow(@"All flags", @"Search and force any of Spotify's remote-config flags", ^UIViewController *{ return [SGFlagsPage new]; }),]),