Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: open Mod Settings by holding Home on the tab bar

Vojtěch Škopekcd42edf49b53
diff --git a/docs/tweaks.md b/docs/tweaks.md
index bae4e39b..a8e08471 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -69,7 +69,8 @@ out again, as are the Home gradient's colour, strength and height, but not the s
## Mod Settings
-Mod Settings, the first row of the side drawer and the last row of Spotify's Settings, sorts every
+Mod Settings, opened by holding Home on the tab bar or from the first row of the side drawer and the
+last row of Spotify's Settings, sorts every
setting by the part of Spotify it changes, so a part's glass, its hide switches and its flags sit on
one page, the mod's own rows first and Spotify's flags below them or on a sub page named after what
they change. It opens on the Appearance card, the three switches that style the whole app: Liquid
diff --git a/tweak/Sources/Features/Appearance/AppearanceSettings.m b/tweak/Sources/Features/Appearance/AppearanceSettings.m
index a5248416..2204dfa1 100644
--- a/tweak/Sources/Features/Appearance/AppearanceSettings.m
+++ b/tweak/Sources/Features/Appearance/AppearanceSettings.m
@@ -35,7 +35,7 @@ SGModSection *SGAppearanceSection(void) {
glass.changed = ^(BOOL on) { SGSetLiquidGlassUI(on); };
return SGNotedSection(@"Appearance", @[
SGWithSymbol(glass, @"drop"),
- SGWithSymbol(SGOptionRow(@"AMOLED background", @"Pure black instead of Spotify's dark grey", SGKeyAmoled), @"moon"),
- SGWithSymbol(SGStatActionRow(@"Accent colour", @"In place of Spotify's green, everywhere it is drawn", ^NSString *{ return SGAccentLabel(); }, ^{ chooseAccent(); }), @"paintpalette"),
+ SGWithSymbol(SGOptionRow(@"AMOLED background", nil, SGKeyAmoled), @"moon"),
+ SGWithSymbol(SGStatActionRow(@"Accent colour", nil, ^NSString *{ return SGAccentLabel(); }, ^{ chooseAccent(); }), @"paintpalette"),
], @"Liquid Glass UI turns every glass switch of the mod's on or off with it. Changes apply after you restart Spotify.");
}
diff --git a/tweak/Sources/Features/Navbar/NavbarSettings.m b/tweak/Sources/Features/Navbar/NavbarSettings.m
index 17e2cb69..55568c87 100644
--- a/tweak/Sources/Features/Navbar/NavbarSettings.m
+++ b/tweak/Sources/Features/Navbar/NavbarSettings.m
@@ -164,8 +164,8 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {
static NSArray<NSArray<NSString *> *> *glassRows(void) {
return @[
- @[@"Glass tab bar", @"The system glass tab bar in place of Spotify's", SGKeyTabBar],
- @[@"Glass search field", @"A glass capsule instead of the white field on Search", SGKeySearchField],
+ @[@"Glass tab bar", SGKeyTabBar],
+ @[@"Glass search field", SGKeySearchField],
];
}
@@ -256,17 +256,17 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {
switch (path.section) {
case SGNavbarSectionGlass: {
NSArray<NSString *> *row = glassRows()[(NSUInteger)path.row];
- SGFillCell(cell, row[0], row[1], nil, nil);
+ SGFillCell(cell, row[0], nil, nil, nil);
UISwitch *toggle = [UISwitch new];
toggle.onTintColor = SGGreen();
- toggle.on = SGFlag(row[2], NO);
+ toggle.on = SGFlag(row[1], NO);
toggle.tag = path.row;
[toggle addTarget:self action:@selector(glassToggled:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = toggle;
break;
}
case SGNavbarSectionSwitch: {
- SGFillCell(cell, @"Custom navbar", @"Off leaves the bar exactly as Spotify built it", nil, nil);
+ SGFillCell(cell, @"Custom navbar", nil, nil, nil);
UISwitch *toggle = [UISwitch new];
toggle.onTintColor = SGGreen();
toggle.on = SGEnabled(SGKeyNavbar);
@@ -346,7 +346,7 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {
}
- (void)glassToggled:(UISwitch *)toggle {
- SGSetEnabled(glassRows()[(NSUInteger)toggle.tag][2], toggle.on);
+ SGSetEnabled(glassRows()[(NSUInteger)toggle.tag][1], toggle.on);
}
- (void)reset {
diff --git a/tweak/Sources/Features/Navbar/TabBar.x b/tweak/Sources/Features/Navbar/TabBar.x
index 73ab6b5a..2303150d 100644
--- a/tweak/Sources/Features/Navbar/TabBar.x
+++ b/tweak/Sources/Features/Navbar/TabBar.x
@@ -12,15 +12,18 @@
#import "Core/SGCore.h"
#import "Navbar.h"
#import "Features/Appearance/Appearance.h"
+#import "Settings/SGPage.h"
#import "Headers/SPTEncoreIconView.h"
#import <objc/message.h>
static char kBarKey;
static __weak UIView *sg_stockBar;
-@interface SGSystemTabBar : UITabBar <UITabBarDelegate>
+@interface SGSystemTabBar : UITabBar <UITabBarDelegate, UIGestureRecognizerDelegate>
@property (nonatomic, weak) UIView *stockBar;
@property (nonatomic, copy) NSArray<UIView *> *sources;
+@property (nonatomic, weak) UILongPressGestureRecognizer *hold;
+@property (nonatomic) BOOL holding;
@end
static void syncBar(UIView *stockBar);
@@ -38,6 +41,11 @@ static NSArray<UIView *> *tabItems(UIView *tabBar) {
}];
}
+// Navbar.x never reorders Spotify's row and appends the mod's own tabs after it, so Home stays first.
+static BOOL isHome(UIView *item, UIView *tabBar) {
+ return item && item == SGRowIn(tabBar).arrangedSubviews.firstObject;
+}
+
static UILabel *labelIn(UIView *item) {
__block UILabel *label = nil;
SGForEachView(item, ^(UIView *v) {
@@ -174,7 +182,8 @@ static void forwardTap(UIView *item) {
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSUInteger index = [self.items indexOfObject:item];
if (index == NSNotFound || index >= self.sources.count) return;
- forwardTap(self.sources[index]);
+ // Home tapped while on Home pops Spotify's stack, which would take Mod Settings straight off it.
+ if (!self.holding) forwardTap(self.sources[index]);
// Spotify repaints its labels a moment later; a tap it did not take snaps the selection back.
UIView *stockBar = self.stockBar;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -182,8 +191,69 @@ static void forwardTap(UIView *item) {
});
}
+// UIKit's item views are private, so the item under a touch is the one whose title label is nearest.
+- (UITabBarItem *)itemAt:(CGPoint)point {
+ __block UITabBarItem *nearest = nil;
+ __block CGFloat best = CGFLOAT_MAX;
+ SGForEachView(self, ^(UIView *v) {
+ if (![v isKindOfClass:UILabel.class] || v.bounds.size.width < 1) return;
+ CGFloat distance = fabs([v convertPoint:CGPointMake(CGRectGetMidX(v.bounds), 0) toView:self].x - point.x);
+ if (distance >= best) return;
+ for (UITabBarItem *item in self.items) {
+ if (![((UILabel *)v).text isEqualToString:item.title]) continue;
+ best = distance;
+ nearest = item;
+ break;
+ }
+ });
+ return nearest;
+}
+
+// UIView asks itself this for its own recognizers too, so only the hold is answered here.
+- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer {
+ if (recognizer != self.hold) return [super gestureRecognizerShouldBegin:recognizer];
+ NSUInteger index = [self.items indexOfObject:[self itemAt:[recognizer locationInView:self]]];
+ return index < self.sources.count && isHome(self.sources[index], self.stockBar);
+}
+
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)other {
+ return YES;
+}
+
+- (void)held:(UILongPressGestureRecognizer *)hold {
+ if (hold.state == UIGestureRecognizerStateBegan) {
+ self.holding = YES;
+ SGOpenModSettings(self);
+ } else if (hold.state != UIGestureRecognizerStateChanged) {
+ // The bar may still pick Home as the finger lifts, after this.
+ __weak typeof(self) weakSelf = self;
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ weakSelf.holding = NO;
+ });
+ }
+}
+
@end
+@interface SGHomeHold : UILongPressGestureRecognizer
+@end
+
+@implementation SGHomeHold
++ (void)held:(SGHomeHold *)hold {
+ if (hold.state == UIGestureRecognizerStateBegan) SGOpenModSettings(hold.view);
+}
+@end
+
+// On Spotify's own bar a hold that begins fails the item's tap recognizer, so Home is not tapped too.
+static void holdHome(UIView *stockBar) {
+ UIView *home = SGRowIn(stockBar).arrangedSubviews.firstObject;
+ if (!home) return;
+ for (UIGestureRecognizer *recognizer in home.gestureRecognizers) {
+ if ([recognizer isKindOfClass:SGHomeHold.class]) return;
+ }
+ [home addGestureRecognizer:[[SGHomeHold alloc] initWithTarget:SGHomeHold.class action:@selector(held:)]];
+}
+
static void removeBar(UIView *stockBar) {
UIView *bar = objc_getAssociatedObject(stockBar, &kBarKey);
if (!bar) return;
@@ -216,6 +286,10 @@ static void syncBar(UIView *stockBar) {
bar = [[SGSystemTabBar alloc] initWithFrame:stockBar.bounds];
bar.delegate = bar;
bar.stockBar = stockBar;
+ UILongPressGestureRecognizer *hold = [[UILongPressGestureRecognizer alloc] initWithTarget:bar action:@selector(held:)];
+ hold.delegate = bar;
+ [bar addGestureRecognizer:hold];
+ bar.hold = hold;
objc_setAssociatedObject(stockBar, &kBarKey, bar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
bar.tintColor = SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];
@@ -292,6 +366,7 @@ static UIView *tabBarOf(UIView *item) {
for (UIView *sub in ((UIView *)self).subviews) {
if (![sub isKindOfClass:SGSystemTabBar.class]) [sub layoutIfNeeded];
}
+ holdHome((UIView *)self);
syncBar((UIView *)self);
SGLogTabBarRow((UIView *)self);
}
@@ -302,6 +377,7 @@ static void itemDidLayOut(UIView *item) {
UIView *bar = tabBarOf(item);
if (!bar) return;
SGComposeTabBar(bar);
+ holdHome(bar);
syncBar(bar);
SGLogTabBarRow(bar);
}
diff --git a/tweak/Sources/Features/Onboarding/Tour.m b/tweak/Sources/Features/Onboarding/Tour.m
index 1bb179ee..6c368c57 100644
--- a/tweak/Sources/Features/Onboarding/Tour.m
+++ b/tweak/Sources/Features/Onboarding/Tour.m
@@ -363,7 +363,7 @@ static SGTourRow *actionRow(NSString *symbol, NSString *title, NSString *subtitl
lyricsOnly.changed = ^(BOOL on) { SGSetPlayerLyricsOnly(on); };
[pages addObject:[self pageWithSymbol:@"rectangle.compress.vertical" heading:@"Declutter." body:@"The player, down to the music. Every piece has a switch of its own under Player in Mod Settings." rows:@[lyricsOnly]]];
[pages addObject:[self navbarPage]];
- [pages addObject:[self pageWithSymbol:@"slider.horizontal.3" heading:@"Everything lives in Mod Settings." body:@"First row of the side drawer behind your avatar, and the last row of Spotify's Settings. Every switch, the tab bar editor and all of Spotify's flags.\n\nFree and open source. A star is what keeps it going." rows:@[
+ [pages addObject:[self pageWithSymbol:@"slider.horizontal.3" heading:@"Everything lives in Mod Settings." body:@"Hold Home on the tab bar to open it from anywhere. It is also the first row of the side drawer behind your avatar, and the last row of Spotify's Settings. Every switch, the tab bar editor and all of Spotify's flags.\n\nFree and open source. A star is what keeps it going." rows:@[
actionRow(@"star.fill", @"Star on GitHub", @"skopevoj/spoti.pw", ^{ SGOpenURL(SGRepoURL); }),
actionRow(@"square.and.arrow.up", @"Share spoti.pw", @"Send the site to someone", ^{ [weakSelf share]; }),
]]];
diff --git a/tweak/Sources/Settings/SGModSettings.x b/tweak/Sources/Settings/SGModSettings.x
index 5e74607a..9e08eea7 100644
--- a/tweak/Sources/Settings/SGModSettings.x
+++ b/tweak/Sources/Settings/SGModSettings.x
@@ -3,7 +3,7 @@
// part's glass, hide switches and flags (Navbar, Player, Home & Library), Premium, ads & privacy
// and Labs, All flags, a searchable list of every flag with an override per flag, and Mod, the
// build, its updates and links. The same row leads the side drawer's list (trees/test6.txt), above
-// Your plan, so the page is a tap from Home. The tweaks read the switches when they run, so a change
+// Your plan, so the page is a tap from Home, and holding Home on the tab bar opens it too. The tweaks read the switches when they run, so a change
// shows after Spotify restarts; the tab editor on the Navbar page applies as soon as the bar lays
// out again.
//
@@ -128,6 +128,17 @@ static UINavigationController *navigationIn(UIViewController *page) {
@end
+// The tab bar's controller holds no stack itself; the selected tab's sits among its parent's children.
+void SGOpenModSettings(UIView *source) {
+ UIViewController *owner = nil;
+ for (UIResponder *r = source; r && !owner; r = r.nextResponder) {
+ if ([r isKindOfClass:UIViewController.class]) owner = (UIViewController *)r;
+ }
+ UINavigationController *nav = nil;
+ for (UIViewController *page = owner; page && !nav; page = page.parentViewController) nav = navigationIn(page);
+ SGShowPage(nav.topViewController ?: SGTopController(), modSettingsPage());
+}
+
// At the end of the settings list, or above the first row of the drawer's, with the inset for it
// added again whenever Spotify resets the inset.
static void placeRow(UICollectionView *list, SGModSettingsRow *row) {
diff --git a/tweak/Sources/Settings/SGPage.h b/tweak/Sources/Settings/SGPage.h
index 1afe2a50..310459aa 100644
--- a/tweak/Sources/Settings/SGPage.h
+++ b/tweak/Sources/Settings/SGPage.h
@@ -8,3 +8,5 @@
void SGRegisterPages(void);
// Pushes the page if it can go on Spotify's stack, presents it otherwise.
void SGShowPage(UIViewController *owner, UIViewController *page);
+// Mod Settings, pushed onto the selected tab's stack; `source` is any view on the tab bar.
+void SGOpenModSettings(UIView *source);