Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
refactor: split the tweak into core, settings and feature modules
Vojtěch Škopekf9387335e523
diff --git a/.editorconfig b/.editorconfignew file mode 100644index 00000000..1518c00f--- /dev/null+++ b/.editorconfig@@ -0,0 +1,15 @@+root = true++[*]+charset = utf-8+end_of_line = lf+insert_final_newline = true+trim_trailing_whitespace = true+indent_style = space+indent_size = 4++[Makefile]+indent_style = tab++[*.{yml,yaml,json}]+indent_size = 2diff --git a/.gitignore b/.gitignoreindex d0381ffa..9bec29af 100644--- a/.gitignore+++ b/.gitignore@@ -12,4 +12,4 @@ trees/*.txttweak/.theos/tweak/obj/tweak/packages/-tweak/src/SGFlagList.m+tweak/Sources/Features/Flags/SGFlagList.mdiff --git a/Makefile b/Makefileindex 02f037a0..251f190e 100644--- a/Makefile+++ b/Makefile@@ -18,5 +18,5 @@ trees: ## record per-screen view trees into trees/ (needs a FLEX build on the./scripts/record-trees.pylog: ## stream the tweak's log lines from the phone./scripts/dump-log.sh-flags: ## regenerate tweak/src/SGFlagList.m, Spotify's remote-config flags, from the IPA+flags: ## regenerate tweak/Sources/Features/Flags/SGFlagList.m, Spotify's remote-config flags, from the IPA./scripts/extract-flags.py $(IPA)diff --git a/README.md b/README.mdindex 673348e7..4eda725c 100644--- a/README.md+++ b/README.md@@ -86,7 +86,7 @@ Put the decrypted `.ipa` in `ipa/`, then:`.signing.env.example` and fill it in. `BUNDLE_ID=` overrides the bundle id.The first build spends about a minute reading Spotify's remote-config flags out of your IPA into-`tweak/src/SGFlagList.m`, so the flag list always matches the Spotify you built from. Later builds+`tweak/Sources/Features/Flags/SGFlagList.m`, so the flag list always matches the Spotify you built from. Later buildsreuse it; `make flags` regenerates it.## Mod Settingsdiff --git a/docs/tweaks.md b/docs/tweaks.mdindex 990266de..2200f4f5 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -2,16 +2,49 @@## Layout- tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, HomeGradient, Declutter, Playlist, Repaint, Settings- tweak/src/SG* shared helpers (glass panes, view walking, logging, screen dumps) and SGPrivacy, the telemetry blocking- scripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py, dump-log.sh, extract-flags.py- trees/ recorded view trees, one per screen; the input for every new tweak- plist/ Info.plist overrides merged into the app (turns UIDesignRequiresCompatibility off)- vendor/ AutoFLEX deb- ipa/, out/ decrypted Spotify IPA in, built IPAs out (both gitignored)+ tweak/ the Theos project: Makefile, control, the bundle filter plist+ tweak/Sources/Core/ what every file builds on: logging, preferences, view-tree walking, glass panes,+ runtime declarations of iOS 26 API (SGCore.h imports all of it)+ tweak/Sources/Headers/ reverse-engineered Spotify classes, one header each, only the selectors used+ tweak/Sources/Settings/ the Mod Settings framework: SGPage (a page on Spotify's stack), SGModPage (sections+ of rows), SGPageStyle (Spotify's list look), SGModSettings.x (the root page and+ the row that opens it from Spotify's settings)+ tweak/Sources/Features/ one directory per feature, see below+ tweak/Sources/Diagnostics/ screen dumps and the tree server of FLEX builds+ scripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py,+ dump-log.sh, extract-flags.py, make-manifests.py+ trees/ recorded view trees, one per screen; the input for every new hook+ plist/ Info.plist overrides merged into the app (turns UIDesignRequiresCompatibility off)+ site/ the manifests spoti.pw serves (version.json, AltStore and Scarlet sources)+ vendor/ AutoFLEX deb+ ipa/, out/ decrypted Spotify IPA in, built IPAs out (both gitignored)-`tweak/src/SGFlagList.m` is generated from the IPA and gitignored, as are the recorded trees: both-are read out of Spotify's own binary and belong to whoever built them.+`tweak/Sources/Features/Flags/SGFlagList.m` is generated from the IPA and gitignored, as are the+recorded trees: both are read out of Spotify's own binary and belong to whoever built them.++## Features++A feature is a directory under `tweak/Sources/Features/` holding everything about one area of the+app:++ <Feature>.h the keys of its switches, and the functions other files may call+ <Something>.x the hooks, one file per screen or mechanism, each ending in its own %ctor+ <Feature>Settings.m its Mod Settings page, built from the rows in Settings/SGModPage.h+ <Model>.m plain Objective-C the hooks and the page share, where there is any++ NowPlaying/ the glass bar (NowPlayingBar.x), the full screen player (Player.x), the lyrics card and page (Lyrics.x)+ Navbar/ the glass tab bar (TabBar.x) and its composition (Navbar.x, NavbarLayout.m), the Navbar and Add a tab pages+ Home/ the Home gradient+ Playlist/ the playlist header and pills, hidden one switch each+ Declutter/ cards under the player and sections of Home collapsed, player buttons hidden; rows on the Now Playing and Home pages+ Appearance/ AMOLED (Amoled.x), the glass search field (SearchField.x), and Repaint.x, which keeps stripped areas transparent+ Flags/ Spotify's remote-config flags: the provider hook, the generated table, the All flags page and the topic pages+ Privacy/ telemetry blocking and its counters+ About/ the update check and the About section of the root page++A hook reads its switch when it runs (`SGEnabled`, `SGHidden`, `SGFlag` from Core/SGPrefs.h), so a+change shows after Spotify restarts; Navbar is the exception and applies as soon as the bar lays+out again. The root page in `Settings/SGModSettings.x` lists every feature's page by hand.## Make targets@@ -21,7 +54,7 @@ are read out of Spotify's own binary and belong to whoever built them.make install FLEX=1 # the same with FLEX, which is what make trees reads throughmake trees # record view trees screen by screen (FLEX build open on the phone, USB)make log # stream [spotifyglass] log lines from the phone- make flags # regenerate tweak/src/SGFlagList.m from the IPA+ make flags # regenerate the flag table from the IPA## Mod Settings@@ -41,7 +74,7 @@ its newer design behind several flags at once, so UI Tweaks > Spotify's own Liqu(the glass navigation bar, the new player slider, the sheet style player, the queue and Connectsheets, the redesigned player header, the sleep timer's options sheet): while it is on it forceseach of them, and their rows elsewhere show what it forces and take no touch, so the group has one-switch. `SGGlassOwnsFlag` in SGCommon.m holds the list. A change shows after Spotify restarts.+switch. `SGGlassOwnsFlag` in Features/Flags/Flags.x holds the list. 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 or@@ -50,10 +83,18 @@ name under their icon, so they can be hidden but never removed, and switching thstarts the order over. A tab of the mod's own opens its link through Spotify's link dispatcher, so itnever lights up as the tab you are on.-## Adding a tweak+## Adding a feature1. `make trees`, record the screen, read `trees/<screen>.txt` for the classes and frames.-2. Add `tweak/src/ui/<Area>.x`: hook the classes, use `SGGlassFor`/`SGGlassAt` + `SGShapeGlass` for- glass, `SGStripBackgrounds` to clear Spotify's paint, and end with `%ctor { %init; SGRequireClasses(...); }`.-3. `make install`. Log lines are prefixed `[spotifyglass]`. A FLEX build serves the visible screen's+2. Make `tweak/Sources/Features/<Feature>/` with `<Feature>.h` declaring the switch key+ (`#define SGKey<Feature> @"spotifyglass.<feature>"`) and `UIViewController *SG<Feature>SettingsPage(void)`.+3. Add the hooks in `<Screen>.x`: `#import "Core/SGCore.h"` and the feature header, guard on the+ switch, use `SGGlassFor`/`SGGlassAt` + `SGShapeGlass` for glass and `SGStripBackgrounds` to clear+ Spotify's paint, and end with `%ctor { %init; SGRequireClasses(@[...]); }`.+4. Add `<Feature>Settings.m` returning an `SGModPage` of `SGSection`s of `SGSwitchRow`/`SGHideRow`/+ `SGFlagRow` (Settings/SGModPage.h), and list it in `Settings/SGModSettings.x`.+5. `make install`. Log lines are prefixed `[spotifyglass]`. A FLEX build serves the visible screen'stree on the phone's port 8085, which `make trees` reaches over USB through iproxy.++A class Spotify has renamed shows up in the log as `class X not found, its hooks are inactive`;+declare the classes a feature needs in `Headers/` only when a hook calls into them by type.diff --git a/scripts/extract-flags.py b/scripts/extract-flags.pyindex e27e59f9..95bac9af 100755--- a/scripts/extract-flags.py+++ b/scripts/extract-flags.py@@ -1,5 +1,5 @@#!/usr/bin/env python3-"""Write tweak/src/SGFlagList.m, the table of Spotify's remote-config flags, from a decrypted IPA.+"""Write tweak/Sources/Features/Flags/SGFlagList.m, the table of Spotify's remote-config flags, from a decrypted IPA.Every generated SPT*ImplProperties class reads its flags in initWithConfigurationProvider: throughboolValueForId:defaultValue:, intValueForId:lower:upper:defaultValue: or@@ -247,12 +247,12 @@ def main():info = next(n for n in z.namelist() if re.fullmatch(r'Payload/[^/]+\.app/Info\.plist', n))version = plistlib.loads(z.read(info))['CFBundleShortVersionString']lines = [f'// Generated by scripts/extract-flags.py from Spotify {version}. Do not edit.',- '#import "SGCommon.h"', '', 'const SGFlagDef SGFlagTable[] = {']+ '#import "Flags.h"', '', 'const SGFlagDef SGFlagTable[] = {']for key in sorted(flags):kind, value, lower, upper = flags[key]lines.append(f' {{"{key}", SGFlag{kind}, {signed(value)}, {signed(lower)}, {signed(upper)}}},')lines += ['};', 'const NSUInteger SGFlagCount = sizeof(SGFlagTable) / sizeof(*SGFlagTable);', '']- out = ROOT / 'tweak/src/SGFlagList.m'+ out = ROOT / 'tweak/Sources/Features/Flags/SGFlagList.m'out.write_text('\n'.join(lines))typed = sum(1 for f in flags.values() if f[0] != 'Unknown')print(f'{out.relative_to(ROOT)}: {len(flags)} flags, {typed} with a type and default')diff --git a/scripts/pipeline.sh b/scripts/pipeline.shindex 961c2028..b12beadf 100755--- a/scripts/pipeline.sh+++ b/scripts/pipeline.sh@@ -46,7 +46,7 @@ OUT="${OUT:-$ROOT/out/Spotify-$VERSION-glass.ipa}"echo "==> Spotify $VERSION -> $OUT"# The flag table is generated rather than committed, so it always matches the IPA being built.-if [ ! -f "$ROOT/tweak/src/SGFlagList.m" ]; then+if [ ! -f "$ROOT/tweak/Sources/Features/Flags/SGFlagList.m" ]; thenecho "==> extracting the flag table (once, about 40 s)""$ROOT/scripts/extract-flags.py" "$IN"fidiff --git a/tweak/Makefile b/tweak/Makefileindex 4334551a..60320c07 100644--- a/tweak/Makefile+++ b/tweak/Makefile@@ -1,4 +1,4 @@-TARGET := iphone:clang:16.5:16.0+TARGET := iphone:clang:latest:16.0ARCHS := arm64FINALPACKAGE := 1@@ -8,8 +8,10 @@ TWEAK_NAME := spotifyglassSG_VERSION := $(shell sed -n 's/^Version: //p' control)-spotifyglass_FILES := $(wildcard src/*.m) $(wildcard src/*.x) $(wildcard src/ui/*.x)-spotifyglass_CFLAGS := -fobjc-arc -Isrc -DSG_VERSION=\"$(SG_VERSION)\"+# Every source under Sources/, so a new feature needs no Makefile edit. Features/Flags/SGFlagList.m+# is generated from the IPA by scripts/extract-flags.py.+spotifyglass_FILES := $(shell find Sources -name '*.m' -o -name '*.x' | sort)+spotifyglass_CFLAGS := -fobjc-arc -ISources -DSG_VERSION=\"$(SG_VERSION)\"spotifyglass_FRAMEWORKS := UIKit QuartzCore# Runtime swizzling instead of Substrate so the dylib has no extra dependency inside the IPA.spotifyglass_LOGOS_DEFAULT_GENERATOR := internaldiff --git a/tweak/Sources/Core/SGCore.h b/tweak/Sources/Core/SGCore.hnew file mode 100644index 00000000..8014aecd--- /dev/null+++ b/tweak/Sources/Core/SGCore.h@@ -0,0 +1,7 @@+// What every source file of the mod builds on. Feature-specific API lives in the feature's own+// header under Features/, next to the keys it reads.+#import "Core/SGRuntime.h"+#import "Core/SGLog.h"+#import "Core/SGPrefs.h"+#import "Core/SGViewTree.h"+#import "Core/SGGlass.h"diff --git a/tweak/Sources/Core/SGGlass.h b/tweak/Sources/Core/SGGlass.hnew file mode 100644index 00000000..cb97969c--- /dev/null+++ b/tweak/Sources/Core/SGGlass.h@@ -0,0 +1,25 @@+// Glass panes: one UIVisualEffectView per host, kept behind the host's own content.+#import <UIKit/UIKit.h>++UIVisualEffectView *SGGlassFor(UIView *host, const void *key);+// Several panes on one host, addressed by index; panes past `count` are hidden by SGHideGlassFrom.+UIVisualEffectView *SGGlassAt(UIView *host, NSUInteger index);+void SGHideGlassFrom(UIView *host, NSUInteger count);+// Glass takes its shape from cornerConfiguration on iOS 26; layer.cornerRadius is the fallback.+void SGShapeGlass(UIView *glass, CGFloat radius, BOOL capsule);++// Areas kept transparent by Features/Appearance/Repaint.x, set by the features that own them.+extern __weak UIView *sg_nowPlayingRoot;+extern __weak UIView *sg_tabBarRoot;+extern __weak UIView *sg_nowPlayingCard;+extern __weak UIView *sg_lyricsCardRoot;+extern __weak UIView *sg_lyricsPageRoot;+extern __weak UIView *sg_homeRoot; // Home/HomeGradient.x, the base surface only+extern __weak UIView *sg_npvBackdropRoot; // NowPlaying/Player.x, the plane behind the player++// The full screen player morphs the now playing bar's own card into the cover art, so for the+// length of that animation NowPlaying/NowPlayingBar.x hands the bar back to Spotify: the flag lets+// the album colour through Repaint.x again, and the last colour it took off is kept to restore.+extern BOOL sg_nowPlayingStock;+extern CGColorRef sg_nowPlayingCardColor;+void SGRememberCardColor(CGColorRef color);diff --git a/tweak/Sources/Core/SGGlass.m b/tweak/Sources/Core/SGGlass.mnew file mode 100644index 00000000..647763b8--- /dev/null+++ b/tweak/Sources/Core/SGGlass.m@@ -0,0 +1,90 @@+#import "SGGlass.h"+#import "SGRuntime.h"++__weak UIView *sg_nowPlayingRoot = nil;+__weak UIView *sg_tabBarRoot = nil;+__weak UIView *sg_nowPlayingCard = nil;+__weak UIView *sg_lyricsCardRoot = nil;+__weak UIView *sg_lyricsPageRoot = nil;+__weak UIView *sg_homeRoot = nil;+__weak UIView *sg_npvBackdropRoot = nil;++BOOL sg_nowPlayingStock = NO;+CGColorRef sg_nowPlayingCardColor = NULL;++// Only the main thread writes it, so the read in NowPlayingBar.x cannot see a released colour.+void SGRememberCardColor(CGColorRef color) {+ if (!NSThread.isMainThread || color == sg_nowPlayingCardColor) return;+ CGColorRef kept = color ? CGColorRetain(color) : NULL;+ CGColorRelease(sg_nowPlayingCardColor);+ sg_nowPlayingCardColor = kept;+}++// +effectWithStyle: is the only initialiser UIGlassEffect has; a bare -init leaves the material+// unresolved and the pane renders as a plain blur, while the capsule shape, which is the view's+// own property, still comes out right. Spotify's own Reprise glass builds its effect the same way.+static UIVisualEffect *glassEffect(void) {+ Class glass = NSClassFromString(@"UIGlassEffect");+ if ([glass respondsToSelector:@selector(effectWithStyle:)]) return [glass effectWithStyle:0];+ return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterialDark];+}++static UIVisualEffectView *newPane(void) {+ UIVisualEffectView *glass = [[UIVisualEffectView alloc] initWithEffect:glassEffect()];+ glass.userInteractionEnabled = NO;+ // A pane goes in at index 0, but a host that rebuilds its content puts that in at index 0 too+ // and the pane would end up over it. Depth keeps a pane behind whatever the host draws.+ glass.layer.zPosition = -1;+ return glass;+}++UIVisualEffectView *SGGlassFor(UIView *host, const void *key) {+ UIVisualEffectView *glass = objc_getAssociatedObject(host, key);+ if (!glass) {+ glass = newPane();+ objc_setAssociatedObject(host, key, glass, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ if (glass.superview != host) [host insertSubview:glass atIndex:0];+ return glass;+}++static char kPanesKey;++UIVisualEffectView *SGGlassAt(UIView *host, NSUInteger index) {+ NSMutableArray<UIVisualEffectView *> *panes = objc_getAssociatedObject(host, &kPanesKey);+ if (!panes) {+ panes = [NSMutableArray array];+ objc_setAssociatedObject(host, &kPanesKey, panes, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ while (panes.count <= index) [panes addObject:newPane()];+ UIVisualEffectView *glass = panes[index];+ glass.hidden = NO;+ if (glass.superview != host) [host insertSubview:glass atIndex:0];+ return glass;+}++void SGHideGlassFrom(UIView *host, NSUInteger count) {+ NSArray<UIVisualEffectView *> *panes = objc_getAssociatedObject(host, &kPanesKey);+ for (NSUInteger i = count; i < panes.count; i++) panes[i].hidden = YES;+}++void SGShapeGlass(UIView *glass, CGFloat radius, BOOL capsule) {+ Class config = NSClassFromString(@"UICornerConfiguration");+ Class cornerRadius = NSClassFromString(@"UICornerRadius");+ id shape = nil;+ if (config && [glass respondsToSelector:@selector(setCornerConfiguration:)]) {+ if (capsule && [config respondsToSelector:@selector(capsuleConfiguration)]) {+ shape = [config capsuleConfiguration];+ } else if ([config respondsToSelector:@selector(configurationWithUniformRadius:)] && [cornerRadius respondsToSelector:@selector(fixedRadius:)]) {+ shape = [config configurationWithUniformRadius:[cornerRadius fixedRadius:radius]];+ }+ }+ if (shape) {+ [glass setCornerConfiguration:shape];+ glass.clipsToBounds = NO;+ } else {+ glass.layer.cornerRadius = capsule ? glass.bounds.size.height / 2 : radius;+ glass.layer.cornerCurve = kCACornerCurveContinuous;+ glass.clipsToBounds = YES;+ }+}diff --git a/tweak/Sources/Core/SGLog.h b/tweak/Sources/Core/SGLog.hnew file mode 100644index 00000000..2d8c6b3a--- /dev/null+++ b/tweak/Sources/Core/SGLog.h@@ -0,0 +1,10 @@+#import <Foundation/Foundation.h>+#import <os/log.h>++// %{public}s so idevicesyslog on the Mac sees the text instead of <private>.+#define SGLog(fmt, ...) os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_DEFAULT, "[spotifyglass] %{public}s", [NSString stringWithFormat:(fmt), ##__VA_ARGS__].UTF8String)++// Long dumps, split into numbered parts under the unified log's size cap.+void SGLogLong(NSString *tag, NSString *text);+// Logs every class of the list that this Spotify does not have; a feature calls it from its %ctor.+void SGRequireClasses(NSArray<NSString *> *names);diff --git a/tweak/Sources/Core/SGLog.m b/tweak/Sources/Core/SGLog.mnew file mode 100644index 00000000..a0144e8d--- /dev/null+++ b/tweak/Sources/Core/SGLog.m@@ -0,0 +1,24 @@+#import "SGLog.h"++// The unified log cuts a message at about 1 KB, so long dumps go out as numbered parts.+void SGLogLong(NSString *tag, NSString *text) {+ NSMutableArray<NSString *> *parts = [NSMutableArray array];+ NSMutableString *current = [NSMutableString string];+ for (NSString *line in [text componentsSeparatedByString:@"\n"]) {+ if (current.length && [current lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + [line lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > 900) {+ [parts addObject:[current copy]];+ [current setString:@""];+ }+ [current appendFormat:@"%@\n", line];+ }+ if (current.length) [parts addObject:current];+ [parts enumerateObjectsUsingBlock:^(NSString *part, NSUInteger i, BOOL *stop) {+ SGLog(@"%@ %lu/%lu\n%@", tag, (unsigned long)i + 1, (unsigned long)parts.count, part);+ }];+}++void SGRequireClasses(NSArray<NSString *> *names) {+ for (NSString *name in names) {+ if (!NSClassFromString(name)) SGLog(@"class %@ not found, its hooks are inactive", name);+ }+}diff --git a/tweak/Sources/Core/SGPrefs.h b/tweak/Sources/Core/SGPrefs.hnew file mode 100644index 00000000..0dec37d8--- /dev/null+++ b/tweak/Sources/Core/SGPrefs.h@@ -0,0 +1,14 @@+// The mod's own settings, in Spotify's NSUserDefaults. Every key is declared by the feature that+// owns it, in that feature's header; the accessors here are what the hooks and the pages share.+#import <Foundation/Foundation.h>++BOOL SGFlag(NSString *key, BOOL fallback);+BOOL SGEnabled(NSString *key); // an unset switch is on+BOOL SGHidden(NSString *key); // an unset switch is off+void SGSetEnabled(NSString *key, BOOL on);++// Overrides of Spotify's remote-config flags, stored under SGFlagOverridePrefix + flag key;+// nil keeps Spotify's value. Features/Flags reads them, the All flags page and flag rows write them.+extern NSString *const SGFlagOverridePrefix;+id SGFlagOverride(NSString *key);+void SGSetFlagOverride(NSString *key, id value);diff --git a/tweak/Sources/Core/SGPrefs.m b/tweak/Sources/Core/SGPrefs.mnew file mode 100644index 00000000..706a1400--- /dev/null+++ b/tweak/Sources/Core/SGPrefs.m@@ -0,0 +1,30 @@+#import "SGPrefs.h"++BOOL SGFlag(NSString *key, BOOL fallback) {+ id value = [NSUserDefaults.standardUserDefaults objectForKey:key];+ return value ? [value boolValue] : fallback;+}++BOOL SGEnabled(NSString *key) {+ return SGFlag(key, YES);+}++BOOL SGHidden(NSString *key) {+ return SGFlag(key, NO);+}++void SGSetEnabled(NSString *key, BOOL on) {+ [NSUserDefaults.standardUserDefaults setBool:on forKey:key];+}++NSString *const SGFlagOverridePrefix = @"spotifyglass.flag.";++id SGFlagOverride(NSString *key) {+ return [NSUserDefaults.standardUserDefaults objectForKey:[SGFlagOverridePrefix stringByAppendingString:key]];+}++void SGSetFlagOverride(NSString *key, id value) {+ key = [SGFlagOverridePrefix stringByAppendingString:key];+ if (value) [NSUserDefaults.standardUserDefaults setObject:value forKey:key];+ else [NSUserDefaults.standardUserDefaults removeObjectForKey:key];+}diff --git a/tweak/Sources/Core/SGRuntime.h b/tweak/Sources/Core/SGRuntime.hnew file mode 100644index 00000000..ed0c7ca5--- /dev/null+++ b/tweak/Sources/Core/SGRuntime.h@@ -0,0 +1,25 @@+// Declarations the SDK Theos builds against does not have: iOS 26 API and private UIKit.+// Everything here is resolved at runtime; a call site checks respondsToSelector: first.+#import <UIKit/UIKit.h>+#import <objc/runtime.h>++@interface UIGlassEffect : UIVisualEffect++ (instancetype)effectWithStyle:(NSInteger)style;+@property (nonatomic, copy) UIColor *tintColor;+@property (nonatomic, getter=isInteractive) BOOL interactive;+@end++@interface NSObject (SGiOS26)++ (id)capsuleConfiguration;++ (id)configurationWithUniformRadius:(id)radius;++ (id)fixedRadius:(CGFloat)radius;+- (void)setCornerConfiguration:(id)configuration;+@end++@interface UIView (SGPrivate)+- (NSString *)recursiveDescription;+@end++@interface UIViewController (SGPrivate)+- (NSString *)_printHierarchy;+@enddiff --git a/tweak/Sources/Core/SGViewTree.h b/tweak/Sources/Core/SGViewTree.hnew file mode 100644index 00000000..dc4d1325--- /dev/null+++ b/tweak/Sources/Core/SGViewTree.h@@ -0,0 +1,23 @@+// Walking and reading Spotify's view trees.+#import <UIKit/UIKit.h>++void SGForEachView(UIView *view, void (^fn)(UIView *));+CGRect SGFrameIn(UIView *view, UIView *target);+// Whether `view` sits under `root`, stopping at a visual effect view on the way up.+BOOL SGIsInside(UIView *view, UIView *root);+// The first wide stack view under `host` with at least two arranged children: a player row, or+// the row of items in the tab bar.+UIStackView *SGRowIn(UIView *host);+// Whether any view under `root` has `marker` in its class name.+BOOL SGHasClass(UIView *root, NSString *marker);++// Artwork, glyphs, text and thin lines (progress bar) keep their colour, everything else goes clear.+BOOL SGKeepsColor(UIView *view);+void SGStripBackgrounds(UIView *view);+BOOL SGIsVisibleColor(CGColorRef color);+BOOL SGIsLightColor(CGColorRef color);+// Spotify's base surface: the neutral #121212 it paints its pages with, or the black AMOLED turns+// that into.+BOOL SGIsBaseSurface(CGColorRef color);+// A painted, card-sized view: the now playing bar's card, for one.+BOOL SGLooksLikeCard(UIView *view, CGColorRef color);diff --git a/tweak/Sources/Core/SGViewTree.m b/tweak/Sources/Core/SGViewTree.mnew file mode 100644index 00000000..95929381--- /dev/null+++ b/tweak/Sources/Core/SGViewTree.m@@ -0,0 +1,81 @@+#import "SGViewTree.h"++void SGForEachView(UIView *view, void (^fn)(UIView *)) {+ fn(view);+ for (UIView *sub in view.subviews) SGForEachView(sub, fn);+}++CGRect SGFrameIn(UIView *view, UIView *target) {+ return [view.superview convertRect:view.frame toView:target];+}++BOOL SGIsInside(UIView *view, UIView *root) {+ if (!root) return NO;+ for (UIView *v = view; v; v = v.superview) {+ if ([v isKindOfClass:UIVisualEffectView.class]) return NO;+ if (v == root) return YES;+ }+ return NO;+}++UIStackView *SGRowIn(UIView *host) {+ __block UIStackView *row = nil;+ SGForEachView(host, ^(UIView *v) {+ if (!row && [v isKindOfClass:UIStackView.class] && v.bounds.size.width > 200 && ((UIStackView *)v).arrangedSubviews.count >= 2) row = (UIStackView *)v;+ });+ return row;+}++BOOL SGHasClass(UIView *root, NSString *marker) {+ __block BOOL found = NO;+ SGForEachView(root, ^(UIView *v) {+ if (!found && [NSStringFromClass(v.class) containsString:marker]) found = YES;+ });+ return found;+}++BOOL SGKeepsColor(UIView *view) {+ return [view isKindOfClass:UIImageView.class] || [view isKindOfClass:UILabel.class] || view.bounds.size.height <= 4;+}++void SGStripBackgrounds(UIView *view) {+ if ([view isKindOfClass:UIVisualEffectView.class]) return;+ if (!SGKeepsColor(view)) view.layer.backgroundColor = NULL;+ if ([view.layer isKindOfClass:CAGradientLayer.class] || [NSStringFromClass(view.class) containsString:@"GradientView"]) view.hidden = YES;+ for (CALayer *layer in view.layer.sublayers) {+ if ([layer isKindOfClass:CAGradientLayer.class]) layer.hidden = YES;+ }+ for (UIView *sub in view.subviews) SGStripBackgrounds(sub);+}++BOOL SGIsVisibleColor(CGColorRef color) {+ if (!color || CGColorGetAlpha(color) < 0.05) return NO;+ const CGFloat *c = CGColorGetComponents(color);+ size_t n = CGColorGetNumberOfComponents(color);+ CGFloat brightest = 0;+ for (size_t i = 0; i + 1 < n; i++) brightest = MAX(brightest, c[i]);+ return brightest > 0.08;+}++BOOL SGIsLightColor(CGColorRef color) {+ if (!color || CGColorGetAlpha(color) < 0.5) return NO;+ const CGFloat *c = CGColorGetComponents(color);+ size_t n = CGColorGetNumberOfComponents(color);+ for (size_t i = 0; i + 1 < n; i++) if (c[i] < 0.85) return NO;+ return YES;+}++// Lighter greys (#1F1F1F placeholders, #292929 cards) and translucent paint stay.+BOOL SGIsBaseSurface(CGColorRef color) {+ if (!color || CFGetTypeID(color) != CGColorGetTypeID() || CGColorGetAlpha(color) < 0.95) return NO;+ const CGFloat *c = CGColorGetComponents(color);+ size_t n = CGColorGetNumberOfComponents(color);+ if (n == 2) return c[0] <= 0.10;+ if (n < 3) return NO;+ return c[0] <= 0.10 && fabs(c[0] - c[1]) < 0.02 && fabs(c[1] - c[2]) < 0.02;+}++BOOL SGLooksLikeCard(UIView *view, CGColorRef color) {+ CGSize size = view.bounds.size;+ return size.height >= 40 && size.height <= 140 && size.width >= 200 && SGIsVisibleColor(color);+}diff --git a/tweak/Sources/Diagnostics/Diagnostics.h b/tweak/Sources/Diagnostics/Diagnostics.hnew file mode 100644index 00000000..73e50f27--- /dev/null+++ b/tweak/Sources/Diagnostics/Diagnostics.h@@ -0,0 +1,7 @@+// Screen dumps for FLEX builds: the visible screen's view tree, served over the phone's loopback+// and logged when the app goes to the background.+#import <Foundation/Foundation.h>++BOOL SGIsDebugBuild(void);+NSString *SGScreenTree(void);+void SGDumpScreen(NSString *reason);diff --git a/tweak/src/SGDiagnostics.x b/tweak/Sources/Diagnostics/Diagnostics.xsimilarity index 99%rename from tweak/src/SGDiagnostics.xrename to tweak/Sources/Diagnostics/Diagnostics.xindex be53d1bf..54da80e5 100644--- a/tweak/src/SGDiagnostics.x+++ b/tweak/Sources/Diagnostics/Diagnostics.x@@ -1,7 +1,8 @@// Screen dumps for FLEX builds. The tree of the visible screen is served over HTTP on the phone's// loopback (fetched from the Mac through `iproxy` over USB), and also logged when the app goes to// the background or the full player appears.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Diagnostics.h"#import <sys/socket.h>#import <netinet/in.h>#import <unistd.h>diff --git a/tweak/Sources/Features/About/About.h b/tweak/Sources/Features/About/About.hnew file mode 100644index 00000000..0e544133--- /dev/null+++ b/tweak/Sources/Features/About/About.h@@ -0,0 +1,15 @@+// About: where the build points its user, and whether the site has a newer one (Update.m). The+// status is a string for the Updates row; the page's ticker reads it, so the check needs no+// callback. SGCheckForUpdate(NO) respects a six hour cache, SGCheckForUpdate(YES) always asks.+#import <UIKit/UIKit.h>+#import "Settings/SGModPage.h"++extern NSString *const SGSiteURL;+extern NSString *const SGRepoURL;+extern NSString *const SGUpdateURL;+NSString *SGUpdateVersion(void); // nil unless the site has one newer than this build+NSString *SGUpdateNotes(void);+NSString *SGUpdateStatus(void);+void SGCheckForUpdate(BOOL force);++SGModSection *SGAboutSection(void);diff --git a/tweak/Sources/Features/About/AboutSettings.m b/tweak/Sources/Features/About/AboutSettings.mnew file mode 100644index 00000000..10ce2cc5--- /dev/null+++ b/tweak/Sources/Features/About/AboutSettings.m@@ -0,0 +1,17 @@+#import "Settings/SGPageStyle.h"+#import "About.h"++// Which build this is, whether the site has a newer one, and where to reach the mod: without these+// rows a build that is already installed has no way of telling its user that anything moved on.+SGModSection *SGAboutSection(void) {+ NSString *spotify = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"unknown";+ return SGSection(@"About", @[+ SGStatRow(@"Version", ^NSString *{ return @(SG_VERSION); }),+ SGStatRow(@"Spotify", ^NSString *{ return spotify; }),+ SGStatActionRow(@"Updates", @"Asks the site for the newest build; tap to check now", ^NSString *{+ return SGUpdateStatus();+ }, ^{ SGCheckForUpdate(YES); }),+ SGLinkRow(@"Website", @"Downloads, and the source to add to AltStore or SideStore", SGSiteURL),+ SGLinkRow(@"GitHub", @"Source, releases and issues", SGRepoURL),+ ]);+}diff --git a/tweak/src/SGUpdate.m b/tweak/Sources/Features/About/Update.msimilarity index 93%rename from tweak/src/SGUpdate.mrename to tweak/Sources/Features/About/Update.mindex ec86b989..65bda615 100644--- a/tweak/src/SGUpdate.m+++ b/tweak/Sources/Features/About/Update.m@@ -1,7 +1,8 @@// The site's version.json, so a build that is already on someone's phone can tell them a newer one// exists. Fetched when the Mod Settings page opens, at most once every six hours, and on demand// from the Updates row; the reply is a static file and nothing but the request itself leaves.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "About.h"NSString *const SGSiteURL = @"https://spoti.pw";NSString *const SGRepoURL = @"https://github.com/skopevoj/spoti.pw";@@ -82,11 +83,3 @@ void SGCheckForUpdate(BOOL force) {}];[task resume];}--void SGOpenURL(NSString *url) {- NSURL *target = url ? [NSURL URLWithString:url] : nil;- if (!target) return;- dispatch_async(dispatch_get_main_queue(), ^{- [UIApplication.sharedApplication openURL:target options:@{} completionHandler:nil];- });-}diff --git a/tweak/src/ui/Amoled.x b/tweak/Sources/Features/Appearance/Amoled.xsimilarity index 97%rename from tweak/src/ui/Amoled.xrename to tweak/Sources/Features/Appearance/Amoled.xindex d35a1819..05378d9c 100644--- a/tweak/src/ui/Amoled.x+++ b/tweak/Sources/Features/Appearance/Amoled.x@@ -4,7 +4,8 @@//// Trees: #121212 sits on the Home, Search, Library and settings scroll views, on list rows, the// message bar and the player's bottom gradient view.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Appearance.h"// Neutral and darker than #1A1A1A, but not already black.static BOOL isBaseGrey(CGColorRef color) {diff --git a/tweak/Sources/Features/Appearance/Appearance.h b/tweak/Sources/Features/Appearance/Appearance.hnew file mode 100644index 00000000..f46aa499--- /dev/null+++ b/tweak/Sources/Features/Appearance/Appearance.h@@ -0,0 +1,8 @@+// Appearance: the AMOLED background (Amoled.x), the glass search field (SearchField.x) and+// Repaint.x, which keeps what the other features stripped transparent when Spotify repaints it.+#import <UIKit/UIKit.h>++#define SGKeyAmoled @"spotifyglass.amoled"+#define SGKeySearchField @"spotifyglass.searchField"++UIViewController *SGAppearanceSettingsPage(void);diff --git a/tweak/Sources/Features/Appearance/AppearanceSettings.m b/tweak/Sources/Features/Appearance/AppearanceSettings.mnew file mode 100644index 00000000..3f713f03--- /dev/null+++ b/tweak/Sources/Features/Appearance/AppearanceSettings.m@@ -0,0 +1,18 @@+#import "Settings/SGModPage.h"+#import "Appearance.h"+#import "Features/Navbar/Navbar.h"+#import "Features/Flags/Flags.h"++UIViewController *SGAppearanceSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"UI Tweaks" intro:SGRestartNote sections:@[+ SGSection(@"Liquid Glass", @[+ SGUnstableRow(@"Tab bar", @"[WIP] Unstable", SGKeyTabBar,+ @"The glass capsule does not render the way iOS draws its own, and there is no selection indicator behind the active tab. Switching this on will look wrong.\n\nIf you want to take it further, pull requests are very welcome."),+ SGSwitchRow(@"Search field", @"Glass capsule instead of the white field", SGKeySearchField),+ SGSwitchRow(@"Spotify's own Liquid Glass", @"The glass navigation bar, the new player slider and the new sheets, all shipped switched off", SGKeySpotifyGlass),+ ]),+ SGSection(@"Theme", @[+ SGSwitchRow(@"AMOLED background", @"Pure black instead of Spotify's dark grey", SGKeyAmoled),+ ]),+ ] footer:nil];+}diff --git a/tweak/src/ui/Repaint.x b/tweak/Sources/Features/Appearance/Repaint.xsimilarity index 94%rename from tweak/src/ui/Repaint.xrename to tweak/Sources/Features/Appearance/Repaint.xindex 590e6d04..bbb8c205 100644--- a/tweak/src/ui/Repaint.x+++ b/tweak/Sources/Features/Appearance/Repaint.x@@ -1,6 +1,7 @@// Keeps the areas other tweaks stripped transparent when Spotify repaints them, and learns which// view is the now playing card from the album-colour paint.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Appearance.h"%hook CALayer- (void)setBackgroundColor:(CGColorRef)color {@@ -24,7 +25,7 @@color = NULL;} else if (SGIsBaseSurface(color) && SGIsInside(view, sg_homeRoot)) {// Home keeps its cards and its placeholders; only the base surface the gradient- // of ui/HomeGradient.x sits behind goes.+ // of Home/HomeGradient.x sits behind goes.color = NULL;}}diff --git a/tweak/src/ui/SearchField.x b/tweak/Sources/Features/Appearance/SearchField.xsimilarity index 98%rename from tweak/src/ui/SearchField.xrename to tweak/Sources/Features/Appearance/SearchField.xindex 0b9cf744..511c2036 100644--- a/tweak/src/ui/SearchField.x+++ b/tweak/Sources/Features/Appearance/SearchField.x@@ -11,7 +11,9 @@// Spotify configures the field for a white background again, black glyph and black text, after the// layout pass that styled it: both are then invisible on the glass until the next pass, a second or// so later. So the two setters are refused for as long as the field is a capsule.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Appearance.h"+#import "Diagnostics/Diagnostics.h"// Spotify's glyph view, resolved at runtime; declared on UIView so the call and the hook below// share one declaration.diff --git a/tweak/Sources/Features/Declutter/Declutter.h b/tweak/Sources/Features/Declutter/Declutter.hnew file mode 100644index 00000000..779be651--- /dev/null+++ b/tweak/Sources/Features/Declutter/Declutter.h@@ -0,0 +1,25 @@+// Declutter: cards under the player and sections of Home collapsed, player buttons hidden, one+// switch each (Declutter.x). The rows live on the Now Playing and Home pages. An unset switch is off.+#import <Foundation/Foundation.h>++#define SGHideShuffle @"spotifyglass.hide.shuffle"+#define SGHideRepeat @"spotifyglass.hide.repeat"+#define SGHideConnect @"spotifyglass.hide.connect"+#define SGHideShare @"spotifyglass.hide.share"+#define SGHideQueue @"spotifyglass.hide.queue"+#define SGHideAddTo @"spotifyglass.hide.addTo"+#define SGHideLyricsInline @"spotifyglass.hide.lyricsInline"+#define SGHideLyricsCard @"spotifyglass.hide.lyricsCard"+#define SGHideAboutArtist @"spotifyglass.hide.aboutArtist"+#define SGHideRelatedVideos @"spotifyglass.hide.relatedVideos"+#define SGHideSongDNA @"spotifyglass.hide.songDNA"+#define SGHideLiveEvents @"spotifyglass.hide.liveEvents"+#define SGHideExploreArtist @"spotifyglass.hide.exploreArtist"+#define SGHideCredits @"spotifyglass.hide.credits"+#define SGHideMerch @"spotifyglass.hide.merch"+#define SGHideRecommendations @"spotifyglass.hide.recommendations"+#define SGHideHomeShortcuts @"spotifyglass.hide.homeShortcuts"+#define SGHideHomePills @"spotifyglass.hide.homePills"+#define SGHideHomePromo @"spotifyglass.hide.homePromo"+#define SGHideHomePreviews @"spotifyglass.hide.homePreviews"+#define SGHideHomeDJ @"spotifyglass.hide.homeDJ"diff --git a/tweak/src/ui/Declutter.x b/tweak/Sources/Features/Declutter/Declutter.xsimilarity index 98%rename from tweak/src/ui/Declutter.xrename to tweak/Sources/Features/Declutter/Declutter.xindex 2cf00a8a..08b97d64 100644--- a/tweak/src/ui/Declutter.x+++ b/tweak/Sources/Features/Declutter/Declutter.x@@ -8,7 +8,8 @@// the card. Player rows are the UIStackView of each NowPlaying_ModesImpl unit: playback controls// hold shuffle, previous, play, next, repeat; the footer holds connect, a hidden button, share// and the queue; track info ends with the add-to button.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Declutter.h"#pragma mark - cards and sections@@ -76,7 +77,7 @@ static BOOL vanish(UIView *view) {return YES;}-// Re-layout once something went invisible, so the glass panes of ui/NowPlayingView.x follow.+// Re-layout once something went invisible, so the glass panes of NowPlaying/Player.x follow.static void finish(UIViewController *unit, BOOL changed) {if (changed) [unit.viewIfLoaded setNeedsLayout];}diff --git a/tweak/Sources/Features/Flags/FlagPages.m b/tweak/Sources/Features/Flags/FlagPages.mnew file mode 100644index 00000000..c399a18d--- /dev/null+++ b/tweak/Sources/Features/Flags/FlagPages.m@@ -0,0 +1,142 @@+// Pages that list Spotify's flags by topic; every row forces one flag.+#import "Settings/SGModPage.h"+#import "Flags.h"++UIViewController *SGLockScreenSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Lock screen widget" intro:SGRestartNote sections:@[+ SGSection(@"Spotify's flags", @[+ SGFlagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled"),+ SGFlagRow(@"Animated artwork", @"ios-feature-lockscreen.animated_artwork_enabled"),+ SGFlagRow(@"Video artwork", @"ios-feature-lockscreen.vit_artwork_enabled"),+ SGFlagRow(@"Companion content", @"ios-feature-lockscreen.companion_content_enabled"),+ SGFlagRow(@"Burst skip", @"ios-feature-lockscreen.burst_skip_enabled"),+ SGFlagRow(@"Chapter skip controls", @"ios-feature-lockscreen.enable_chapter_skip_controls"),+ SGFlagRow(@"Skip button on podcasts", @"ios-feature-lockscreen.skip_button_on_podcasts"),+ ]),+ ] footer:nil];+}++UIViewController *SGPlaybackSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Playback" intro:SGRestartNote sections:@[+ SGSection(@"Speed", @[+ SGFlagRow(@"Speed control for music", @"ios-playbackcontrol-playbackspeed-impl.enable_playback_speed_for_music"),+ SGFlagRow(@"Trim silence", @"ios-playbackcontrol-playbackspeed-impl.enable_trim_silence"),+ SGFlagRow(@"Speed shortcuts", @"ios-playbackcontrol-playbackspeed-impl.enable_speed_shortcuts_v2"),+ ]),+ SGSection(@"Queue", @[+ SGFlagRow(@"Swipe a row to play next", @"ios-feature-queue.is_swipe_to_play_next_enabled"),+ SGFlagRow(@"Play next in the context menu", @"ios-feature-queue.is_play_next_context_menu_enabled"),+ SGFlagRow(@"Reshuffle", @"ios-feature-queue.is_reshuffle_enabled"),+ SGFlagRow(@"Peek the queue when adding", @"ios-feature-queue.is_queue_peek_on_add_enabled"),+ ]),+ SGSection(@"Player", @[+ SGFlagRow(@"Pinch to zoom", @"ios-feature-nowplaying-fullscreen.pinch_to_zoom"),+ SGFlagRow(@"Audio settings in the menu", @"ios-nowplaying-contextmenusettings-impl.audio_settings"),+ SGFlagRow(@"Playback settings in the menu", @"ios-nowplaying-contextmenusettings-impl.playback_settings"),+ SGFlagRow(@"Video settings in the menu", @"ios-nowplaying-contextmenusettings-impl.video_settings"),+ SGFlagRow(@"New progress slider", @"ios-feature-encoreexperiments.new_npv_slider_enabled"),+ SGFlagRow(@"Tilt the cover art", @"ios-creativeworkcommons-cover-art-tilt-configuration-kit.cover_art_tilt_enabled"),+ SGFlagRow(@"Tilt it on album and playlist pages", @"ios-creativeworkcommons-cover-art-tilt-configuration-kit.album_playlist_and_podcast_pages_enabled"),+ SGFlagRow(@"Lyrics over Canvas", @"ios-feature-canvas.lyrics_on_canvas_enabled"),+ SGFlagRow(@"Mixing transitions", @"ios-feature-canvas.mixing_transition_enabled"),+ SGFlagRow(@"Picture in picture in the app", @"ios-feature-picture-in-picture.picture_in_picture_in_app"),+ SGFlagRow(@"Connect as a bottom sheet", @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet"),+ SGFlagRow(@"Connect sheet from the video switcher", @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet"),+ ]),+ SGSection(@"Now playing bar", @[+ SGFlagRow(@"Hold and drag to resize", @"ios-feature-nowplayingbar.hold_and_drag_to_resize"),+ SGFlagRow(@"Save button", @"ios-feature-nowplayingbar.add_button"),+ SGFlagRow(@"Queue badge", @"ios-feature-nowplayingbar.queue_badge"),+ SGFlagRow(@"Two lines of track info", @"ios-feature-nowplayingbar.two_lines_information_unit"),+ ]),+ SGSection(@"Spotify's settings", @[+ SGFlagRow(@"Offline listening toggle", @"ios-feature-settings.enable_offline_listening_toggle"),+ SGFlagRow(@"Gapless in Playback settings", @"ios-feature-settings.use_playback_settings_gapless"),+ ]),+ ] footer:nil];+}++// Every switch here forces a flag Spotify ships on to off, so the switch off is Spotify's own value.+UIViewController *SGAdsSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Ads & nags" intro:SGRestartNote sections:@[+ SGSection(@"Ads", @[+ SGKillRow(@"Ad when the app opens", @"ios-feature-adonappopen.enabled"),+ SGKillRow(@"Its CTA card", @"ios-feature-adonappopen.cta_card_enabled"),+ ]),+ SGSection(@"Upsells", @[+ SGKillRow(@"Shuffle toggle upsell", @"ios-feature-shuffletoggleupsell.is_enabled_pt2"),+ SGKillRow(@"Shuffle upsell in the video player", @"ios-feature-nowplaying-modes.video_first_shuffle_upsell_enabled"),+ ]),+ SGSection(@"Badges", @[+ SGKillRow(@"DJ beta badge", @"ios-home-evopage-impl.dj_mdc_beta_badge_enabled"),+ SGKillRow(@"DJ button on Home", @"ios-home-evopage-impl.idj_show_dj_button"),+ ]),+ SGSection(@"Tooltips", @[+ SGKillRow(@"Data saver", @"ios-feature-nowplayingbar.data_saver_tooltip"),+ SGKillRow(@"Smart shuffle helper", @"ios-messaging-reduceinterventions-impl.enable_message_smart_shuffle_helper_tooltip"),+ SGKillRow(@"Watch feed explorer", @"ios-messaging-reduceinterventions-impl.enable_message_watch_feed_entity_explorer_tooltip"),+ SGKillRow(@"AI playlist creation", @"ios-messaging-reduceinterventions-impl.enable_message_your_library_ai_playlist_creation_tooltip"),+ SGKillRow(@"Account switching", @"ios-messaging-reduceinterventions-impl.enable_message_account_switching_tooltip"),+ SGKillRow(@"Concert notifications", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_concert_notifications_tooltip"),+ SGKillRow(@"Live event", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_safe_tooltip"),+ SGKillRow(@"Live event venue", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_venuename_header_tooltip"),+ SGKillRow(@"Player suggestions upsell", @"ios-messaging-reduceinterventions-impl.enable_message_reinvent_free_n_p_v_suggestions_upsell"),+ SGKillRow(@"Puffin nudge", @"ios-messaging-reduceinterventions-impl.enable_message_puffin_nudge_end_optimization"),+ ]),+ SGSection(nil, @[+ SGFlagRow(@"Reduce interventions", @"ios-messaging-reduceinterventions-impl.enabled"),+ ]),+ ] footer:@"The tooltip switches belong to Spotify's own intervention-reduction system, which the last switch turns on."];+}++UIViewController *SGUnreleasedSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Unreleased" intro:SGRestartNote sections:@[+ SGSection(@"Player", @[+ SGFlagRow(@"Snake on the cover art", @"ios-feature-cover-art-snake.enabled"),+ SGFlagRow(@"SongDNA", @"ios-songdna-featureproperties.is_song_dna_enabled"),+ SGFlagRow(@"SongDNA covers playlist", @"ios-songdna-featureproperties.enable_go_to_covers_playlist"),+ ]),+ SGSection(@"Podcast comments", @[+ SGFlagRow(@"Comments card", @"ios-feature-comments.enable_comments_card"),+ SGFlagRow(@"Pinned comments", @"ios-feature-comments.enable_pinned_comments"),+ SGFlagRow(@"Several reactions", @"ios-feature-comments.enable_multi_reactions"),+ ]),+ SGSection(@"Sleep timer", @[+ SGFlagRow(@"Fade out", @"ios-feature-sleeptimer.enable_fade_out"),+ SGFlagRow(@"One minute option", @"ios-feature-sleeptimer.enable_one_minute_option"),+ SGFlagRow(@"Options sheet", @"ios-feature-sleeptimer.use_options_sheet"),+ ]),+ SGSection(@"Elsewhere", @[+ SGFlagRow(@"Local files from the Files app", @"ios-feature-localfiles.documents_enabled"),+ SGFlagRow(@"Progress bar in the home screen widget", @"ios-widgets-widgetremoteconfig-impl.progress_bar_enabled"),+ ]),+ ] footer:nil];+}++static UIViewController *martiniPage(void) {+ return [[SGModPage alloc] initWithTitle:@"AI Chat (Martini)" intro:SGRestartNote sections:@[+ SGSection(@"On Home", @[+ SGFlagRow(@"Chat entry point", @"ios-home-evopage-impl.interactive_entrypoint_enabled"),+ SGFlagRow(@"Martini behind it", @"ios-home-evopage-impl.interactive_entrypoint_martini_enabled"),+ SGFlagRow(@"Floating chat", @"ios-home-evopage-impl.interactive_entrypoint_floating_chat_enabled"),+ SGFlagRow(@"Microphone", @"ios-home-evopage-impl.interactive_entrypoint_mic_enabled"),+ SGFlagRow(@"Glowing pill", @"ios-home-evopage-impl.interactive_entrypoint_pill_glow_enabled"),+ ]),+ SGSection(@"The chat", @[+ SGFlagRow(@"Intent pills", @"ios-martini-floatingchat-impl.intent_pills_enabled"),+ SGFlagRow(@"Thinking states", @"ios-martini-floatingchat-impl.thinking_states_enabled"),+ SGFlagRow(@"Voice recording", @"ios-martini-floatingchat-impl.voice_recording_enabled"),+ ]),+ SGSection(@"In the player", @[+ SGFlagRow(@"Chat entry point", @"ios-martini-npvcardprovider-impl.floating_chat_entry_point_enabled"),+ ]),+ ] footer:nil];+}++UIViewController *SGExperimentalSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Experimental" intro:nil sections:@[+ SGSection(nil, @[+ SGPageRow(@"AI Chat (Martini)", ^UIViewController *{ return martiniPage(); }),+ ]),+ ] footer:nil];+}diff --git a/tweak/Sources/Features/Flags/Flags.h b/tweak/Sources/Features/Flags/Flags.hnew file mode 100644index 00000000..5988bd84--- /dev/null+++ b/tweak/Sources/Features/Flags/Flags.h@@ -0,0 +1,23 @@+// Flags: Spotify's remote-config flags. Flags.x forces an override into the configuration+// provider; SGFlagList.m is the table of every flag, generated from the IPA by+// scripts/extract-flags.py; FlagsPage.m is the searchable All flags page and FlagPages.m the pages+// that list flags by topic (Playback, Ads & nags, Lock screen widget, Unreleased, Experimental).+#import <UIKit/UIKit.h>++// Spotify ships its newer design behind several flags at once, so this switch owns them all:+// Flags.x forces each one while it is on and the settings rows show them locked at the forced+// value, which is what keeps the switch and the rows from contradicting each other.+#define SGKeySpotifyGlass @"spotifyglass.spotifyGlass"+BOOL SGGlassOwnsFlag(NSString *key);++typedef NS_ENUM(NSInteger, SGFlagType) { SGFlagUnknown, SGFlagBool, SGFlagInt, SGFlagEnum };+typedef struct { const char *key; SGFlagType type; long value, lower, upper; } SGFlagDef;+extern const SGFlagDef SGFlagTable[];+extern const NSUInteger SGFlagCount;++UIViewController *SGAllFlagsPage(void);+UIViewController *SGPlaybackSettingsPage(void);+UIViewController *SGAdsSettingsPage(void);+UIViewController *SGLockScreenSettingsPage(void);+UIViewController *SGUnreleasedSettingsPage(void);+UIViewController *SGExperimentalSettingsPage(void);diff --git a/tweak/src/ui/Flags.x b/tweak/Sources/Features/Flags/Flags.xsimilarity index 73%rename from tweak/src/ui/Flags.xrename to tweak/Sources/Features/Flags/Flags.xindex 4cdd7a47..93842675 100644--- a/tweak/src/ui/Flags.x+++ b/tweak/Sources/Features/Flags/Flags.x@@ -1,7 +1,26 @@// Spotify reads every remote-config flag once at startup through the configuration provider,// keyed "component.property". An override from the Flags page wins; the Spotify's own Liquid// Glass switch then forces the flags of Spotify's own newer design, which it ships switched off.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Flags.h"++BOOL SGGlassOwnsFlag(NSString *key) {+ static NSSet<NSString *> *owned;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ owned = [NSSet setWithArray:@[+ @"ios-reprise-liquid-glass-properties.context_menu_in_navigation_bar_enabled",+ @"ios-feature-encoreexperiments.new_npv_slider_enabled",+ @"ios-feature-nowplaying.sheet_style_npv",+ @"ios-feature-nowplaying.bottom_sheet_queue_enabled",+ @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled",+ @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet",+ @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet",+ @"ios-feature-sleeptimer.use_options_sheet",+ ]];+ });+ return [owned containsObject:key];+}static id forced(NSString *key) {id value = SGFlagOverride(key);diff --git a/tweak/Sources/Features/Flags/FlagsPage.m b/tweak/Sources/Features/Flags/FlagsPage.mnew file mode 100644index 00000000..76e14cf6--- /dev/null+++ b/tweak/Sources/Features/Flags/FlagsPage.m@@ -0,0 +1,164 @@+#import "Core/SGCore.h"+#import "Settings/SGPage.h"+#import "Settings/SGPageStyle.h"+#import "Flags.h"++static NSString *flagState(const SGFlagDef *flag, id value) {+ if (value) return [NSString stringWithFormat:@"forced %@", flag->type == SGFlagBool ? ([value boolValue] ? @"on" : @"off") : value];+ switch (flag->type) {+ case SGFlagBool: return flag->value ? @"on by default" : @"off by default";+ case SGFlagInt: return [NSString stringWithFormat:@"%ld by default, %ld to %ld", flag->value, flag->lower, flag->upper];+ case SGFlagEnum: return @"text value";+ default: return @"type unknown";+ }+}++// Every flag in SGFlagTable, filtered by the search words; forced flags first while the search+// is empty. Bool flags get an Auto / Off / On control, the others a text field in an alert.+@interface SGFlagsPage : SGPage <UISearchBarDelegate>+@end++@implementation SGFlagsPage {+ NSArray<NSNumber *> *_shown;+ NSDictionary<NSString *, id> *_overrides;+ UISearchBar *_search;+ UIView *_header;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStylePlain])) return nil;+ self.title = @"Flags";+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.tableView.backgroundColor = SGPageBackground();+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;+ self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;+ _search = [UISearchBar new];+ _search.placeholder = [NSString stringWithFormat:@"Search %lu flags", (unsigned long)SGFlagCount];+ _search.searchBarStyle = UISearchBarStyleMinimal;+ _search.delegate = self;+ _header = SGNote(@"Spotify's remote config, read once at startup. Auto keeps the value Spotify sends; a change applies after you restart Spotify.");+ [_header addSubview:_search];+ self.tableView.tableHeaderView = _header;+ [self reload];+}++- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ _search.frame = CGRectMake(8, 4, self.tableView.bounds.size.width - 16, 44);+ SGFitNote(self.tableView, _header, 52, 8);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ SGInsetForBars(self.tableView);+}++- (void)reload {+ NSMutableDictionary *overrides = [NSMutableDictionary dictionary];+ NSDictionary *defaults = NSUserDefaults.standardUserDefaults.dictionaryRepresentation;+ for (NSString *key in defaults) {+ if ([key hasPrefix:SGFlagOverridePrefix]) overrides[[key substringFromIndex:SGFlagOverridePrefix.length]] = defaults[key];+ }+ NSArray<NSString *> *words = [_search.text.lowercaseString componentsSeparatedByString:@" "];+ NSMutableArray *forced = [NSMutableArray array], *rest = [NSMutableArray array];+ for (NSUInteger i = 0; i < SGFlagCount; i++) {+ NSString *key = @(SGFlagTable[i].key);+ BOOL match = YES;+ for (NSString *word in words) match = match && (!word.length || [key containsString:word]);+ if (match) [overrides[key] ? forced : rest addObject:@(i)];+ }+ _overrides = overrides;+ _shown = [forced arrayByAddingObjectsFromArray:rest];+ [self.tableView reloadData];+}++- (void)searchBar:(UISearchBar *)bar textDidChange:(NSString *)text {+ [self reload];+}++- (void)searchBarSearchButtonClicked:(UISearchBar *)bar {+ [bar resignFirstResponder];+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return (NSInteger)_shown.count;+}++- (const SGFlagDef *)flagAt:(NSInteger)row {+ return &SGFlagTable[_shown[(NSUInteger)row].unsignedIntegerValue];+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"flag");+ const SGFlagDef *flag = [self flagAt:path.row];+ NSString *key = @(flag->key);+ NSUInteger dot = [key rangeOfString:@"."].location;+ id value = _overrides[key];++ SGFillCell(cell, [key substringFromIndex:dot + 1],+ [NSString stringWithFormat:@"%@ · %@", [key substringToIndex:dot], flagState(flag, value)],+ value ? SGGreen() : nil, nil);+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;++ if (flag->type == SGFlagBool) {+ UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"Auto", @"Off", @"On"]];+ control.selectedSegmentIndex = value ? ([value boolValue] ? 2 : 1) : 0;+ control.selectedSegmentTintColor = SGGreen();+ [control setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor, NSFontAttributeName: SGSubtitleFont()} forState:UIControlStateNormal];+ control.tag = path.row;+ [control addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];+ [control sizeToFit];+ cell.accessoryView = control;+ cell.selectionStyle = UITableViewCellSelectionStyleNone;+ }+ return cell;+}++- (void)segmentChanged:(UISegmentedControl *)control {+ NSString *key = @([self flagAt:control.tag]->key);+ NSInteger index = control.selectedSegmentIndex;+ [self store:index == 0 ? nil : @(index == 2) forKey:key row:control.tag];+}++- (void)store:(id)value forKey:(NSString *)key row:(NSInteger)row {+ SGSetFlagOverride(key, value);+ NSMutableDictionary *overrides = [_overrides mutableCopy];+ overrides[key] = value;+ _overrides = overrides;+ [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ const SGFlagDef *flag = [self flagAt:path.row];+ if (flag->type == SGFlagBool) return;+ NSString *key = @(flag->key);+ id value = _overrides[key];+ NSString *hint = flag->type == SGFlagUnknown ? @"true or false, a number, or a text value" : flagState(flag, value);+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:[key substringFromIndex:[key rangeOfString:@"."].location + 1] message:hint preferredStyle:UIAlertControllerStyleAlert];+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {+ field.text = value ? [value description] : @"";+ field.keyboardType = flag->type == SGFlagInt ? UIKeyboardTypeNumbersAndPunctuation : UIKeyboardTypeDefault;+ }];+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Auto" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *a) {+ [self store:nil forKey:key row:path.row];+ }]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Force" style:UIAlertActionStyleDefault handler:^(UIAlertAction *a) {+ NSString *text = alert.textFields.firstObject.text;+ if (!text.length) return;+ [self store:flag->type == SGFlagInt ? @(text.integerValue) : text forKey:key row:path.row];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++@end++UIViewController *SGAllFlagsPage(void) {+ return [SGFlagsPage new];+}diff --git a/tweak/Sources/Features/Home/Home.h b/tweak/Sources/Features/Home/Home.hnew file mode 100644index 00000000..a2a5474f--- /dev/null+++ b/tweak/Sources/Features/Home/Home.h@@ -0,0 +1,6 @@+// Home: the gradient behind the top of the page (HomeGradient.x), off until it is asked for.+#import <UIKit/UIKit.h>++#define SGKeyHomeGradient @"spotifyglass.homeGradient"++UIViewController *SGHomeSettingsPage(void);diff --git a/tweak/src/ui/HomeGradient.x b/tweak/Sources/Features/Home/HomeGradient.xsimilarity index 97%rename from tweak/src/ui/HomeGradient.xrename to tweak/Sources/Features/Home/HomeGradient.xindex f83e0a88..4866fed6 100644--- a/tweak/src/ui/HomeGradient.x+++ b/tweak/Sources/Features/Home/HomeGradient.x@@ -1,7 +1,7 @@// Home gradient: a green wash behind the top of the Home tab, strongest under the avatar and the// pills and out by the second shelf, like the gradient Spotify's own Home used to have. The wash// is a layer inside the page's scroll view, under its content, so it scrolls away with the-// shelves; the base grey the page and the shelves paint over it goes clear in ui/Repaint.x, and+// shelves; the base grey the page and the shelves paint over it goes clear in Appearance/Repaint.x, and// Spotify's own scrim behind the header goes with it, since it would only mute the colour.//// Tree (trees/home.txt): FunkisViewController.view holds the page, a 402x112 wrapper around@@ -10,7 +10,8 @@// Home_CarouselKit.TouchCancellingCollectionView of the page, full screen and inset 112pt at the// top for the header, painted #121212; the shelves inside it are collection views of their own,// painted #121212 as well.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Home.h"// Sampled off the design: #0B4110 at the top of the screen, level behind the header, gone by 390pt.static UIColor *tint(void) { return [UIColor colorWithRed:0x0B / 255.0 green:0x41 / 255.0 blue:0x10 / 255.0 alpha:1]; }@@ -33,7 +34,7 @@ static char kGradientKey, kStrippedKey;@end// The shelves and the shortcuts grid are lists of their own, each painting the base surface over-// the wash. A cell paints itself before the page puts it in, where the hook in ui/Repaint.x cannot+// the wash. A cell paints itself before the page puts it in, where the hook in Appearance/Repaint.x cannot// see that it belongs to Home, so every cell is stripped once as it turns up; the repaints it// takes later, in the page by then, go through the hook. The page's own paint is behind the wash.static void stripCells(UIScrollView *list) {diff --git a/tweak/Sources/Features/Home/HomeSettings.m b/tweak/Sources/Features/Home/HomeSettings.mnew file mode 100644index 00000000..98f43c38--- /dev/null+++ b/tweak/Sources/Features/Home/HomeSettings.m@@ -0,0 +1,32 @@+#import "Settings/SGModPage.h"+#import "Home.h"+#import "Features/Declutter/Declutter.h"++UIViewController *SGHomeSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Home & Library" intro:SGRestartNote sections:@[+ SGSection(@"Background", @[+ SGOptionRow(@"Gradient", @"A green wash behind the top of the page, fading into the background", SGKeyHomeGradient),+ ]),+ SGSection(@"Hide", @[+ SGHideRow(@"Filter pills", @"Music and Podcasts next to your avatar", SGHideHomePills),+ SGHideRow(@"Shortcuts grid", @"The tiles at the top", SGHideHomeShortcuts),+ SGHideRow(@"Promo cards", @"Single cards such as the next episode of a podcast", SGHideHomePromo),+ SGHideRow(@"Preview cards", @"Album, playlist and video previews with a play button", SGHideHomePreviews),+ SGHideRow(@"DJ card", @"Your own personal DJ", SGHideHomeDJ),+ ]),+ SGSection(@"Spotify's flags", @[+ SGFlagRow(@"Pull to refresh", @"ios-home-evopage-impl.pull_to_refresh_enabled"),+ SGFlagRow(@"Hide items from Recents", @"ios-system-home-hidefromhome.is_hide_from_recents_enabled"),+ SGFlagRow(@"Hide items from Shortcuts", @"ios-system-home-hidefromhome.is_hide_from_shortcuts_enabled"),+ ]),+ SGSection(@"Library", @[+ SGFlagRow(@"Denser rows", @"ios-feature-yourlibaryx.denser_rows_enabled"),+ SGFlagRow(@"Recents", @"ios-feature-yourlibaryx.recents_enabled"),+ SGFlagRow(@"Recents sort order", @"ios-feature-yourlibaryx.recents_sort_order_enabled"),+ SGFlagRow(@"Sort playlists by recently updated", @"ios-feature-yourlibaryx.recently_updated_playlists_sort_enabled"),+ SGFlagRow(@"Sort artists by recently updated", @"ios-feature-yourlibaryx.recently_updated_artists_sort_enabled"),+ SGFlagRow(@"Library settings", @"ios-feature-yourlibaryx.library_settings_enabled"),+ SGFlagRow(@"Library Pro", @"ios-feature-yourlibaryx.your_library_pro_enabled"),+ ]),+ ] footer:nil];+}diff --git a/tweak/Sources/Features/Navbar/Navbar.h b/tweak/Sources/Features/Navbar/Navbar.hnew file mode 100644index 00000000..7e9dd30b--- /dev/null+++ b/tweak/Sources/Features/Navbar/Navbar.h@@ -0,0 +1,26 @@+// Navbar: the glass tab bar (TabBar.x) and the bar's own composition (Navbar.x): an ordered list+// of entries, each a dictionary. An entry with a URI is a tab of the mod's own; one without names+// one of Spotify's, by the label under its icon. No list at all is Spotify's order, all shown.+#import <UIKit/UIKit.h>++#define SGKeyTabBar @"spotifyglass.tabBar"+#define SGKeyNavbar @"spotifyglass.navbar"++extern NSString *const SGNavbarID; // NSString, the entry's identity+extern NSString *const SGNavbarTitle; // NSString, the name in the settings list and under the icon+extern NSString *const SGNavbarURI; // NSString, the mod's own tabs only: what a tap opens+extern NSString *const SGNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts"+extern NSString *const SGNavbarHidden; // NSNumber+NSArray<NSDictionary *> *SGNavbarLayout(void);+void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);+// Spotify's own tabs in Spotify's order, as Navbar.x last saw them on the bar.+NSArray<NSString *> *SGNavbarStock(void);+void SGSetNavbarStock(NSArray<NSString *> *stock);++// Navbar.x, called from the tab bar's layout passes in TabBar.x.+void SGComposeTabBar(UIView *tabBar);+void SGLogTabBarRow(UIView *tabBar);+// Lays the bar out again after the Navbar page changes something, so it does not wait for a touch.+void SGRefreshTabBar(void);++UIViewController *SGNavbarSettingsPage(void);diff --git a/tweak/src/ui/Navbar.x b/tweak/Sources/Features/Navbar/Navbar.xsimilarity index 96%rename from tweak/src/ui/Navbar.xrename to tweak/Sources/Features/Navbar/Navbar.xindex fd02a145..a47cb633 100644--- a/tweak/src/ui/Navbar.x+++ b/tweak/Sources/Features/Navbar/Navbar.x@@ -13,32 +13,25 @@// 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.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Navbar.h"+#import "Headers/SPTEncoreIconView.h"+#import "Headers/SPTLinkDispatcherImplementation.h"#import <objc/message.h>-// Spotify's own, resolved at runtime: SpotifyShared has the icons, the app the link dispatcher.-@interface SPTEncoreIconView : UIView-- (instancetype)initWithIcon:(id)icon;-- (void)setForegroundColor:(UIColor *)color;-@end--@interface SGLinkDispatcher : NSObject-- (void)navigateToURI:(NSURL *)uri options:(long long)options interactionID:(id)interactionID;-@end-static const CGFloat kIconSize = 24;static const CGFloat kIconTop = 12.5;static const CGFloat kLabelTop = 35;static const CGFloat kLabelHeight = 14;static char kCustomKey, kOrderKey;-// Where Spotify's own items keep their icon and label, read off one of them every pass. ui/TabBar.x+// Where Spotify's own items keep their icon and label, read off one of them every pass. Navbar/TabBar.x// moves the icons when the glass bar is on, and this follows a pass later, so an item of the mod's// own sits on the same line as its neighbours either way.static CGRect sg_iconBox = {{0, kIconTop}, {kIconSize, kIconSize}};static CGRect sg_labelBox = {{0, kLabelTop}, {0, kLabelHeight}};-static __weak SGLinkDispatcher *sg_linkDispatcher;+static __weak SPTLinkDispatcherImplementation *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;@@ -110,7 +103,7 @@ static UIView *iconView(NSString *name) {[self addSubview:_icon];}-// Both boxes come off a neighbour, so whatever Spotify or ui/TabBar.x does to the row's line-up+// Both boxes come off a neighbour, so whatever Spotify or Navbar/TabBar.x does to the row's line-up// is copied rather than guessed at; only the horizontal centring is the item's own.- (void)layoutSubviews {[super layoutSubviews];@@ -135,7 +128,7 @@ static UIView *iconView(NSString *name) {- (void)open {NSURL *url = self.uri.length ? [NSURL URLWithString:self.uri] : nil;- SGLinkDispatcher *dispatcher = sg_linkDispatcher;+ SPTLinkDispatcherImplementation *dispatcher = sg_linkDispatcher;if (!url || ![dispatcher respondsToSelector:@selector(navigateToURI:options:interactionID:)]) {SGLog(@"navbar: cannot open %@, dispatcher %@", self.uri, dispatcher);return;@@ -368,7 +361,7 @@ void SGLogTabBarRow(UIView *tabBar) {%hook SPTLinkDispatcherImplementation- (void)setMainUILoaded:(BOOL)loaded {%orig;- sg_linkDispatcher = (SGLinkDispatcher *)self;+ sg_linkDispatcher = (SPTLinkDispatcherImplementation *)self;}%enddiff --git a/tweak/Sources/Features/Navbar/NavbarLayout.m b/tweak/Sources/Features/Navbar/NavbarLayout.mnew file mode 100644index 00000000..f4666be0--- /dev/null+++ b/tweak/Sources/Features/Navbar/NavbarLayout.m@@ -0,0 +1,34 @@+// The saved composition of the bar, as NSUserDefaults property lists.+#import "Navbar.h"++NSString *const SGNavbarID = @"id";+NSString *const SGNavbarTitle = @"title";+NSString *const SGNavbarURI = @"uri";+NSString *const SGNavbarIcon = @"icon";+NSString *const SGNavbarHidden = @"hidden";++static NSString *const kNavbarLayout = @"spotifyglass.navbar.layout";+static NSString *const kNavbarStock = @"spotifyglass.navbar.stock";++// Only property list types go in, so a corrupt read cannot be anything but an array of dictionaries.+static NSArray *listOfKind(NSString *key, Class kind) {+ NSArray *list = [NSUserDefaults.standardUserDefaults arrayForKey:key];+ for (id item in list) if (![item isKindOfClass:kind]) return @[];+ return list ?: @[];+}++NSArray<NSDictionary *> *SGNavbarLayout(void) {+ return listOfKind(kNavbarLayout, NSDictionary.class);+}++void SGSetNavbarLayout(NSArray<NSDictionary *> *layout) {+ [NSUserDefaults.standardUserDefaults setObject:layout ?: @[] forKey:kNavbarLayout];+}++NSArray<NSString *> *SGNavbarStock(void) {+ return listOfKind(kNavbarStock, NSString.class);+}++void SGSetNavbarStock(NSArray<NSString *> *stock) {+ [NSUserDefaults.standardUserDefaults setObject:stock ?: @[] forKey:kNavbarStock];+}diff --git a/tweak/Sources/Features/Navbar/NavbarSettings.m b/tweak/Sources/Features/Navbar/NavbarSettings.mnew file mode 100644index 00000000..b7d2d460--- /dev/null+++ b/tweak/Sources/Features/Navbar/NavbarSettings.m@@ -0,0 +1,331 @@+#import "Core/SGCore.h"+#import "Settings/SGPage.h"+#import "Settings/SGPageStyle.h"+#import "Navbar.h"++// What "Add a tab" offers: URIs Spotify's own router resolves to a page of its own, each with the+// name of the SPTEncoreIcon class method that draws its glyph.+static NSArray<NSDictionary *> *tabPresets(void) {+ return @[+ @{SGNavbarTitle: @"Home", SGNavbarURI: @"spotify:home", SGNavbarIcon: @"home"},+ @{SGNavbarTitle: @"Search", SGNavbarURI: @"spotify:search", SGNavbarIcon: @"search"},+ @{SGNavbarTitle: @"Your Library", SGNavbarURI: @"spotify:collection", SGNavbarIcon: @"collection"},+ @{SGNavbarTitle: @"Liked Songs", SGNavbarURI: @"spotify:collection:tracks", SGNavbarIcon: @"heart"},+ @{SGNavbarTitle: @"Playlists", SGNavbarURI: @"spotify:collection:playlists", SGNavbarIcon: @"playlist"},+ @{SGNavbarTitle: @"Albums", SGNavbarURI: @"spotify:collection:albums", SGNavbarIcon: @"album"},+ @{SGNavbarTitle: @"Artists", SGNavbarURI: @"spotify:collection:artists", SGNavbarIcon: @"artist"},+ @{SGNavbarTitle: @"Podcasts", SGNavbarURI: @"spotify:collection:podcasts", SGNavbarIcon: @"podcasts"},+ @{SGNavbarTitle: @"Audiobooks", SGNavbarURI: @"spotify:collection:audiobooks", SGNavbarIcon: @"audiobook"},+ @{SGNavbarTitle: @"Downloads", SGNavbarURI: @"spotify:collection:downloads", SGNavbarIcon: @"downloaded"},+ @{SGNavbarTitle: @"Your Episodes", SGNavbarURI: @"spotify:collection:your-episodes", SGNavbarIcon: @"bookmark"},+ @{SGNavbarTitle: @"Browse", SGNavbarURI: @"spotify:browse", SGNavbarIcon: @"browse"},+ @{SGNavbarTitle: @"New Releases", SGNavbarURI: @"spotify:new-releases", SGNavbarIcon: @"star"},+ @{SGNavbarTitle: @"Made For You", SGNavbarURI: @"spotify:made-for-you", SGNavbarIcon: @"user"},+ @{SGNavbarTitle: @"Concerts", SGNavbarURI: @"spotify:concerts", SGNavbarIcon: @"events"},+ @{SGNavbarTitle: @"Queue", SGNavbarURI: @"spotify:now-playing:queue", SGNavbarIcon: @"queue"},+ @{SGNavbarTitle: @"Create", SGNavbarURI: @"spotify:create-menu", SGNavbarIcon: @"plus"},+ ];+}++// The list the Navbar page edits: the saved order first, then every tab of Spotify's it does not+// name, in Spotify's order. Entries for tabs Spotify no longer has drop out.+static NSMutableArray<NSMutableDictionary *> *navbarEntries(void) {+ NSArray<NSString *> *stock = SGNavbarStock();+ NSMutableArray<NSMutableDictionary *> *entries = [NSMutableArray array];+ NSMutableSet<NSString *> *seen = [NSMutableSet set];+ for (NSDictionary *entry in SGNavbarLayout()) {+ NSString *ident = entry[SGNavbarID];+ if (![ident isKindOfClass:NSString.class] || [seen containsObject:ident]) continue;+ if (!entry[SGNavbarURI] && ![stock containsObject:ident]) continue;+ [seen addObject:ident];+ [entries addObject:[entry mutableCopy]];+ }+ for (NSString *ident in stock) {+ if ([seen containsObject:ident]) continue;+ [entries addObject:[@{SGNavbarID: ident, SGNavbarTitle: ident} mutableCopy]];+ }+ return entries;+}++// A tab of the mod's own carries an identity of its own, so the same page can sit on the bar twice+// and renaming one does not shuffle the order.+static void appendTab(NSDictionary *tab) {+ NSMutableDictionary *entry = [tab mutableCopy];+ entry[SGNavbarID] = NSUUID.UUID.UUIDString;+ SGSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);+ SGRefreshTabBar();+}++@interface SGTabPickerPage : SGPage+@end++@implementation SGTabPickerPage {+ UIView *_footer;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;+ self.title = @"Add a Tab";+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.tableView.backgroundColor = SGPageBackground();+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;+ self.tableView.sectionHeaderTopPadding = 0;+ _footer = SGNote(@"Anything Spotify can open by link works, so a playlist, an artist or a page of "+ "your own goes on the bar the same way. Icons are Spotify's own: home, search, "+ "collection, heart, playlist, album, artist, podcasts, audiobook, downloaded, "+ "bookmark, browse, star, user, events, queue, plus, radio, gears, spotifyLogo.");+ self.tableView.tableFooterView = _footer;+}++- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ SGFitNote(self.tableView, _footer, 16, 24);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ SGInsetForBars(self.tableView);+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return 2;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return section == 0 ? (NSInteger)tabPresets().count : 1;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ return SGSectionHeader(table, section == 0 ? @"Spotify's pages" : @"Anywhere else");+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ return SGSectionHeaderHeight;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"pick");+ if (path.section == 0) {+ NSDictionary *tab = tabPresets()[(NSUInteger)path.row];+ SGFillCell(cell, tab[SGNavbarTitle], tab[SGNavbarURI], nil, nil);+ } else {+ SGFillCell(cell, @"Any link…", @"A name, a URI of your own and an icon", nil, @"link");+ }+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ return cell;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ if (path.section == 0) {+ appendTab(tabPresets()[(NSUInteger)path.row]);+ [self.navigationController popViewControllerAnimated:YES];+ return;+ }+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Any link" message:@"Where the tab goes, and the glyph on it." preferredStyle:UIAlertControllerStyleAlert];+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) { field.placeholder = @"Name"; }];+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {+ field.placeholder = @"spotify:playlist:…";+ field.autocapitalizationType = UITextAutocapitalizationTypeNone;+ field.autocorrectionType = UITextAutocorrectionTypeNo;+ }];+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {+ field.placeholder = @"Icon";+ field.text = @"star";+ field.autocapitalizationType = UITextAutocapitalizationTypeNone;+ field.autocorrectionType = UITextAutocorrectionTypeNo;+ }];+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Add" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {+ NSString *title = alert.textFields[0].text, *uri = alert.textFields[1].text, *icon = alert.textFields[2].text;+ if (!uri.length) return;+ appendTab(@{SGNavbarTitle: title.length ? title : uri, SGNavbarURI: uri, SGNavbarIcon: icon.length ? icon : @"star"});+ [self.navigationController popViewControllerAnimated:YES];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++@end++// The tabs, in the order the bar shows them: drag to reorder, tap to show or hide, swipe a tab of+// your own away. Spotify's own tabs can only be hidden, never removed.+@interface SGNavbarPage : SGPage+@end++@implementation SGNavbarPage {+ NSMutableArray<NSMutableDictionary *> *_entries;+ UIView *_intro;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;+ self.title = @"Navbar";+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.tableView.backgroundColor = SGPageBackground();+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;+ self.tableView.sectionHeaderTopPadding = 0;+ self.tableView.allowsSelectionDuringEditing = YES;+ self.tableView.editing = YES;+ _intro = SGNote(@"Drag a tab by the handle to move it, tap it to show or hide it. The bar follows straight away.");+ self.tableView.tableHeaderView = _intro;+ _entries = navbarEntries();+}++// The Add page writes straight to the layout, so the list is read again on the way back.+- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ _entries = navbarEntries();+ [self.tableView reloadData];+}++- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ SGFitNote(self.tableView, _intro, 24, 0);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ SGInsetForBars(self.tableView);+}++- (void)save {+ SGSetNavbarLayout(_entries);+ SGRefreshTabBar();+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return 4;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return section == 1 ? (NSInteger)_entries.count : 1;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ return section == 1 ? SGSectionHeader(table, @"Tabs") : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ return section == 1 ? SGSectionHeaderHeight : CGFLOAT_MIN;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"navbar");+ switch (path.section) {+ case 0: {+ SGFillCell(cell, @"Custom navbar", @"Off leaves the bar exactly as Spotify built it", nil, nil);+ UISwitch *toggle = [UISwitch new];+ toggle.onTintColor = SGGreen();+ toggle.on = SGEnabled(SGKeyNavbar);+ [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];+ cell.accessoryView = toggle;+ break;+ }+ case 1: {+ NSDictionary *entry = _entries[(NSUInteger)path.row];+ BOOL hidden = [entry[SGNavbarHidden] boolValue];+ NSString *uri = entry[SGNavbarURI];+ SGFillCell(cell, entry[SGNavbarTitle], hidden ? @"Hidden" : (uri ?: @"Spotify's own tab"),+ hidden ? SGGrey() : nil, hidden ? @"eye.slash" : @"eye");+ break;+ }+ case 2:+ SGFillCell(cell, @"Add a tab…", @"A page of Spotify's, or any link", nil, @"plus");+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ break;+ default:+ SGFillCell(cell, @"Use Spotify's order", @"Forgets the order and the tabs you added", nil, @"arrow.uturn.backward");+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ break;+ }+ return cell;+}++- (BOOL)tableView:(UITableView *)table canMoveRowAtIndexPath:(NSIndexPath *)path {+ return path.section == 1;+}++- (BOOL)tableView:(UITableView *)table canEditRowAtIndexPath:(NSIndexPath *)path {+ return path.section == 1;+}++// Spotify's own tabs stay on the list to be switched back on; only the mod's own can go.+- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)path {+ if (path.section != 1) return UITableViewCellEditingStyleNone;+ return _entries[(NSUInteger)path.row][SGNavbarURI] ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;+}++- (NSIndexPath *)tableView:(UITableView *)table targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)from toProposedIndexPath:(NSIndexPath *)to {+ return to.section == 1 ? to : from;+}++- (void)tableView:(UITableView *)table moveRowAtIndexPath:(NSIndexPath *)from toIndexPath:(NSIndexPath *)to {+ NSMutableDictionary *entry = _entries[(NSUInteger)from.row];+ [_entries removeObjectAtIndex:(NSUInteger)from.row];+ [_entries insertObject:entry atIndex:(NSUInteger)to.row];+ [self save];+}++- (void)tableView:(UITableView *)table commitEditingStyle:(UITableViewCellEditingStyle)style forRowAtIndexPath:(NSIndexPath *)path {+ if (style != UITableViewCellEditingStyleDelete) return;+ [_entries removeObjectAtIndex:(NSUInteger)path.row];+ [self save];+ [table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ if (path.section == 1) {+ NSMutableDictionary *entry = _entries[(NSUInteger)path.row];+ entry[SGNavbarHidden] = [entry[SGNavbarHidden] boolValue] ? nil : @YES;+ [self save];+ [table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];+ } else if (path.section == 2) {+ [self.navigationController pushViewController:[SGTabPickerPage new] animated:YES];+ } else if (path.section == 3) {+ [self reset];+ }+}++- (void)toggled:(UISwitch *)toggle {+ SGSetEnabled(SGKeyNavbar, toggle.on);+ SGRefreshTabBar();+}++- (void)reset {+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Use Spotify's order"+ message:@"Every tab of Spotify's comes back where Spotify put it, and the tabs you added go."+ preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {+ SGSetNavbarLayout(@[]);+ SGRefreshTabBar();+ self->_entries = navbarEntries();+ [self.tableView reloadData];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++@end++UIViewController *SGNavbarSettingsPage(void) {+ return [SGNavbarPage new];+}diff --git a/tweak/src/ui/TabBar.x b/tweak/Sources/Features/Navbar/TabBar.xsimilarity index 93%rename from tweak/src/ui/TabBar.xrename to tweak/Sources/Features/Navbar/TabBar.xindex d2cdb448..2174ae91 100644--- a/tweak/src/ui/TabBar.x+++ b/tweak/Sources/Features/Navbar/TabBar.x@@ -1,17 +1,18 @@// Tab bar: gradient and labels go, icons centre, a glass capsule sits behind the tabs and a glass-// circle behind Create when Create is the last of them. ui/Navbar.x owns which items are on the+// circle behind Create when Create is the last of them. Navbar/Navbar.x owns which items are on the// bar and in what order; this file only paints whatever it left there.//// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > TabBarGradientView// + UIStackView 402x49 of four ElementContentView<TabBarItemElement> 100x49, each with an// SPTEncoreIconView 24x24 and an SPTEncoreLabel.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Navbar.h"static const CGFloat kPillHeight = 56;static const CGFloat kCircleSize = 52;static char kPillKey, kCircleKey;-// The items the bar shows, left to right. ui/Navbar.x leaves the stack in Spotify's order and+// The items the bar shows, left to right. Navbar/Navbar.x leaves the stack in Spotify's order and// shifts the items across it, so the row reads by position on screen, not by arranged order.static NSArray<UIView *> *tabItems(UIView *tabBar) {NSMutableArray<UIView *> *items = [NSMutableArray array];@@ -35,7 +36,7 @@ static void styleTabBar(UIView *tabBar) {if (items.count < 2) return;// Create is a round button of its own, but only where Spotify puts it: last. Moved in among- // the others by ui/Navbar.x it joins them under the capsule instead.+ // the others by Navbar/Navbar.x it joins them under the capsule instead.BOOL circled = SGHasClass(items.lastObject, @"CreateMenu");NSArray<UIView *> *capsuled = circled ? [items subarrayWithRange:NSMakeRange(0, items.count - 1)] : items;CGRect first = SGFrameIn(items.firstObject, tabBar);diff --git a/tweak/src/ui/Lyrics.x b/tweak/Sources/Features/NowPlaying/Lyrics.xsimilarity index 92%rename from tweak/src/ui/Lyrics.xrename to tweak/Sources/Features/NowPlaying/Lyrics.xindex 3659ddb9..b7c2b1da 100644--- a/tweak/src/ui/Lyrics.x+++ b/tweak/Sources/Features/NowPlaying/Lyrics.x@@ -11,10 +11,11 @@// the card reads as having grown to the screen.//// The album colour is the stubborn one: it arrives per track, after the page has laid out, and it-// comes back through a path ui/Repaint.x never sees, so a sweep at layout time loses the race.+// comes back through a path Appearance/Repaint.x never sees, so a sweep at layout time loses the race.// FullscreenView is asked not to keep it at all instead. The pane goes inside FullscreenView, in// front of whatever that view still fills itself with, rather than behind the whole page.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "NowPlaying.h"static const CGFloat kCardRadius = 16;static char kCardGlassKey, kPageGlassKey;@@ -35,10 +36,10 @@ static UIView *cellAround(UIView *view) {%orig;if (!SGEnabled(SGKeyLyricsCard)) return;UIView *cell = cellAround((UIView *)self);- // A card ui/Declutter.x collapsed reports no height; leave it alone.+ // A card Declutter/Declutter.x collapsed reports no height; leave it alone.if (!cell || cell.bounds.size.height < 40) return;// Spotify repaints the card with the album colour when the track changes, which is no layout- // pass of its own; ui/Repaint.x keeps it clear in between.+ // pass of its own; Appearance/Repaint.x keeps it clear in between.sg_lyricsCardRoot = cell;SGStripBackgrounds(cell);UIVisualEffectView *glass = SGGlassFor(cell, &kCardGlassKey);diff --git a/tweak/Sources/Features/NowPlaying/NowPlaying.h b/tweak/Sources/Features/NowPlaying/NowPlaying.hnew file mode 100644index 00000000..5709d597--- /dev/null+++ b/tweak/Sources/Features/NowPlaying/NowPlaying.h@@ -0,0 +1,11 @@+// Now Playing: the glass bar (NowPlayingBar.x), the full screen player (Player.x) and the lyrics+// card with the page it expands into (Lyrics.x). An unset switch is on; the backdrop is off until+// it is asked for.+#import <UIKit/UIKit.h>++#define SGKeyNowPlayingBar @"spotifyglass.nowPlayingBar"+#define SGKeyPlayer @"spotifyglass.player"+#define SGKeyPlayerBackdrop @"spotifyglass.playerBackdrop"+#define SGKeyLyricsCard @"spotifyglass.lyricsCard"++UIViewController *SGNowPlayingSettingsPage(void);diff --git a/tweak/src/ui/NowPlayingBar.x b/tweak/Sources/Features/NowPlaying/NowPlayingBar.xsimilarity index 98%rename from tweak/src/ui/NowPlayingBar.xrename to tweak/Sources/Features/NowPlaying/NowPlayingBar.xindex 2f333148..ae2c9bd3 100644--- a/tweak/src/ui/NowPlayingBar.x+++ b/tweak/Sources/Features/NowPlaying/NowPlayingBar.x@@ -3,14 +3,15 @@//// The full screen player does not fade in over the bar, it morphs the bar's own card and artwork// into the cover art, so for the length of that animation the bar is handed back: the rounding-// this file applied is undone, the album colour returns through ui/Repaint.x and the glass fades+// this file applied is undone, the album colour returns through Appearance/Repaint.x and the glass fades// out. Without that the card animates from a transparent circle-artwork bar into the player and// reads as a cut. Coming back the glass dissolves in as the artwork settles.//// Tree (trees/home.txt): NowPlayingBarContainerViewController.view 402x56 > NowPlayingBarViewController.view// at {8,0} 386x56 > UIView 386x56 (the painted card) > artwork 40x40 r=4, title stack,// progress line 370x2 at the bottom. The glass pane goes on the container's view.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "NowPlaying.h"static const CGFloat kCardRadius = 24;static const NSTimeInterval kFadeOut = 0.12, kFadeIn = 0.2;diff --git a/tweak/Sources/Features/NowPlaying/NowPlayingSettings.m b/tweak/Sources/Features/NowPlaying/NowPlayingSettings.mnew file mode 100644index 00000000..014b8d98--- /dev/null+++ b/tweak/Sources/Features/NowPlaying/NowPlayingSettings.m@@ -0,0 +1,71 @@+#import "Settings/SGModPage.h"+#import "NowPlaying.h"+#import "Features/Declutter/Declutter.h"++static UIViewController *lyricsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:SGRestartNote sections:@[+ SGSection(@"Spotify's flags", @[+ SGFlagRow(@"Translations in the player", @"ios-feature-lyrics.enable_lyrics_multilanguage_npv"),+ SGFlagRow(@"Translations full screen", @"ios-feature-lyrics.enable_lyrics_multilanguage_fullscreen"),+ SGFlagRow(@"Keep lyrics offline", @"ios-feature-lyrics.lyrics_offline_enabled"),+ SGFlagRow(@"Vocal removal", @"ios-feature-lyrics.enable_vocal_removal"),+ SGFlagRow(@"Lyrics toggle in the context menu", @"ios-feature-lyrics.lyrics_context_menu_toggle_enabled"),+ SGFlagRow(@"Dynamic colours", @"ios-feature-lyrics.enable_dynamic_colors"),+ SGFlagRow(@"Centre a single line", @"ios-feature-lyrics.is_single_line_centering_enabled"),+ SGFlagRow(@"Full screen on track change", @"ios-feature-lyrics.enable_fullscreen_track_change"),+ SGFlagRow(@"Edit lyrics", @"ios-feature-lyrics.lyrics_edit_enabled"),+ ]),+ ] footer:nil];+}++UIViewController *SGNowPlayingSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Now Playing" intro:SGRestartNote sections:@[+ SGSection(@"Liquid Glass", @[+ SGSwitchRow(@"Now playing bar", @"Glass card with round artwork", SGKeyNowPlayingBar),+ SGOptionRow(@"Artwork background", @"The cover blurred and dimmed behind the player instead of the flat album colour", SGKeyPlayerBackdrop),+ SGSwitchRow(@"Header buttons", @"Glass circles behind close and more, over the artwork", SGKeyPlayer),+ SGSwitchRow(@"Lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard),+ ]),+ SGSection(@"Spotify's flags", @[+ SGFlagRow(@"Sheet style player", @"ios-feature-nowplaying.sheet_style_npv"),+ SGFlagRow(@"Queue as a bottom sheet", @"ios-feature-nowplaying.bottom_sheet_queue_enabled"),+ SGFlagRow(@"Queue flip transition", @"ios-feature-nowplaying.queue_flip_transition_enabled"),+ SGFlagRow(@"Mini player transition animations", @"ios-feature-nowplaying.miniplayer_transition_animations"),+ SGFlagRow(@"Bar to cover art animation", @"ios-feature-nowplaying.bartocoverart_animation_enabled"),+ SGFlagRow(@"White heart button", @"ios-feature-nowplaying.white_heart_button_in_nowplaying_screen"),+ SGFlagRow(@"Expand the sticky header on tap", @"ios-feature-nowplaying.expand_sticky_header_on_tap"),+ SGFlagRow(@"Cover art in the header", @"ios-feature-nowplaying.show_header_context_cover_art"),+ SGFlagRow(@"Redesigned header with context menu", @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled"),+ SGFlagRow(@"Picture in picture", @"ios-feature-nowplaying.picture_in_picture"),+ SGFlagRow(@"Video in the mini player", @"ios-feature-nowplaying.video_in_miniplayer"),+ ]),+ SGSection(@"Lock screen", @[+ SGFlagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled"),+ ]),+ SGSection(@"Hide buttons", @[+ SGHideRow(@"Shuffle", @"Left of the playback controls", SGHideShuffle),+ SGHideRow(@"Repeat", @"Right of the playback controls", SGHideRepeat),+ SGHideRow(@"Connect to a device", @"The speaker and device name in the bottom row", SGHideConnect),+ SGHideRow(@"Share", @"The share button in the bottom row", SGHideShare),+ SGHideRow(@"Queue", @"The queue button in the bottom row", SGHideQueue),+ SGHideRow(@"Add to playlist", @"The plus next to the track title", SGHideAddTo),+ ]),+ SGSection(@"Under the artwork", @[+ SGHideRow(@"Lyrics preview", @"The lyric lines shown under the artwork", SGHideLyricsInline),+ ]),+ SGSection(@"Hide cards below the player", @[+ SGHideRow(@"Lyrics", @"The lyrics card", SGHideLyricsCard),+ SGHideRow(@"About the artist", @"Photo, listeners and biography", SGHideAboutArtist),+ SGHideRow(@"Related videos", @"The video carousel", SGHideRelatedVideos),+ SGHideRow(@"SongDNA", @"Discover the people behind the song", SGHideSongDNA),+ SGHideRow(@"Live events", @"Concerts and tickets", SGHideLiveEvents),+ SGHideRow(@"Explore the artist", @"The vertical video cards", SGHideExploreArtist),+ SGHideRow(@"Credits", @"Performers and writers", SGHideCredits),+ SGHideRow(@"Merch", @"The artist's shop", SGHideMerch),+ SGHideRow(@"Recommendations", @"\"Artist: what you might like\", the episode and track rows", SGHideRecommendations),+ ]),+ SGSection(nil, @[+ SGPageRow(@"Lyrics", ^UIViewController *{ return lyricsPage(); }),+ ]),+ ] footer:nil];+}diff --git a/tweak/src/ui/NowPlayingView.x b/tweak/Sources/Features/NowPlaying/Player.xsimilarity index 97%rename from tweak/src/ui/NowPlayingView.xrename to tweak/Sources/Features/NowPlaying/Player.xindex 808a51cd..d9611035 100644--- a/tweak/src/ui/NowPlayingView.x+++ b/tweak/Sources/Features/NowPlaying/Player.x@@ -6,7 +6,7 @@// shuffle, repeat, previous, next and the footer (connect, share, queue) are bare glyphs over the// artwork next to Spotify's white play disc: a pane each turned both rows into a strip of glass// discs sampling one another, which is the one thing the material cannot do. The cards below the-// player are surfaces rather than controls; the lyrics one is in ui/Lyrics.x.+// player are surfaces rather than controls; the lyrics one is in NowPlaying/Lyrics.x.//// Tree (trees/now-playing.txt): NowPlaying_ModesImpl units, each a child controller whose view// holds one UIStackView row; the header row is chevron 48x48, playlist name 110x48, more 48x48.@@ -20,7 +20,9 @@// covers what that field changes around it too: the artwork takes corners and a shadow so it sits// on the field rather than being pasted onto it, the lyric under it drops behind the title in// contrast, and the timestamps take monospaced digits so they stop twitching every second.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "NowPlaying.h"+#import "Features/Appearance/Appearance.h"static const CGFloat kButtonMin = 36, kButtonMax = 48;static const CGFloat kArtRadius = 12;@@ -36,7 +38,7 @@ static BOOL backdropOn(void) {// A glass circle per round button in the unit's row: children about as wide as they are tall.// The playlist name is 110 wide against 48 tall, so it keeps no pane, and neither do the children-// ui/Declutter.x made invisible.+// Declutter/Declutter.x made invisible.static void glassBehindRoundButtons(UIViewController *unit) {if (!SGEnabled(SGKeyPlayer)) return;UIView *host = unit.viewIfLoaded;@@ -211,7 +213,7 @@ static UIView *backdropIn(UIView *plane) {- (void)layoutSubviews {%orig;// White at full strength, and alone in the space under the artwork, the line reads louder than- // the title it sits above. ui/Declutter.x hides the same view outright.+ // the title it sits above. Declutter/Declutter.x hides the same view outright.if (backdropOn()) ((UIView *)self).alpha = 0.72;}%enddiff --git a/tweak/Sources/Features/Playlist/Playlist.h b/tweak/Sources/Features/Playlist/Playlist.hnew file mode 100644index 00000000..251e96da--- /dev/null+++ b/tweak/Sources/Features/Playlist/Playlist.h@@ -0,0 +1,16 @@+// Playlist: parts of the playlist page hidden one switch each (Playlist.x). An unset switch is off.+#import <UIKit/UIKit.h>++#define SGHidePlaylistArtwork @"spotifyglass.hide.playlistArtwork"+#define SGHidePlaylistDescription @"spotifyglass.hide.playlistDescription"+#define SGHidePlaylistCreator @"spotifyglass.hide.playlistCreator"+#define SGHidePlaylistLength @"spotifyglass.hide.playlistLength"+#define SGHidePlaylistVideo @"spotifyglass.hide.playlistVideo"+#define SGHidePlaylistAddTo @"spotifyglass.hide.playlistAddTo"+#define SGHidePlaylistDownload @"spotifyglass.hide.playlistDownload"+#define SGHidePlaylistShare @"spotifyglass.hide.playlistShare"+#define SGHidePlaylistMore @"spotifyglass.hide.playlistMore"+#define SGHidePlaylistPills @"spotifyglass.hide.playlistPills"+#define SGHidePlaylistFind @"spotifyglass.hide.playlistFind"++UIViewController *SGPlaylistSettingsPage(void);diff --git a/tweak/src/ui/Playlist.x b/tweak/Sources/Features/Playlist/Playlist.xsimilarity index 99%rename from tweak/src/ui/Playlist.xrename to tweak/Sources/Features/Playlist/Playlist.xindex c342134c..1e6cd8f5 100644--- a/tweak/src/ui/Playlist.x+++ b/tweak/Sources/Features/Playlist/Playlist.x@@ -13,7 +13,8 @@// The header's height is not measured from what it shows: -[SPTFreeTierPlaylistEncoreHeaderViewController// update] adds three numbers into a stored fullHeaderHeight and pins headerViewHeightConstraint to// it, so a hidden cover leaves the room it was counted for. collapseCover() takes that room back.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Playlist.h"@interface NSObject (SGPlaylistHeader)- (NSLayoutConstraint *)headerViewHeightConstraint;diff --git a/tweak/Sources/Features/Playlist/PlaylistSettings.m b/tweak/Sources/Features/Playlist/PlaylistSettings.mnew file mode 100644index 00000000..de04711f--- /dev/null+++ b/tweak/Sources/Features/Playlist/PlaylistSettings.m@@ -0,0 +1,24 @@+#import "Settings/SGModPage.h"+#import "Playlist.h"++UIViewController *SGPlaylistSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Playlist" intro:SGRestartNote sections:@[+ SGSection(@"Hide in the header", @[+ SGHideRow(@"Cover artwork", @"The square cover over the title", SGHidePlaylistArtwork),+ SGHideRow(@"Description", @"The text under the title", SGHidePlaylistDescription),+ SGHideRow(@"Creator and collaborators", @"The faces, the name and Message", SGHidePlaylistCreator),+ SGHideRow(@"Length and saves", @"The line under the creator", SGHidePlaylistLength),+ ]),+ SGSection(@"Hide header buttons", @[+ SGHideRow(@"Video", @"The stack of clips at the start of the row", SGHidePlaylistVideo),+ SGHideRow(@"Add to library", @"The plus", SGHidePlaylistAddTo),+ SGHideRow(@"Download", @"The download arrow", SGHidePlaylistDownload),+ SGHideRow(@"Share", @"The button that opens the share sheet", SGHidePlaylistShare),+ SGHideRow(@"More", @"The three dots at the end of the row", SGHidePlaylistMore),+ ]),+ SGSection(@"Hide over the tracks", @[+ SGHideRow(@"Curation pills", @"Add, Mix, Video, Edit, Sort and the rest", SGHidePlaylistPills),+ SGHideRow(@"Find and sort bar", @"Find on page and Sort, under the header", SGHidePlaylistFind),+ ]),+ ] footer:nil];+}diff --git a/tweak/Sources/Features/Privacy/Privacy.h b/tweak/Sources/Features/Privacy/Privacy.hnew file mode 100644index 00000000..3ffcbedc--- /dev/null+++ b/tweak/Sources/Features/Privacy/Privacy.h@@ -0,0 +1,13 @@+// Privacy: telemetry blocking (Privacy.x), an NSURLProtocol that answers the analytics endpoints+// itself and counts what it stopped. On unless switched off.+#import <UIKit/UIKit.h>++#define SGKeyBlockTelemetry @"spotifyglass.blockTelemetry"++// The destinations it knows in the order it lists them, and how many requests to one of them it+// has answered instead of letting out (nil label for all of them).+NSArray<NSString *> *SGBlockedLabels(void);+NSUInteger SGBlockedCount(NSString *label);+void SGResetBlocked(void);++UIViewController *SGPrivacySettingsPage(void);diff --git a/tweak/src/SGPrivacy.x b/tweak/Sources/Features/Privacy/Privacy.xsimilarity index 99%rename from tweak/src/SGPrivacy.xrename to tweak/Sources/Features/Privacy/Privacy.xindex 6cc19a73..2302c6ab 100644--- a/tweak/src/SGPrivacy.x+++ b/tweak/Sources/Features/Privacy/Privacy.x@@ -12,7 +12,8 @@// sessions from. What the core sends over its own sockets is out of reach either way, and the// counter is what tells the two apart -- Spotify events climbing in it means those events travel// over NSURLSession after all.-#import "SGCommon.h"+#import "Core/SGCore.h"+#import "Privacy.h"typedef struct { const char *host, *path, *label; } SGBlockRule;diff --git a/tweak/Sources/Features/Privacy/PrivacySettings.m b/tweak/Sources/Features/Privacy/PrivacySettings.mnew file mode 100644index 00000000..b60c9d56--- /dev/null+++ b/tweak/Sources/Features/Privacy/PrivacySettings.m@@ -0,0 +1,23 @@+#import "Settings/SGModPage.h"+#import "Privacy.h"++UIViewController *SGPrivacySettingsPage(void) {+ NSMutableArray<SGModRow *> *counts = [NSMutableArray array];+ for (NSString *label in SGBlockedLabels()) {+ [counts addObject:SGStatRow(label, ^NSString *{+ return @(SGBlockedCount(label)).stringValue;+ })];+ }+ [counts addObject:SGStatRow(@"Total", ^NSString *{+ return @(SGBlockedCount(nil)).stringValue;+ })];+ return [[SGModPage alloc] initWithTitle:@"Privacy" intro:SGRestartNote sections:@[+ SGSection(@"Telemetry", @[+ SGSwitchRow(@"Block telemetry", @"Answer the analytics endpoints with an empty reply instead of letting the request out", SGKeyBlockTelemetry),+ ]),+ SGSection(@"Blocked so far", counts),+ SGSection(nil, @[+ SGActionRow(@"Reset the counters", @"Start counting from zero", ^{ SGResetBlocked(); }),+ ]),+ ] footer:nil];+}diff --git a/tweak/Sources/Headers/SPTEncoreIconView.h b/tweak/Sources/Headers/SPTEncoreIconView.hnew file mode 100644index 00000000..f49f293b--- /dev/null+++ b/tweak/Sources/Headers/SPTEncoreIconView.h@@ -0,0 +1,8 @@+// Spotify's glyph view, from SpotifyShared.framework. It bakes its colour into what it draws, so+// tintColor never reaches it and setForegroundColor: is the way in.+#import <UIKit/UIKit.h>++@interface SPTEncoreIconView : UIView+- (instancetype)initWithIcon:(id)icon;+- (void)setForegroundColor:(UIColor *)color;+@enddiff --git a/tweak/Sources/Headers/SPTLinkDispatcherImplementation.h b/tweak/Sources/Headers/SPTLinkDispatcherImplementation.hnew file mode 100644index 00000000..db5e4910--- /dev/null+++ b/tweak/Sources/Headers/SPTLinkDispatcherImplementation.h@@ -0,0 +1,7 @@+// Spotify's link dispatcher, a singleton the app builds at startup; the route the app itself takes+// for a link it opens.+#import <Foundation/Foundation.h>++@interface SPTLinkDispatcherImplementation : NSObject+- (void)navigateToURI:(NSURL *)uri options:(long long)options interactionID:(id)interactionID;+@enddiff --git a/tweak/Sources/Settings/SGModPage.h b/tweak/Sources/Settings/SGModPage.hnew file mode 100644index 00000000..1ac936b8--- /dev/null+++ b/tweak/Sources/Settings/SGModPage.h@@ -0,0 +1,47 @@+// A page of sections of rows, the shape of every feature's settings page.+#import "SGPage.h"++// A row is a switch when it has a key and a link to another page when it has a page. A flag row+// switches one of Spotify's remote-config flags: on forces it (off for a forceOff row, which is how+// a flag Spotify ships on is turned off), the switch off leaves Spotify's own value. A row+// with a value reads one out on the right and is asked again while the page is open; a row with an+// action runs it when tapped.+@interface SGModRow : NSObject+@property (nonatomic, copy) NSString *title;+@property (nonatomic, copy) NSString *subtitle;+@property (nonatomic, copy) NSString *key;+@property (nonatomic) BOOL defaultOn;+@property (nonatomic) BOOL flag;+@property (nonatomic) BOOL forceOff;+@property (nonatomic, copy) UIViewController *(^page)(void);+@property (nonatomic, copy) NSString *(^value)(void);+@property (nonatomic, copy) void (^action)(void);+@property (nonatomic, copy) NSString *warning;+@end++@interface SGModSection : NSObject+@property (nonatomic, copy) NSString *title;+@property (nonatomic, copy) NSArray<SGModRow *> *rows;+@end++@interface SGModPage : SGPage+- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer;+@end++// The intro of every page whose switches the hooks read at launch.+extern NSString *const SGRestartNote;++SGModRow *SGSwitchRow(NSString *title, NSString *subtitle, NSString *key); // on until switched off+SGModRow *SGHideRow(NSString *title, NSString *subtitle, NSString *key); // off until switched on+// A switch for something the mod adds rather than takes away: off until it is asked for.+SGModRow *SGOptionRow(NSString *title, NSString *subtitle, NSString *key);+// A switch whose work is not finished: turning it on says so first, and offers the repo.+SGModRow *SGUnstableRow(NSString *title, NSString *subtitle, NSString *key, NSString *warning);+SGModRow *SGFlagRow(NSString *title, NSString *key); // forces one of Spotify's flags on+SGModRow *SGKillRow(NSString *title, NSString *key); // forces a flag Spotify ships on off+SGModRow *SGStatRow(NSString *title, NSString *(^value)(void));+SGModRow *SGActionRow(NSString *title, NSString *subtitle, void (^action)(void));+SGModRow *SGPageRow(NSString *title, UIViewController *(^page)(void));+SGModRow *SGLinkRow(NSString *title, NSString *subtitle, NSString *url);+SGModRow *SGStatActionRow(NSString *title, NSString *subtitle, NSString *(^value)(void), void (^action)(void));+SGModSection *SGSection(NSString *title, NSArray<SGModRow *> *rows);diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.mnew file mode 100644index 00000000..ce9724ba--- /dev/null+++ b/tweak/Sources/Settings/SGModPage.m@@ -0,0 +1,264 @@+#import "SGModPage.h"+#import "SGPageStyle.h"+#import "Core/SGCore.h"+#import "Features/Flags/Flags.h"+#import "Features/About/About.h"++NSString *const SGRestartNote = @"Changes apply after you restart Spotify.";++@implementation SGModRow+@end++@implementation SGModSection+@end++SGModRow *SGSwitchRow(NSString *title, NSString *subtitle, NSString *key) {+ SGModRow *row = [SGModRow new];+ row.title = title;+ row.subtitle = subtitle;+ row.key = key;+ row.defaultOn = YES;+ return row;+}++SGModRow *SGHideRow(NSString *title, NSString *subtitle, NSString *key) {+ SGModRow *row = SGSwitchRow(title, subtitle, key);+ row.defaultOn = NO;+ return row;+}++// A switch for something the mod adds rather than takes away: off until it is asked for.+SGModRow *SGOptionRow(NSString *title, NSString *subtitle, NSString *key) {+ SGModRow *row = SGSwitchRow(title, subtitle, key);+ row.defaultOn = NO;+ return row;+}++// A switch whose work is not finished: turning it on says so first, and offers the repo to anyone+// who would rather fix it than live with it.+SGModRow *SGUnstableRow(NSString *title, NSString *subtitle, NSString *key, NSString *warning) {+ SGModRow *row = SGSwitchRow(title, subtitle, key);+ row.warning = warning;+ return row;+}++SGModRow *SGFlagRow(NSString *title, NSString *key) {+ SGModRow *row = SGHideRow(title, [key substringFromIndex:[key rangeOfString:@"."].location + 1], key);+ row.flag = YES;+ return row;+}++// A flag Spotify ships on: the switch forces it off.+SGModRow *SGKillRow(NSString *title, NSString *key) {+ SGModRow *row = SGFlagRow(title, key);+ row.forceOff = YES;+ return row;+}++SGModRow *SGStatRow(NSString *title, NSString *(^value)(void)) {+ SGModRow *row = [SGModRow new];+ row.title = title;+ row.value = value;+ return row;+}++SGModRow *SGActionRow(NSString *title, NSString *subtitle, void (^action)(void)) {+ SGModRow *row = [SGModRow new];+ row.title = title;+ row.subtitle = subtitle;+ row.action = action;+ return row;+}++// No subtitle: a list of pages reads as a list, not as a wall of explanations.+SGModRow *SGPageRow(NSString *title, UIViewController *(^page)(void)) {+ SGModRow *row = [SGModRow new];+ row.title = title;+ row.page = page;+ return row;+}++SGModRow *SGLinkRow(NSString *title, NSString *subtitle, NSString *url) {+ return SGActionRow(title, subtitle, ^{ SGOpenURL(url); });+}++// A value on the right and a tap: the Updates row reads its status out of About/Update.m every tick,+// and a tap asks the site again instead of waiting for the six hour cache to lapse.+SGModRow *SGStatActionRow(NSString *title, NSString *subtitle, NSString *(^value)(void), void (^action)(void)) {+ SGModRow *row = [SGModRow new];+ row.title = title;+ row.subtitle = subtitle;+ row.value = value;+ row.action = action;+ return row;+}++SGModSection *SGSection(NSString *title, NSArray<SGModRow *> *rows) {+ SGModSection *s = [SGModSection new];+ s.title = title;+ s.rows = rows;+ return s;+}++// On means the row's own override is in place; anything else, including the opposite override+// somebody set from the All flags page, reads as off.+static BOOL flagRowOn(SGModRow *row) {+ id value = SGFlagOverride(row.key);+ return value && [value boolValue] != row.forceOff;+}++// A flag the Spotify's own Liquid Glass switch owns: its row shows what that switch forces and+// takes no touch, so the flag has one place to change. An override from All flags still wins.+static BOOL flagRowLocked(SGModRow *row) {+ return row.flag && SGGlassOwnsFlag(row.key) && SGEnabled(SGKeySpotifyGlass);+}++@implementation SGModPage {+ NSArray<SGModSection *> *_sections;+ UIView *_intro;+ UIView *_footer;+ NSTimer *_ticker;+ BOOL _live;+}++- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer {+ if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;+ self.title = title;+ _sections = sections;+ _intro = intro ? SGNote(intro) : nil;+ _footer = footer ? SGNote(footer) : nil;+ for (SGModSection *s in sections) for (SGModRow *row in s.rows) _live |= row.value != nil;+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.tableView.backgroundColor = SGPageBackground();+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;+ self.tableView.sectionHeaderTopPadding = 0;+ self.tableView.tableHeaderView = _intro;+ self.tableView.tableFooterView = _footer;+}++- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ if (_intro) SGFitNote(self.tableView, _intro, 24, 0);+ if (_footer) SGFitNote(self.tableView, _footer, 16, 24);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ SGInsetForBars(self.tableView);+}++- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ if (!_live) return;+ [self.tableView reloadData];+ // The counters climb while the page is open; the labels are written straight into the cells so+ // that a reload never lands under a switch being dragged.+ _ticker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(readValues) userInfo:nil repeats:YES];+}++- (void)viewDidDisappear:(BOOL)animated {+ [super viewDidDisappear:animated];+ [_ticker invalidate];+ _ticker = nil;+}++- (void)readValues {+ for (UITableViewCell *cell in self.tableView.visibleCells) {+ SGModRow *row = [self rowAt:[self.tableView indexPathForCell:cell]];+ UILabel *label = (UILabel *)cell.accessoryView;+ if (!row.value || ![label isKindOfClass:UILabel.class]) continue;+ label.text = row.value();+ [label sizeToFit];+ [cell setNeedsLayout];+ }+}++- (SGModRow *)rowAt:(NSIndexPath *)path {+ return _sections[(NSUInteger)path.section].rows[(NSUInteger)path.row];+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return (NSInteger)_sections.count;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return (NSInteger)_sections[(NSUInteger)section].rows.count;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ NSString *title = _sections[(NSUInteger)section].title;+ return title ? SGSectionHeader(table, title) : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ return _sections[(NSUInteger)section].title ? SGSectionHeaderHeight : CGFLOAT_MIN;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"row");+ SGModRow *row = [self rowAt:path];+ SGFillCell(cell, row.title, row.subtitle, nil, nil);++ if (row.key) {+ UISwitch *toggle = [UISwitch new];+ toggle.onTintColor = SGGreen();+ BOOL locked = flagRowLocked(row);+ toggle.on = row.flag ? (locked && !SGFlagOverride(row.key) ? YES : flagRowOn(row)) : SGFlag(row.key, row.defaultOn);+ toggle.enabled = !locked;+ toggle.tag = path.section * 1000 + path.row;+ [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];+ cell.accessoryView = toggle;+ } else if (row.page) {+ cell.accessoryView = SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ } else if (row.value) {+ UILabel *label = [UILabel new];+ label.font = SGTitleFont();+ label.textColor = SGGrey();+ label.text = row.value();+ [label sizeToFit];+ cell.accessoryView = label;+ cell.selectionStyle = row.action ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;+ } else if (row.action) {+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ }+ return cell;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ SGModRow *row = [self rowAt:path];+ if (row.page) [self.navigationController pushViewController:row.page() animated:YES];+ if (!row.action) return;+ row.action();+ [table deselectRowAtIndexPath:path animated:YES];+ [self readValues];+}++- (void)toggled:(UISwitch *)toggle {+ SGModRow *row = [self rowAt:[NSIndexPath indexPathForRow:toggle.tag % 1000 inSection:toggle.tag / 1000]];+ if (row.flag) SGSetFlagOverride(row.key, toggle.on ? @(!row.forceOff) : nil);+ else SGSetEnabled(row.key, toggle.on);+ if (toggle.on && row.warning) [self warn:row];+}++- (void)warn:(SGModRow *)row {+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:[row.title stringByAppendingString:@" is unstable"]+ message:row.warning+ preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"Open GitHub" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {+ SGOpenURL(SGRepoURL);+ }]];+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];+ [self presentViewController:alert animated:YES completion:nil];+}++@enddiff --git a/tweak/Sources/Settings/SGModSettings.x b/tweak/Sources/Settings/SGModSettings.xnew file mode 100644index 00000000..6983fc65--- /dev/null+++ b/tweak/Sources/Settings/SGModSettings.x@@ -0,0 +1,172 @@+// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own pages:+// UI Tweaks, Home, Playlist and Now Playing, each sections of switches (the mod's own and a few of+// Spotify's remote-config flags), Navbar, the tab bar's own composition, and All flags, a+// searchable list of every flag with an override per flag. The tweaks read the switches when they+// run, so a change shows after Spotify restarts; the Navbar page is the exception and applies as+// soon as the bar lays out again.+//+// Tree (trees/settings.txt): SettingsListViewController.view > SettingsListCollectionView of+// Element_List cells 402x56: 24pt icon at x 12, 13pt white title and 11pt grey subtitle at+// x 48, 12pt chevron on the right. A pushed page (trees/settings notifications opened.txt) is a+// UITableView bg #121212: header with an 11pt grey description at (16, 24), 53pt cells with the+#import "Core/SGCore.h"+#import "SGPage.h"+#import "SGPageStyle.h"+#import "SGModPage.h"+#import "Features/Appearance/Appearance.h"+#import "Features/Navbar/Navbar.h"+#import "Features/Home/Home.h"+#import "Features/Playlist/Playlist.h"+#import "Features/NowPlaying/NowPlaying.h"+#import "Features/Flags/Flags.h"+#import "Features/Privacy/Privacy.h"+#import "Features/About/About.h"++static const CGFloat kRowHeight = 56;+static char kRowKey, kInsetKey;++static UIViewController *modSettingsPage(void) {+ // Opening the page is the only thing that asks; the cache keeps it to once every six hours.+ SGCheckForUpdate(NO);+ return [[SGModPage alloc] initWithTitle:@"Mod Settings" intro:nil sections:@[+ SGSection(nil, @[+ SGPageRow(@"UI Tweaks", ^UIViewController *{ return SGAppearanceSettingsPage(); }),+ SGPageRow(@"Navbar", ^UIViewController *{ return SGNavbarSettingsPage(); }),+ SGPageRow(@"Home & Library", ^UIViewController *{ return SGHomeSettingsPage(); }),+ SGPageRow(@"Playlist", ^UIViewController *{ return SGPlaylistSettingsPage(); }),+ SGPageRow(@"Now Playing", ^UIViewController *{ return SGNowPlayingSettingsPage(); }),+ SGPageRow(@"Lock screen widget", ^UIViewController *{ return SGLockScreenSettingsPage(); }),+ SGPageRow(@"Playback", ^UIViewController *{ return SGPlaybackSettingsPage(); }),+ SGPageRow(@"Ads & nags", ^UIViewController *{ return SGAdsSettingsPage(); }),+ SGPageRow(@"Unreleased", ^UIViewController *{ return SGUnreleasedSettingsPage(); }),+ SGPageRow(@"Experimental", ^UIViewController *{ return SGExperimentalSettingsPage(); }),+ SGPageRow(@"Privacy", ^UIViewController *{ return SGPrivacySettingsPage(); }),+ SGPageRow(@"All flags", ^UIViewController *{ return SGAllFlagsPage(); }),+ ]),+ SGAboutSection(),+ ] footer:nil];+}++#pragma mark - row in the settings list++@interface SGModSettingsRow : UIControl+@end++@implementation SGModSettingsRow {+ UIImageView *_icon;+ UILabel *_title;+ UIImageView *_chevron;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ _icon = SGSymbolView(@"slider.horizontal.3", 20, UIImageSymbolWeightRegular, 24);+ _title = [UILabel new];+ _title.text = @"Mod Settings";+ _title.textColor = UIColor.whiteColor;+ _chevron = SGSymbolView(@"chevron.right", 11, UIImageSymbolWeightSemibold, 12);+ for (UIView *v in @[_icon, _title, _chevron]) [self addSubview:v];+ [self addTarget:self action:@selector(open) forControlEvents:UIControlEventTouchUpInside];+ return self;+}++- (void)layoutSubviews {+ [super layoutSubviews];+ _title.font = SGTitleFont();+ CGFloat width = self.bounds.size.width, height = self.bounds.size.height;+ _icon.frame = CGRectMake(12, (height - 24) / 2, 24, 24);+ _title.frame = CGRectMake(48, 0, width - 96, height);+ _chevron.frame = CGRectMake(width - 24, (height - 12) / 2, 12, 12);+}++- (void)setHighlighted:(BOOL)highlighted {+ [super setHighlighted:highlighted];+ self.alpha = highlighted ? 0.5 : 1;+}++- (void)open {+ UIViewController *owner = nil;+ for (UIResponder *r = self; r && !owner; r = r.nextResponder) {+ if ([r isKindOfClass:UIViewController.class]) owner = (UIViewController *)r;+ }+ SGShowPage(owner, modSettingsPage());+}++@end++static void placeRow(UICollectionView *list, SGModSettingsRow *row) {+ SGAdoptFonts(list, row);+ CGFloat bottom = list.contentSize.height;+ row.hidden = bottom <= 0;+ row.frame = CGRectMake(0, bottom, list.bounds.size.width, kRowHeight);++ // Room to scroll to the row, added again whenever Spotify resets the inset.+ UIEdgeInsets inset = list.contentInset;+ NSValue *applied = objc_getAssociatedObject(list, &kInsetKey);+ if (applied && UIEdgeInsetsEqualToEdgeInsets(inset, applied.UIEdgeInsetsValue)) return;+ inset.bottom += kRowHeight;+ objc_setAssociatedObject(list, &kInsetKey, [NSValue valueWithUIEdgeInsets:inset], OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ list.contentInset = inset;+}++// Media quality, Playback, Account and most of the rest of settings are the same controller class+// as the list they were opened from, which is why the row turned up at the end of all of them.+// What is on the navigation stack is not that controller though: every page in the app is wrapped+// in a MusicAppPageHostingViewController (trees/settings notifications opened.txt), and Spotify+// pushes a settings sub page as a page of its own, leaving the list it came from on the stack+// underneath. So the settings list inside the lowest wrapper that holds one is the list the row+// belongs at the end of, and a controller with no stack to be found on keeps the row rather than+// losing it.+static UIViewController *settingsListIn(UIViewController *page, Class kind) {+ if ([page isKindOfClass:kind]) return page;+ for (UIViewController *child in page.childViewControllers) {+ UIViewController *found = settingsListIn(child, kind);+ if (found) return found;+ }+ return nil;+}++static BOOL isSettingsRoot(UIViewController *list) {+ for (UIViewController *page in list.navigationController.viewControllers) {+ UIViewController *found = settingsListIn(page, list.class);+ if (found) return found == list;+ }+ return YES;+}++%hook _TtC21Settings_PlatformImpl26SettingsListViewController+- (void)viewDidLayoutSubviews {+ %orig;+ BOOL root = isSettingsRoot((UIViewController *)self);+ for (UIView *sub in ((UIViewController *)self).view.subviews) {+ if (![sub isKindOfClass:UICollectionView.class]) continue;+ SGModSettingsRow *row = objc_getAssociatedObject(sub, &kRowKey);+ // A page that laid itself out before it was on the stack looked like the list for as long+ // as that took; the row goes again as soon as it can be seen for what it is.+ if (!root) {+ [row removeFromSuperview];+ objc_setAssociatedObject(sub, &kRowKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ continue;+ }+ if (row) continue;+ row = [[SGModSettingsRow alloc] initWithFrame:CGRectZero];+ objc_setAssociatedObject(sub, &kRowKey, row, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ [sub addSubview:row];+ }+}+%end++// The list lays out after its controller and again whenever its content changes.+%hook UICollectionView+- (void)layoutSubviews {+ %orig;+ SGModSettingsRow *row = objc_getAssociatedObject(self, &kRowKey);+ if (row) placeRow(self, row);+}+%end++%ctor {+ %init;+ SGRequireClasses(@[@"_TtC21Settings_PlatformImpl26SettingsListViewController"]);+ SGRegisterPages();+}diff --git a/tweak/Sources/Settings/SGPage.h b/tweak/Sources/Settings/SGPage.hnew file mode 100644index 00000000..1afe2a50--- /dev/null+++ b/tweak/Sources/Settings/SGPage.h@@ -0,0 +1,10 @@+// The base of every page of the mod's, pushable onto Spotify's own navigation stack.+#import <UIKit/UIKit.h>++@interface SGPage : UITableViewController+@end++// Registers SGPage as one of Spotify's pages; called once, from the settings hook's %ctor.+void SGRegisterPages(void);+// Pushes the page if it can go on Spotify's stack, presents it otherwise.+void SGShowPage(UIViewController *owner, UIViewController *page);diff --git a/tweak/Sources/Settings/SGPage.m b/tweak/Sources/Settings/SGPage.mnew file mode 100644index 00000000..7cf72662--- /dev/null+++ b/tweak/Sources/Settings/SGPage.m@@ -0,0 +1,36 @@+#import "SGPage.h"+#import "Core/SGCore.h"+++// Spotify's navigation controller asserts that everything on its stack is one of its own pages+// (SPNavigationController.m:645, "[viewController conformsToProtocol:@protocol(SPTPageController)]"),+// and the tab bar asks it for that page on every tab tap to log the interaction. A plain view+// controller of the mod's pushed onto that stack therefore takes the app down the next time a tab+// is pressed, from wherever it was left. The pages below answer the protocol's two questions+// instead and are registered as conforming at load; if the protocol is gone they are presented+// rather than pushed, so a rename in some later Spotify costs the push, not the app.+static BOOL sg_pagesConform;++@implementation SGPage++- (NSString *)spt_pageIdentifier {+ return @"spotifyglass";+}++- (NSURL *)spt_pageURI {+ return [NSURL URLWithString:@"spotify:internal:spotifyglass"];+}++@end++void SGRegisterPages(void) {+ // Swift's own name for the protocol, which is what the runtime registers it under.+ Protocol *page = objc_getProtocol("_TtP19Tome_PageAttributes17SPTPageController_") ?: objc_getProtocol("SPTPageController");+ sg_pagesConform = page && class_addProtocol(SGPage.class, page);+ if (!sg_pagesConform) SGLog(@"SPTPageController not found, the mod's pages are presented instead of pushed");+}++void SGShowPage(UIViewController *owner, UIViewController *page) {+ if (owner.navigationController && sg_pagesConform) [owner.navigationController pushViewController:page animated:YES];+ else [owner presentViewController:[[UINavigationController alloc] initWithRootViewController:page] animated:YES completion:nil];+}diff --git a/tweak/Sources/Settings/SGPageStyle.h b/tweak/Sources/Settings/SGPageStyle.hnew file mode 100644index 00000000..3f0e67ea--- /dev/null+++ b/tweak/Sources/Settings/SGPageStyle.h@@ -0,0 +1,25 @@+// Spotify's own list look, for every page of the mod's: a 13pt white title over an 11pt grey+// subtitle on #121212, 38pt uppercase section headers, green switches.+#import <UIKit/UIKit.h>++UIColor *SGGrey(void);+UIColor *SGGreen(void);+UIColor *SGPageBackground(void);+UIFont *SGTitleFont(void);+UIFont *SGSubtitleFont(void);+// Takes the 13pt and 11pt fonts off Spotify's own settings list, once, so the pages match it.+void SGAdoptFonts(UIView *list, UIView *exclude);++UIImageView *SGSymbolView(NSString *name, CGFloat size, UIImageSymbolWeight weight, CGFloat box);+// A grey note in a wrapper view, for a table header or footer; SGFitNote sizes it to its text.+UIView *SGNote(NSString *text);+void SGFitNote(UITableView *table, UIView *wrapper, CGFloat top, CGFloat bottom);+// The now playing bar and the tab bar float over the content, so a page insets itself under them.+void SGInsetForBars(UITableView *table);++extern const CGFloat SGSectionHeaderHeight;+void SGFillCell(UITableViewCell *cell, NSString *title, NSString *subtitle, UIColor *color, NSString *symbolName);+UIView *SGSectionHeader(UITableView *table, NSString *title);+UITableViewCell *SGDequeueCell(UITableView *table, NSString *identifier);++void SGOpenURL(NSString *url);diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.mnew file mode 100644index 00000000..8a61680c--- /dev/null+++ b/tweak/Sources/Settings/SGPageStyle.m@@ -0,0 +1,139 @@+#import "SGPageStyle.h"+#import "Core/SGCore.h"++static UIFont *sg_titleFont, *sg_subtitleFont;++UIColor *SGGrey(void) { return [UIColor colorWithWhite:0xB3 / 255.0 alpha:1]; }+UIFont *SGTitleFont(void) { return sg_titleFont ?: [UIFont systemFontOfSize:13 weight:UIFontWeightBold]; }+UIFont *SGSubtitleFont(void) { return sg_subtitleFont ?: [UIFont systemFontOfSize:11]; }++UIImageView *SGSymbolView(NSString *name, CGFloat size, UIImageSymbolWeight weight, CGFloat box) {+ UIImage *image = [UIImage systemImageNamed:name withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:size weight:weight]];+ UIImageView *view = [[UIImageView alloc] initWithImage:image];+ view.tintColor = UIColor.whiteColor;+ view.contentMode = UIViewContentModeCenter;+ view.frame = CGRectMake(0, 0, box, box);+ return view;+}++// A grey note in a wrapper view, for the table header and footer.+UIView *SGNote(NSString *text) {+ UILabel *label = [UILabel new];+ label.text = text;+ label.font = SGSubtitleFont();+ label.textColor = SGGrey();+ label.numberOfLines = 0;+ UIView *wrapper = [UIView new];+ [wrapper addSubview:label];+ return wrapper;+}++// Header and footer views keep the height they are given, so size them to their text. Only the+// size is compared: the table moves the footer's origin itself, and reassigning on that would+// loop forever.+void SGFitNote(UITableView *table, UIView *wrapper, CGFloat top, CGFloat bottom) {+ UILabel *label = wrapper.subviews.firstObject;+ CGFloat width = table.bounds.size.width - 32;+ CGFloat height = ceil([label sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height);+ label.frame = CGRectMake(16, top, width, height);+ CGSize size = CGSizeMake(table.bounds.size.width, top + height + bottom);+ if (CGSizeEqualToSize(wrapper.bounds.size, size)) return;+ wrapper.frame = (CGRect){wrapper.frame.origin, size};+ if (wrapper == table.tableHeaderView) table.tableHeaderView = wrapper;+ else table.tableFooterView = wrapper;+}++static CGFloat barsHeight(UIView *view) {+ UIWindow *window = view.window;+ __block CGFloat top = window.bounds.size.height;+ SGForEachView(window, ^(UIView *v) {+ NSString *name = NSStringFromClass(v.class);+ BOOL bar = [name containsString:@"NowPlaying_BarPageImpl"] || [name isEqualToString:@"_TtC23NavigationUI_TabBarImpl10TabBarView"];+ if (!bar || v.hidden || v.alpha == 0 || v.bounds.size.height == 0) return;+ top = MIN(top, SGFrameIn(v, window).origin.y);+ });+ return window.bounds.size.height - top;+}++// The now playing bar and the tab bar float over the content, and the safe area does not cover+// them, so the pages inset themselves by however much of the window the bars take.+void SGInsetForBars(UITableView *table) {+ CGFloat bottom = MAX(0, barsHeight(table) - table.safeAreaInsets.bottom);+ if (table.contentInset.bottom == bottom) return;+ UIEdgeInsets inset = table.contentInset;+ inset.bottom = bottom;+ table.contentInset = inset;+ table.verticalScrollIndicatorInsets = inset;+}++UIColor *SGGreen(void) { return [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }+UIColor *SGPageBackground(void) { return [UIColor colorWithWhite:0x12 / 255.0 alpha:1]; }++const CGFloat SGSectionHeaderHeight = 38;++// Every page below draws Spotify's own list row: a 13pt white title over an 11pt grey subtitle,+// with an optional symbol in the leading slot.+void SGFillCell(UITableViewCell *cell, NSString *title, NSString *subtitle, UIColor *color, NSString *symbolName) {+ UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];+ content.text = title;+ content.secondaryText = subtitle;+ content.textProperties.font = SGTitleFont();+ content.textProperties.color = color ?: UIColor.whiteColor;+ content.secondaryTextProperties.font = SGSubtitleFont();+ content.secondaryTextProperties.color = SGGrey();+ content.textToSecondaryTextVerticalPadding = 0;+ content.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(10, 16, 10, 16);+ if (symbolName) {+ content.image = [UIImage systemImageNamed:symbolName withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:15 weight:UIImageSymbolWeightRegular]];+ content.imageProperties.tintColor = color ?: UIColor.whiteColor;+ content.imageToTextPadding = 14;+ }+ cell.contentConfiguration = content;+ cell.backgroundColor = UIColor.clearColor;+ cell.accessoryView = nil;+ cell.selectionStyle = UITableViewCellSelectionStyleNone;+}++UIView *SGSectionHeader(UITableView *table, NSString *title) {+ UILabel *label = [UILabel new];+ label.text = title.uppercaseString;+ label.font = SGSubtitleFont();+ label.textColor = SGGrey();+ label.frame = CGRectMake(16, 20, table.bounds.size.width - 32, 14);+ label.autoresizingMask = UIViewAutoresizingFlexibleWidth;+ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, SGSectionHeaderHeight)];+ [header addSubview:label];+ return header;+}++UITableViewCell *SGDequeueCell(UITableView *table, NSString *identifier) {+ return [table dequeueReusableCellWithIdentifier:identifier]+ ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];+}++static CGFloat brightness(UIColor *color) {+ CGFloat white = 0;+ [color getWhite:&white alpha:NULL];+ return white;+}++// Spotify's list labels carry its typeface: 13pt titles and 11pt grey subtitles.+void SGAdoptFonts(UIView *list, UIView *row) {+ if (sg_titleFont && sg_subtitleFont) return;+ SGForEachView(list, ^(UIView *v) {+ if (![v isKindOfClass:UILabel.class] || SGIsInside(v, row)) return;+ UILabel *label = (UILabel *)v;+ if (label.text.length < 2) return;+ CGFloat size = label.font.pointSize, white = brightness(label.textColor);+ if (size == 13 && !sg_titleFont) sg_titleFont = label.font;+ if (size == 11 && !sg_subtitleFont && white > 0.3 && white < 0.95) sg_subtitleFont = label.font;+ });+}++void SGOpenURL(NSString *url) {+ NSURL *target = url ? [NSURL URLWithString:url] : nil;+ if (!target) return;+ dispatch_async(dispatch_get_main_queue(), ^{+ [UIApplication.sharedApplication openURL:target options:@{} completionHandler:nil];+ });+}diff --git a/tweak/src/SGCommon.h b/tweak/src/SGCommon.hdeleted file mode 100644index a55a4b21..00000000--- a/tweak/src/SGCommon.h+++ /dev/null@@ -1,179 +0,0 @@-// Shared declarations for every spotifyglass source file.-#import <UIKit/UIKit.h>-#import <objc/runtime.h>-#import <os/log.h>--// iOS 26 API, absent from the SDK Theos builds against. Resolved at runtime.-@interface UIGlassEffect : UIVisualEffect-+ (instancetype)effectWithStyle:(NSInteger)style;-@property (nonatomic, copy) UIColor *tintColor;-@property (nonatomic, getter=isInteractive) BOOL interactive;-@end--@interface NSObject (SGiOS26)-+ (id)capsuleConfiguration;-+ (id)configurationWithUniformRadius:(id)radius;-+ (id)fixedRadius:(CGFloat)radius;-- (void)setCornerConfiguration:(id)configuration;-@end--@interface UIView (SGPrivate)-- (NSString *)recursiveDescription;-@end--@interface UIViewController (SGPrivate)-- (NSString *)_printHierarchy;-@end--// %{public}s so idevicesyslog on the Mac sees the text instead of <private>.-#define SGLog(fmt, ...) os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_DEFAULT, "[spotifyglass] %{public}s", [NSString stringWithFormat:(fmt), ##__VA_ARGS__].UTF8String)-void SGLogLong(NSString *tag, NSString *text);-void SGRequireClasses(NSArray<NSString *> *names);--// View tree-void SGForEachView(UIView *view, void (^fn)(UIView *));-CGRect SGFrameIn(UIView *view, UIView *target);-BOOL SGIsInside(UIView *view, UIView *root);-BOOL SGKeepsColor(UIView *view);-void SGStripBackgrounds(UIView *view);-BOOL SGIsVisibleColor(CGColorRef color);-BOOL SGIsLightColor(CGColorRef color);-BOOL SGIsBaseSurface(CGColorRef color);--BOOL SGHasClass(UIView *root, NSString *marker);-UIStackView *SGRowIn(UIView *host);--// Glass panes-UIVisualEffectView *SGGlassFor(UIView *host, const void *key);-UIVisualEffectView *SGGlassAt(UIView *host, NSUInteger index);-void SGHideGlassFrom(UIView *host, NSUInteger count);-void SGShapeGlass(UIView *glass, CGFloat radius, BOOL capsule);--// Areas kept transparent by ui/Repaint.x, set by the tweaks that own them.-extern __weak UIView *sg_nowPlayingRoot;-extern __weak UIView *sg_tabBarRoot;-extern __weak UIView *sg_nowPlayingCard;-extern __weak UIView *sg_lyricsCardRoot;-extern __weak UIView *sg_lyricsPageRoot;-extern __weak UIView *sg_homeRoot; // ui/HomeGradient.x, the base surface only-extern __weak UIView *sg_npvBackdropRoot; // ui/NowPlayingView.x, the plane behind the player-BOOL SGLooksLikeCard(UIView *view, CGColorRef color);--// The full screen player morphs the now playing bar's own card into the cover art, so for the-// length of that animation ui/NowPlayingBar.x hands the bar back to Spotify: the flag lets the-// album colour through ui/Repaint.x again, and the last colour it took off is kept to restore.-extern BOOL sg_nowPlayingStock;-extern CGColorRef sg_nowPlayingCardColor;-void SGRememberCardColor(CGColorRef color);--// Switches from ui/Settings.x, one per tweak; an unset switch is on.-extern NSString *const SGKeyNowPlayingBar;-extern NSString *const SGKeyTabBar;-extern NSString *const SGKeyPlayer;-extern NSString *const SGKeyPlayerBackdrop; // off unless it is asked for-extern NSString *const SGKeyLyricsCard;-extern NSString *const SGKeySearchField;-extern NSString *const SGKeySpotifyGlass;-extern NSString *const SGKeyAmoled;-extern NSString *const SGKeyHomeGradient; // off unless it is asked for-extern NSString *const SGKeyBlockTelemetry;-BOOL SGFlag(NSString *key, BOOL fallback);-BOOL SGEnabled(NSString *key);-void SGSetEnabled(NSString *key, BOOL on);--// The tab bar's own composition, from ui/Navbar.x and the Navbar settings page: an ordered list-// of entries, each a dictionary. An entry with a URI is a tab of the mod's own; one without names-// one of Spotify's, by the label under its icon. No list at all is Spotify's order, all shown.-extern NSString *const SGKeyNavbar;-extern NSString *const SGNavbarID; // NSString, the entry's identity-extern NSString *const SGNavbarTitle; // NSString, the name in the settings list and under the icon-extern NSString *const SGNavbarURI; // NSString, the mod's own tabs only: what a tap opens-extern NSString *const SGNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts"-extern NSString *const SGNavbarHidden; // NSNumber-NSArray<NSDictionary *> *SGNavbarLayout(void);-void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);-// Spotify's own tabs in Spotify's order, as ui/Navbar.x last saw them on the bar.-NSArray<NSString *> *SGNavbarStock(void);-void SGSetNavbarStock(NSArray<NSString *> *stock);--// ui/Navbar.x, called from the tab bar's layout passes in ui/TabBar.x.-void SGComposeTabBar(UIView *tabBar);-void SGLogTabBarRow(UIView *tabBar);-// Lays the bar out again after the Navbar page changes something, so it does not wait for a touch.-void SGRefreshTabBar(void);--// Spotify's remote-config flags, generated into SGFlagList.m by scripts/extract-flags.py.-typedef NS_ENUM(NSInteger, SGFlagType) { SGFlagUnknown, SGFlagBool, SGFlagInt, SGFlagEnum };-typedef struct { const char *key; SGFlagType type; long value, lower, upper; } SGFlagDef;-extern const SGFlagDef SGFlagTable[];-extern const NSUInteger SGFlagCount;--// Overrides from the Flags page, stored under SGFlagOverridePrefix + key; nil keeps Spotify's value.-extern NSString *const SGFlagOverridePrefix;-id SGFlagOverride(NSString *key);-void SGSetFlagOverride(NSString *key, id value);--// Spotify ships its newer design behind several flags at once, so the Spotify's own Liquid Glass-// switch owns them all: ui/Flags.x forces each one while it is on and ui/Settings.x locks their-// rows, which is what keeps the switch and the rows from contradicting each other.-BOOL SGGlassOwnsFlag(NSString *key);--// Declutter switches from ui/Settings.x, read by ui/Declutter.x; an unset switch is off.-#define SGHideShuffle @"spotifyglass.hide.shuffle"-#define SGHideRepeat @"spotifyglass.hide.repeat"-#define SGHideConnect @"spotifyglass.hide.connect"-#define SGHideShare @"spotifyglass.hide.share"-#define SGHideQueue @"spotifyglass.hide.queue"-#define SGHideAddTo @"spotifyglass.hide.addTo"-#define SGHideLyricsInline @"spotifyglass.hide.lyricsInline"-#define SGHideLyricsCard @"spotifyglass.hide.lyricsCard"-#define SGHideAboutArtist @"spotifyglass.hide.aboutArtist"-#define SGHideRelatedVideos @"spotifyglass.hide.relatedVideos"-#define SGHideSongDNA @"spotifyglass.hide.songDNA"-#define SGHideLiveEvents @"spotifyglass.hide.liveEvents"-#define SGHideExploreArtist @"spotifyglass.hide.exploreArtist"-#define SGHideCredits @"spotifyglass.hide.credits"-#define SGHideMerch @"spotifyglass.hide.merch"-#define SGHideRecommendations @"spotifyglass.hide.recommendations"-#define SGHideHomeShortcuts @"spotifyglass.hide.homeShortcuts"-#define SGHideHomePills @"spotifyglass.hide.homePills"-#define SGHideHomePromo @"spotifyglass.hide.homePromo"-#define SGHideHomePreviews @"spotifyglass.hide.homePreviews"-#define SGHideHomeDJ @"spotifyglass.hide.homeDJ"-BOOL SGHidden(NSString *key);--// Playlist switches from ui/Settings.x, read by ui/Playlist.x; an unset switch is off.-#define SGHidePlaylistArtwork @"spotifyglass.hide.playlistArtwork"-#define SGHidePlaylistDescription @"spotifyglass.hide.playlistDescription"-#define SGHidePlaylistCreator @"spotifyglass.hide.playlistCreator"-#define SGHidePlaylistLength @"spotifyglass.hide.playlistLength"-#define SGHidePlaylistVideo @"spotifyglass.hide.playlistVideo"-#define SGHidePlaylistAddTo @"spotifyglass.hide.playlistAddTo"-#define SGHidePlaylistDownload @"spotifyglass.hide.playlistDownload"-#define SGHidePlaylistShare @"spotifyglass.hide.playlistShare"-#define SGHidePlaylistMore @"spotifyglass.hide.playlistMore"-#define SGHidePlaylistPills @"spotifyglass.hide.playlistPills"-#define SGHidePlaylistFind @"spotifyglass.hide.playlistFind"--// Telemetry blocking (SGPrivacy.x): the destinations it knows in the order it lists them, how many-// requests to one of them it has answered instead of letting out (nil label for all of them).-NSArray<NSString *> *SGBlockedLabels(void);-NSUInteger SGBlockedCount(NSString *label);-void SGResetBlocked(void);--// The site (SGUpdate.m): where the build points its user, and whether a newer one is out. The-// status is a string for the Updates row; the page's ticker reads it, so the check needs no-// callback. SGCheckForUpdate(NO) respects a six hour cache, SGCheckForUpdate(YES) always asks.-extern NSString *const SGSiteURL;-extern NSString *const SGRepoURL;-extern NSString *const SGUpdateURL;-NSString *SGUpdateVersion(void); // nil unless the site has one newer than this build-NSString *SGUpdateNotes(void);-NSString *SGUpdateStatus(void);-void SGCheckForUpdate(BOOL force);-void SGOpenURL(NSString *url);--// Diagnostics (SGDiagnostics.x)-BOOL SGIsDebugBuild(void);-NSString *SGScreenTree(void);-void SGDumpScreen(NSString *reason);diff --git a/tweak/src/SGCommon.m b/tweak/src/SGCommon.mdeleted file mode 100644index 0f785cd5..00000000--- a/tweak/src/SGCommon.m+++ /dev/null@@ -1,301 +0,0 @@-#import "SGCommon.h"--__weak UIView *sg_nowPlayingRoot = nil;-__weak UIView *sg_tabBarRoot = nil;-__weak UIView *sg_nowPlayingCard = nil;-__weak UIView *sg_lyricsCardRoot = nil;-__weak UIView *sg_lyricsPageRoot = nil;-__weak UIView *sg_homeRoot = nil;-__weak UIView *sg_npvBackdropRoot = nil;--BOOL sg_nowPlayingStock = NO;-CGColorRef sg_nowPlayingCardColor = NULL;--// ui/Repaint.x takes the album colour off the card on every repaint; the expand animation of the-// full screen player needs it back, so the last one is kept. Only the main thread writes it, so-// the read in ui/NowPlayingBar.x cannot see a released colour.-void SGRememberCardColor(CGColorRef color) {- if (!NSThread.isMainThread || color == sg_nowPlayingCardColor) return;- CGColorRef kept = color ? CGColorRetain(color) : NULL;- CGColorRelease(sg_nowPlayingCardColor);- sg_nowPlayingCardColor = kept;-}--#pragma mark - logging--// The unified log cuts a message at about 1 KB, so long dumps go out as numbered parts.-void SGLogLong(NSString *tag, NSString *text) {- NSMutableArray<NSString *> *parts = [NSMutableArray array];- NSMutableString *current = [NSMutableString string];- for (NSString *line in [text componentsSeparatedByString:@"\n"]) {- if (current.length && [current lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + [line lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > 900) {- [parts addObject:[current copy]];- [current setString:@""];- }- [current appendFormat:@"%@\n", line];- }- if (current.length) [parts addObject:current];- [parts enumerateObjectsUsingBlock:^(NSString *part, NSUInteger i, BOOL *stop) {- SGLog(@"%@ %lu/%lu\n%@", tag, (unsigned long)i + 1, (unsigned long)parts.count, part);- }];-}--void SGRequireClasses(NSArray<NSString *> *names) {- for (NSString *name in names) {- if (!NSClassFromString(name)) SGLog(@"class %@ not found, its hooks are inactive", name);- }-}--#pragma mark - switches--NSString *const SGKeyNowPlayingBar = @"spotifyglass.nowPlayingBar";-NSString *const SGKeyTabBar = @"spotifyglass.tabBar";-NSString *const SGKeyPlayer = @"spotifyglass.player";-NSString *const SGKeyPlayerBackdrop = @"spotifyglass.playerBackdrop";-NSString *const SGKeyLyricsCard = @"spotifyglass.lyricsCard";-NSString *const SGKeySearchField = @"spotifyglass.searchField";-NSString *const SGKeySpotifyGlass = @"spotifyglass.spotifyGlass";-NSString *const SGKeyAmoled = @"spotifyglass.amoled";-NSString *const SGKeyHomeGradient = @"spotifyglass.homeGradient";-NSString *const SGKeyBlockTelemetry = @"spotifyglass.blockTelemetry";--BOOL SGFlag(NSString *key, BOOL fallback) {- id value = [NSUserDefaults.standardUserDefaults objectForKey:key];- return value ? [value boolValue] : fallback;-}--BOOL SGEnabled(NSString *key) {- return SGFlag(key, YES);-}--BOOL SGHidden(NSString *key) {- return SGFlag(key, NO);-}--void SGSetEnabled(NSString *key, BOOL on) {- [NSUserDefaults.standardUserDefaults setBool:on forKey:key];-}--NSString *const SGKeyNavbar = @"spotifyglass.navbar";-NSString *const SGNavbarID = @"id";-NSString *const SGNavbarTitle = @"title";-NSString *const SGNavbarURI = @"uri";-NSString *const SGNavbarIcon = @"icon";-NSString *const SGNavbarHidden = @"hidden";--static NSString *const kNavbarLayout = @"spotifyglass.navbar.layout";-static NSString *const kNavbarStock = @"spotifyglass.navbar.stock";--// Only property list types go in, so a corrupt read cannot be anything but an array of dictionaries.-static NSArray *listOfKind(NSString *key, Class kind) {- NSArray *list = [NSUserDefaults.standardUserDefaults arrayForKey:key];- for (id item in list) if (![item isKindOfClass:kind]) return @[];- return list ?: @[];-}--NSArray<NSDictionary *> *SGNavbarLayout(void) {- return listOfKind(kNavbarLayout, NSDictionary.class);-}--void SGSetNavbarLayout(NSArray<NSDictionary *> *layout) {- [NSUserDefaults.standardUserDefaults setObject:layout ?: @[] forKey:kNavbarLayout];-}--NSArray<NSString *> *SGNavbarStock(void) {- return listOfKind(kNavbarStock, NSString.class);-}--void SGSetNavbarStock(NSArray<NSString *> *stock) {- [NSUserDefaults.standardUserDefaults setObject:stock ?: @[] forKey:kNavbarStock];-}--NSString *const SGFlagOverridePrefix = @"spotifyglass.flag.";--id SGFlagOverride(NSString *key) {- return [NSUserDefaults.standardUserDefaults objectForKey:[SGFlagOverridePrefix stringByAppendingString:key]];-}--void SGSetFlagOverride(NSString *key, id value) {- key = [SGFlagOverridePrefix stringByAppendingString:key];- if (value) [NSUserDefaults.standardUserDefaults setObject:value forKey:key];- else [NSUserDefaults.standardUserDefaults removeObjectForKey:key];-}--BOOL SGGlassOwnsFlag(NSString *key) {- static NSSet<NSString *> *owned;- static dispatch_once_t once;- dispatch_once(&once, ^{- owned = [NSSet setWithArray:@[- @"ios-reprise-liquid-glass-properties.context_menu_in_navigation_bar_enabled",- @"ios-feature-encoreexperiments.new_npv_slider_enabled",- @"ios-feature-nowplaying.sheet_style_npv",- @"ios-feature-nowplaying.bottom_sheet_queue_enabled",- @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled",- @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet",- @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet",- @"ios-feature-sleeptimer.use_options_sheet",- ]];- });- return [owned containsObject:key];-}--#pragma mark - view tree--void SGForEachView(UIView *view, void (^fn)(UIView *)) {- fn(view);- for (UIView *sub in view.subviews) SGForEachView(sub, fn);-}--CGRect SGFrameIn(UIView *view, UIView *target) {- return [view.superview convertRect:view.frame toView:target];-}--BOOL SGIsInside(UIView *view, UIView *root) {- if (!root) return NO;- for (UIView *v = view; v; v = v.superview) {- if ([v isKindOfClass:UIVisualEffectView.class]) return NO;- if (v == root) return YES;- }- return NO;-}--// Artwork, glyphs, text and thin lines (progress bar) keep their colour, everything else goes clear.-BOOL SGKeepsColor(UIView *view) {- return [view isKindOfClass:UIImageView.class] || [view isKindOfClass:UILabel.class] || view.bounds.size.height <= 4;-}--void SGStripBackgrounds(UIView *view) {- if ([view isKindOfClass:UIVisualEffectView.class]) return;- if (!SGKeepsColor(view)) view.layer.backgroundColor = NULL;- if ([view.layer isKindOfClass:CAGradientLayer.class] || [NSStringFromClass(view.class) containsString:@"GradientView"]) view.hidden = YES;- for (CALayer *layer in view.layer.sublayers) {- if ([layer isKindOfClass:CAGradientLayer.class]) layer.hidden = YES;- }- for (UIView *sub in view.subviews) SGStripBackgrounds(sub);-}--BOOL SGIsVisibleColor(CGColorRef color) {- if (!color || CGColorGetAlpha(color) < 0.05) return NO;- const CGFloat *c = CGColorGetComponents(color);- size_t n = CGColorGetNumberOfComponents(color);- CGFloat brightest = 0;- for (size_t i = 0; i + 1 < n; i++) brightest = MAX(brightest, c[i]);- return brightest > 0.08;-}--BOOL SGIsLightColor(CGColorRef color) {- if (!color || CGColorGetAlpha(color) < 0.5) return NO;- const CGFloat *c = CGColorGetComponents(color);- size_t n = CGColorGetNumberOfComponents(color);- for (size_t i = 0; i + 1 < n; i++) if (c[i] < 0.85) return NO;- return YES;-}--// Spotify's base surface: the neutral #121212 it paints its pages with, or the black ui/Amoled.x-// turns that into. Lighter greys (#1F1F1F placeholders, #292929 cards) and translucent paint stay.-BOOL SGIsBaseSurface(CGColorRef color) {- if (!color || CFGetTypeID(color) != CGColorGetTypeID() || CGColorGetAlpha(color) < 0.95) return NO;- const CGFloat *c = CGColorGetComponents(color);- size_t n = CGColorGetNumberOfComponents(color);- if (n == 2) return c[0] <= 0.10;- if (n < 3) return NO;- return c[0] <= 0.10 && fabs(c[0] - c[1]) < 0.02 && fabs(c[1] - c[2]) < 0.02;-}--BOOL SGHasClass(UIView *root, NSString *marker) {- __block BOOL found = NO;- SGForEachView(root, ^(UIView *v) {- if (!found && [NSStringFromClass(v.class) containsString:marker]) found = YES;- });- return found;-}--// The first wide stack view under `host` with at least two arranged children: a player row, or-// the row of items in the tab bar.-UIStackView *SGRowIn(UIView *host) {- __block UIStackView *row = nil;- SGForEachView(host, ^(UIView *v) {- if (!row && [v isKindOfClass:UIStackView.class] && v.bounds.size.width > 200 && ((UIStackView *)v).arrangedSubviews.count >= 2) row = (UIStackView *)v;- });- return row;-}--BOOL SGLooksLikeCard(UIView *view, CGColorRef color) {- CGSize size = view.bounds.size;- return size.height >= 40 && size.height <= 140 && size.width >= 200 && SGIsVisibleColor(color);-}--#pragma mark - glass--// +effectWithStyle: is the only initialiser UIGlassEffect has; a bare -init leaves the material-// unresolved and the pane renders as a plain blur, while the capsule shape, which is the view's-// own property, still comes out right. Spotify's own Reprise glass builds its effect the same way.-static UIVisualEffect *glassEffect(void) {- Class glass = NSClassFromString(@"UIGlassEffect");- if ([glass respondsToSelector:@selector(effectWithStyle:)]) return [glass effectWithStyle:0];- return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterialDark];-}--static UIVisualEffectView *newPane(void) {- UIVisualEffectView *glass = [[UIVisualEffectView alloc] initWithEffect:glassEffect()];- glass.userInteractionEnabled = NO;- // A pane goes in at index 0, but a host that rebuilds its content puts that in at index 0 too- // and the pane would end up over it. Depth keeps a pane behind whatever the host draws.- glass.layer.zPosition = -1;- return glass;-}--// One pane per host and key, kept behind the host's own content.-UIVisualEffectView *SGGlassFor(UIView *host, const void *key) {- UIVisualEffectView *glass = objc_getAssociatedObject(host, key);- if (!glass) {- glass = newPane();- objc_setAssociatedObject(host, key, glass, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- }- if (glass.superview != host) [host insertSubview:glass atIndex:0];- return glass;-}--// Several panes on one host, addressed by index.-static char kPanesKey;--UIVisualEffectView *SGGlassAt(UIView *host, NSUInteger index) {- NSMutableArray<UIVisualEffectView *> *panes = objc_getAssociatedObject(host, &kPanesKey);- if (!panes) {- panes = [NSMutableArray array];- objc_setAssociatedObject(host, &kPanesKey, panes, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- }- while (panes.count <= index) [panes addObject:newPane()];- UIVisualEffectView *glass = panes[index];- glass.hidden = NO;- if (glass.superview != host) [host insertSubview:glass atIndex:0];- return glass;-}--// Panes past `count` belonged to children that are gone now.-void SGHideGlassFrom(UIView *host, NSUInteger count) {- NSArray<UIVisualEffectView *> *panes = objc_getAssociatedObject(host, &kPanesKey);- for (NSUInteger i = count; i < panes.count; i++) panes[i].hidden = YES;-}--// Glass takes its shape from cornerConfiguration on iOS 26; layer.cornerRadius is the fallback.-void SGShapeGlass(UIView *glass, CGFloat radius, BOOL capsule) {- Class config = NSClassFromString(@"UICornerConfiguration");- Class cornerRadius = NSClassFromString(@"UICornerRadius");- id shape = nil;- if (config && [glass respondsToSelector:@selector(setCornerConfiguration:)]) {- if (capsule && [config respondsToSelector:@selector(capsuleConfiguration)]) {- shape = [config capsuleConfiguration];- } else if ([config respondsToSelector:@selector(configurationWithUniformRadius:)] && [cornerRadius respondsToSelector:@selector(fixedRadius:)]) {- shape = [config configurationWithUniformRadius:[cornerRadius fixedRadius:radius]];- }- }- if (shape) {- [glass setCornerConfiguration:shape];- glass.clipsToBounds = NO;- } else {- glass.layer.cornerRadius = capsule ? glass.bounds.size.height / 2 : radius;- glass.layer.cornerCurve = kCACornerCurveContinuous;- glass.clipsToBounds = YES;- }-}diff --git a/tweak/src/ui/Settings.x b/tweak/src/ui/Settings.xdeleted file mode 100644index 7ec5bb24..00000000--- a/tweak/src/ui/Settings.x+++ /dev/null@@ -1,1397 +0,0 @@-// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own pages:-// UI Tweaks, Home, Playlist and Now Playing, each sections of switches (the mod's own and a few of-// Spotify's remote-config flags), Navbar, the tab bar's own composition, and All flags, a-// searchable list of every flag with an override per flag. The tweaks read the switches when they-// run, so a change shows after Spotify restarts; the Navbar page is the exception and applies as-// soon as the bar lays out again.-//-// Tree (trees/settings.txt): SettingsListViewController.view > SettingsListCollectionView of-// Element_List cells 402x56: 24pt icon at x 12, 13pt white title and 11pt grey subtitle at-// x 48, 12pt chevron on the right. A pushed page (trees/settings notifications opened.txt) is a-// UITableView bg #121212: header with an 11pt grey description at (16, 24), 53pt cells with the-// title and subtitle at (16, 10) and a 16pt disclosure chevron at x 370.-#import "SGCommon.h"--static const CGFloat kRowHeight = 56;-static char kRowKey, kInsetKey;-static UIFont *sg_titleFont, *sg_subtitleFont;--static UIColor *grey(void) { return [UIColor colorWithWhite:0xB3 / 255.0 alpha:1]; }-static UIFont *titleFont(void) { return sg_titleFont ?: [UIFont systemFontOfSize:13 weight:UIFontWeightBold]; }-static UIFont *subtitleFont(void) { return sg_subtitleFont ?: [UIFont systemFontOfSize:11]; }--static UIImageView *symbol(NSString *name, CGFloat size, UIImageSymbolWeight weight, CGFloat box) {- UIImage *image = [UIImage systemImageNamed:name withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:size weight:weight]];- UIImageView *view = [[UIImageView alloc] initWithImage:image];- view.tintColor = UIColor.whiteColor;- view.contentMode = UIViewContentModeCenter;- view.frame = CGRectMake(0, 0, box, box);- return view;-}--// A grey note in a wrapper view, for the table header and footer.-static UIView *note(NSString *text) {- UILabel *label = [UILabel new];- label.text = text;- label.font = subtitleFont();- label.textColor = grey();- label.numberOfLines = 0;- UIView *wrapper = [UIView new];- [wrapper addSubview:label];- return wrapper;-}--// Header and footer views keep the height they are given, so size them to their text. Only the-// size is compared: the table moves the footer's origin itself, and reassigning on that would-// loop forever.-static void fitNote(UITableView *table, UIView *wrapper, CGFloat top, CGFloat bottom) {- UILabel *label = wrapper.subviews.firstObject;- CGFloat width = table.bounds.size.width - 32;- CGFloat height = ceil([label sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height);- label.frame = CGRectMake(16, top, width, height);- CGSize size = CGSizeMake(table.bounds.size.width, top + height + bottom);- if (CGSizeEqualToSize(wrapper.bounds.size, size)) return;- wrapper.frame = (CGRect){wrapper.frame.origin, size};- if (wrapper == table.tableHeaderView) table.tableHeaderView = wrapper;- else table.tableFooterView = wrapper;-}--static CGFloat barsHeight(UIView *view) {- UIWindow *window = view.window;- __block CGFloat top = window.bounds.size.height;- SGForEachView(window, ^(UIView *v) {- NSString *name = NSStringFromClass(v.class);- BOOL bar = [name containsString:@"NowPlaying_BarPageImpl"] || [name isEqualToString:@"_TtC23NavigationUI_TabBarImpl10TabBarView"];- if (!bar || v.hidden || v.alpha == 0 || v.bounds.size.height == 0) return;- top = MIN(top, SGFrameIn(v, window).origin.y);- });- return window.bounds.size.height - top;-}--// The now playing bar and the tab bar float over the content, and the safe area does not cover-// them, so the pages inset themselves by however much of the window the bars take.-static void insetForBars(UITableView *table) {- CGFloat bottom = MAX(0, barsHeight(table) - table.safeAreaInsets.bottom);- if (table.contentInset.bottom == bottom) return;- UIEdgeInsets inset = table.contentInset;- inset.bottom = bottom;- table.contentInset = inset;- table.verticalScrollIndicatorInsets = inset;-}--static UIColor *green(void) { return [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }-static UIColor *pageBackground(void) { return [UIColor colorWithWhite:0x12 / 255.0 alpha:1]; }--#pragma mark - pages--// Spotify's navigation controller asserts that everything on its stack is one of its own pages-// (SPNavigationController.m:645, "[viewController conformsToProtocol:@protocol(SPTPageController)]"),-// and the tab bar asks it for that page on every tab tap to log the interaction. A plain view-// controller of the mod's pushed onto that stack therefore takes the app down the next time a tab-// is pressed, from wherever it was left. The pages below answer the protocol's two questions-// instead and are registered as conforming at load; if the protocol is gone they are presented-// rather than pushed, so a rename in some later Spotify costs the push, not the app.-static BOOL sg_pagesConform;--@interface SGPage : UITableViewController-@end--@implementation SGPage--- (NSString *)spt_pageIdentifier {- return @"spotifyglass";-}--- (NSURL *)spt_pageURI {- return [NSURL URLWithString:@"spotify:internal:spotifyglass"];-}--@end--// A row is a switch when it has a key and a link to another page when it has a page. A flag row-// switches one of Spotify's remote-config flags: on forces it (off for a forceOff row, which is how-// a flag Spotify ships on is turned off), the switch off leaves Spotify's own value. A row-// with a value reads one out on the right and is asked again while the page is open; a row with an-// action runs it when tapped.-@interface SGModRow : NSObject-@property (nonatomic, copy) NSString *title;-@property (nonatomic, copy) NSString *subtitle;-@property (nonatomic, copy) NSString *key;-@property (nonatomic) BOOL defaultOn;-@property (nonatomic) BOOL flag;-@property (nonatomic) BOOL forceOff;-@property (nonatomic, copy) UIViewController *(^page)(void);-@property (nonatomic, copy) NSString *(^value)(void);-@property (nonatomic, copy) void (^action)(void);-@property (nonatomic, copy) NSString *warning;-@end--@implementation SGModRow-@end--@interface SGModSection : NSObject-@property (nonatomic, copy) NSString *title;-@property (nonatomic, copy) NSArray<SGModRow *> *rows;-@end--@implementation SGModSection-@end--static SGModRow *switchRow(NSString *title, NSString *subtitle, NSString *key) {- SGModRow *row = [SGModRow new];- row.title = title;- row.subtitle = subtitle;- row.key = key;- row.defaultOn = YES;- return row;-}--static SGModRow *hideRow(NSString *title, NSString *subtitle, NSString *key) {- SGModRow *row = switchRow(title, subtitle, key);- row.defaultOn = NO;- return row;-}--// A switch for something the mod adds rather than takes away: off until it is asked for.-static SGModRow *optionRow(NSString *title, NSString *subtitle, NSString *key) {- SGModRow *row = switchRow(title, subtitle, key);- row.defaultOn = NO;- return row;-}--// A switch whose work is not finished: turning it on says so first, and offers the repo to anyone-// who would rather fix it than live with it.-static SGModRow *unstableRow(NSString *title, NSString *subtitle, NSString *key, NSString *warning) {- SGModRow *row = switchRow(title, subtitle, key);- row.warning = warning;- return row;-}--static SGModRow *flagRow(NSString *title, NSString *key) {- SGModRow *row = hideRow(title, [key substringFromIndex:[key rangeOfString:@"."].location + 1], key);- row.flag = YES;- return row;-}--// A flag Spotify ships on: the switch forces it off.-static SGModRow *killRow(NSString *title, NSString *key) {- SGModRow *row = flagRow(title, key);- row.forceOff = YES;- return row;-}--static SGModRow *statRow(NSString *title, NSString *(^value)(void)) {- SGModRow *row = [SGModRow new];- row.title = title;- row.value = value;- return row;-}--static SGModRow *actionRow(NSString *title, NSString *subtitle, void (^action)(void)) {- SGModRow *row = [SGModRow new];- row.title = title;- row.subtitle = subtitle;- row.action = action;- return row;-}--// No subtitle: a list of pages reads as a list, not as a wall of explanations.-static SGModRow *pageRow(NSString *title, UIViewController *(^page)(void)) {- SGModRow *row = [SGModRow new];- row.title = title;- row.page = page;- return row;-}--static SGModRow *linkRow(NSString *title, NSString *subtitle, NSString *url) {- return actionRow(title, subtitle, ^{ SGOpenURL(url); });-}--// A value on the right and a tap: the Updates row reads its status out of SGUpdate.m every tick,-// and a tap asks the site again instead of waiting for the six hour cache to lapse.-static SGModRow *statActionRow(NSString *title, NSString *subtitle, NSString *(^value)(void), void (^action)(void)) {- SGModRow *row = [SGModRow new];- row.title = title;- row.subtitle = subtitle;- row.value = value;- row.action = action;- return row;-}--static SGModSection *section(NSString *title, NSArray<SGModRow *> *rows) {- SGModSection *s = [SGModSection new];- s.title = title;- s.rows = rows;- return s;-}--// On means the row's own override is in place; anything else, including the opposite override-// somebody set from the All flags page, reads as off.-static BOOL flagRowOn(SGModRow *row) {- id value = SGFlagOverride(row.key);- return value && [value boolValue] != row.forceOff;-}--// A flag the Spotify's own Liquid Glass switch owns: its row shows what that switch forces and-// takes no touch, so the flag has one place to change. An override from All flags still wins.-static BOOL flagRowLocked(SGModRow *row) {- return row.flag && SGGlassOwnsFlag(row.key) && SGEnabled(SGKeySpotifyGlass);-}--static const CGFloat kSectionHeaderHeight = 38;--// Every page below draws Spotify's own list row: a 13pt white title over an 11pt grey subtitle,-// with an optional symbol in the leading slot.-static void fillCell(UITableViewCell *cell, NSString *title, NSString *subtitle, UIColor *color, NSString *symbolName) {- UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];- content.text = title;- content.secondaryText = subtitle;- content.textProperties.font = titleFont();- content.textProperties.color = color ?: UIColor.whiteColor;- content.secondaryTextProperties.font = subtitleFont();- content.secondaryTextProperties.color = grey();- content.textToSecondaryTextVerticalPadding = 0;- content.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(10, 16, 10, 16);- if (symbolName) {- content.image = [UIImage systemImageNamed:symbolName withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:15 weight:UIImageSymbolWeightRegular]];- content.imageProperties.tintColor = color ?: UIColor.whiteColor;- content.imageToTextPadding = 14;- }- cell.contentConfiguration = content;- cell.backgroundColor = UIColor.clearColor;- cell.accessoryView = nil;- cell.selectionStyle = UITableViewCellSelectionStyleNone;-}--static UIView *sectionHeader(UITableView *table, NSString *title) {- UILabel *label = [UILabel new];- label.text = title.uppercaseString;- label.font = subtitleFont();- label.textColor = grey();- label.frame = CGRectMake(16, 20, table.bounds.size.width - 32, 14);- label.autoresizingMask = UIViewAutoresizingFlexibleWidth;- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, kSectionHeaderHeight)];- [header addSubview:label];- return header;-}--static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {- return [table dequeueReusableCellWithIdentifier:identifier]- ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];-}--@interface SGModPage : SGPage-- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer;-@end--@implementation SGModPage {- NSArray<SGModSection *> *_sections;- UIView *_intro;- UIView *_footer;- NSTimer *_ticker;- BOOL _live;-}--- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer {- if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;- self.title = title;- _sections = sections;- _intro = intro ? note(intro) : nil;- _footer = footer ? note(footer) : nil;- for (SGModSection *s in sections) for (SGModRow *row in s.rows) _live |= row.value != nil;- return self;-}--- (void)viewDidLoad {- [super viewDidLoad];- self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- self.tableView.backgroundColor = pageBackground();- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;- self.tableView.sectionHeaderTopPadding = 0;- self.tableView.tableHeaderView = _intro;- self.tableView.tableFooterView = _footer;-}--- (void)viewWillLayoutSubviews {- [super viewWillLayoutSubviews];- if (_intro) fitNote(self.tableView, _intro, 24, 0);- if (_footer) fitNote(self.tableView, _footer, 16, 24);-}--- (void)viewDidLayoutSubviews {- [super viewDidLayoutSubviews];- insetForBars(self.tableView);-}--- (void)viewWillAppear:(BOOL)animated {- [super viewWillAppear:animated];- if (!_live) return;- [self.tableView reloadData];- // The counters climb while the page is open; the labels are written straight into the cells so- // that a reload never lands under a switch being dragged.- _ticker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(readValues) userInfo:nil repeats:YES];-}--- (void)viewDidDisappear:(BOOL)animated {- [super viewDidDisappear:animated];- [_ticker invalidate];- _ticker = nil;-}--- (void)readValues {- for (UITableViewCell *cell in self.tableView.visibleCells) {- SGModRow *row = [self rowAt:[self.tableView indexPathForCell:cell]];- UILabel *label = (UILabel *)cell.accessoryView;- if (!row.value || ![label isKindOfClass:UILabel.class]) continue;- label.text = row.value();- [label sizeToFit];- [cell setNeedsLayout];- }-}--- (SGModRow *)rowAt:(NSIndexPath *)path {- return _sections[(NSUInteger)path.section].rows[(NSUInteger)path.row];-}--- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {- return (NSInteger)_sections.count;-}--- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return (NSInteger)_sections[(NSUInteger)section].rows.count;-}--- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {- NSString *title = _sections[(NSUInteger)section].title;- return title ? sectionHeader(table, title) : nil;-}--- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return _sections[(NSUInteger)section].title ? kSectionHeaderHeight : CGFLOAT_MIN;-}--- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {- return CGFLOAT_MIN;-}--- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {- UITableViewCell *cell = dequeue(table, @"row");- SGModRow *row = [self rowAt:path];- fillCell(cell, row.title, row.subtitle, nil, nil);-- if (row.key) {- UISwitch *toggle = [UISwitch new];- toggle.onTintColor = green();- BOOL locked = flagRowLocked(row);- toggle.on = row.flag ? (locked && !SGFlagOverride(row.key) ? YES : flagRowOn(row)) : SGFlag(row.key, row.defaultOn);- toggle.enabled = !locked;- toggle.tag = path.section * 1000 + path.row;- [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];- cell.accessoryView = toggle;- } else if (row.page) {- cell.accessoryView = symbol(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- } else if (row.value) {- UILabel *label = [UILabel new];- label.font = titleFont();- label.textColor = grey();- label.text = row.value();- [label sizeToFit];- cell.accessoryView = label;- cell.selectionStyle = row.action ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;- } else if (row.action) {- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- }- return cell;-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- SGModRow *row = [self rowAt:path];- if (row.page) [self.navigationController pushViewController:row.page() animated:YES];- if (!row.action) return;- row.action();- [table deselectRowAtIndexPath:path animated:YES];- [self readValues];-}--- (void)toggled:(UISwitch *)toggle {- SGModRow *row = [self rowAt:[NSIndexPath indexPathForRow:toggle.tag % 1000 inSection:toggle.tag / 1000]];- if (row.flag) SGSetFlagOverride(row.key, toggle.on ? @(!row.forceOff) : nil);- else SGSetEnabled(row.key, toggle.on);- if (toggle.on && row.warning) [self warn:row];-}--- (void)warn:(SGModRow *)row {- UIAlertController *alert = [UIAlertController alertControllerWithTitle:[row.title stringByAppendingString:@" is unstable"]- message:row.warning- preferredStyle:UIAlertControllerStyleAlert];- [alert addAction:[UIAlertAction actionWithTitle:@"Open GitHub" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {- SGOpenURL(SGRepoURL);- }]];- [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];- [self presentViewController:alert animated:YES completion:nil];-}--@end--#pragma mark - flags page--static NSString *flagState(const SGFlagDef *flag, id value) {- if (value) return [NSString stringWithFormat:@"forced %@", flag->type == SGFlagBool ? ([value boolValue] ? @"on" : @"off") : value];- switch (flag->type) {- case SGFlagBool: return flag->value ? @"on by default" : @"off by default";- case SGFlagInt: return [NSString stringWithFormat:@"%ld by default, %ld to %ld", flag->value, flag->lower, flag->upper];- case SGFlagEnum: return @"text value";- default: return @"type unknown";- }-}--// Every flag in SGFlagTable, filtered by the search words; forced flags first while the search-// is empty. Bool flags get an Auto / Off / On control, the others a text field in an alert.-@interface SGFlagsPage : SGPage <UISearchBarDelegate>-@end--@implementation SGFlagsPage {- NSArray<NSNumber *> *_shown;- NSDictionary<NSString *, id> *_overrides;- UISearchBar *_search;- UIView *_header;-}--- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStylePlain])) return nil;- self.title = @"Flags";- return self;-}--- (void)viewDidLoad {- [super viewDidLoad];- self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- self.tableView.backgroundColor = pageBackground();- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;- self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;- _search = [UISearchBar new];- _search.placeholder = [NSString stringWithFormat:@"Search %lu flags", (unsigned long)SGFlagCount];- _search.searchBarStyle = UISearchBarStyleMinimal;- _search.delegate = self;- _header = note(@"Spotify's remote config, read once at startup. Auto keeps the value Spotify sends; a change applies after you restart Spotify.");- [_header addSubview:_search];- self.tableView.tableHeaderView = _header;- [self reload];-}--- (void)viewWillLayoutSubviews {- [super viewWillLayoutSubviews];- _search.frame = CGRectMake(8, 4, self.tableView.bounds.size.width - 16, 44);- fitNote(self.tableView, _header, 52, 8);-}--- (void)viewDidLayoutSubviews {- [super viewDidLayoutSubviews];- insetForBars(self.tableView);-}--- (void)reload {- NSMutableDictionary *overrides = [NSMutableDictionary dictionary];- NSDictionary *defaults = NSUserDefaults.standardUserDefaults.dictionaryRepresentation;- for (NSString *key in defaults) {- if ([key hasPrefix:SGFlagOverridePrefix]) overrides[[key substringFromIndex:SGFlagOverridePrefix.length]] = defaults[key];- }- NSArray<NSString *> *words = [_search.text.lowercaseString componentsSeparatedByString:@" "];- NSMutableArray *forced = [NSMutableArray array], *rest = [NSMutableArray array];- for (NSUInteger i = 0; i < SGFlagCount; i++) {- NSString *key = @(SGFlagTable[i].key);- BOOL match = YES;- for (NSString *word in words) match = match && (!word.length || [key containsString:word]);- if (match) [overrides[key] ? forced : rest addObject:@(i)];- }- _overrides = overrides;- _shown = [forced arrayByAddingObjectsFromArray:rest];- [self.tableView reloadData];-}--- (void)searchBar:(UISearchBar *)bar textDidChange:(NSString *)text {- [self reload];-}--- (void)searchBarSearchButtonClicked:(UISearchBar *)bar {- [bar resignFirstResponder];-}--- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return (NSInteger)_shown.count;-}--- (const SGFlagDef *)flagAt:(NSInteger)row {- return &SGFlagTable[_shown[(NSUInteger)row].unsignedIntegerValue];-}--- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {- UITableViewCell *cell = dequeue(table, @"flag");- const SGFlagDef *flag = [self flagAt:path.row];- NSString *key = @(flag->key);- NSUInteger dot = [key rangeOfString:@"."].location;- id value = _overrides[key];-- fillCell(cell, [key substringFromIndex:dot + 1],- [NSString stringWithFormat:@"%@ · %@", [key substringToIndex:dot], flagState(flag, value)],- value ? green() : nil, nil);- cell.selectionStyle = UITableViewCellSelectionStyleDefault;-- if (flag->type == SGFlagBool) {- UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"Auto", @"Off", @"On"]];- control.selectedSegmentIndex = value ? ([value boolValue] ? 2 : 1) : 0;- control.selectedSegmentTintColor = green();- [control setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor, NSFontAttributeName: subtitleFont()} forState:UIControlStateNormal];- control.tag = path.row;- [control addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];- [control sizeToFit];- cell.accessoryView = control;- cell.selectionStyle = UITableViewCellSelectionStyleNone;- }- return cell;-}--- (void)segmentChanged:(UISegmentedControl *)control {- NSString *key = @([self flagAt:control.tag]->key);- NSInteger index = control.selectedSegmentIndex;- [self store:index == 0 ? nil : @(index == 2) forKey:key row:control.tag];-}--- (void)store:(id)value forKey:(NSString *)key row:(NSInteger)row {- SGSetFlagOverride(key, value);- NSMutableDictionary *overrides = [_overrides mutableCopy];- overrides[key] = value;- _overrides = overrides;- [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- [table deselectRowAtIndexPath:path animated:YES];- const SGFlagDef *flag = [self flagAt:path.row];- if (flag->type == SGFlagBool) return;- NSString *key = @(flag->key);- id value = _overrides[key];- NSString *hint = flag->type == SGFlagUnknown ? @"true or false, a number, or a text value" : flagState(flag, value);- UIAlertController *alert = [UIAlertController alertControllerWithTitle:[key substringFromIndex:[key rangeOfString:@"."].location + 1] message:hint preferredStyle:UIAlertControllerStyleAlert];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {- field.text = value ? [value description] : @"";- field.keyboardType = flag->type == SGFlagInt ? UIKeyboardTypeNumbersAndPunctuation : UIKeyboardTypeDefault;- }];- [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- [alert addAction:[UIAlertAction actionWithTitle:@"Auto" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *a) {- [self store:nil forKey:key row:path.row];- }]];- [alert addAction:[UIAlertAction actionWithTitle:@"Force" style:UIAlertActionStyleDefault handler:^(UIAlertAction *a) {- NSString *text = alert.textFields.firstObject.text;- if (!text.length) return;- [self store:flag->type == SGFlagInt ? @(text.integerValue) : text forKey:key row:path.row];- }]];- [self presentViewController:alert animated:YES completion:nil];-}--@end--#pragma mark - navbar page--// What "Add a tab" offers: URIs Spotify's own router resolves to a page of its own, each with the-// name of the SPTEncoreIcon class method that draws its glyph.-static NSArray<NSDictionary *> *tabPresets(void) {- return @[- @{SGNavbarTitle: @"Home", SGNavbarURI: @"spotify:home", SGNavbarIcon: @"home"},- @{SGNavbarTitle: @"Search", SGNavbarURI: @"spotify:search", SGNavbarIcon: @"search"},- @{SGNavbarTitle: @"Your Library", SGNavbarURI: @"spotify:collection", SGNavbarIcon: @"collection"},- @{SGNavbarTitle: @"Liked Songs", SGNavbarURI: @"spotify:collection:tracks", SGNavbarIcon: @"heart"},- @{SGNavbarTitle: @"Playlists", SGNavbarURI: @"spotify:collection:playlists", SGNavbarIcon: @"playlist"},- @{SGNavbarTitle: @"Albums", SGNavbarURI: @"spotify:collection:albums", SGNavbarIcon: @"album"},- @{SGNavbarTitle: @"Artists", SGNavbarURI: @"spotify:collection:artists", SGNavbarIcon: @"artist"},- @{SGNavbarTitle: @"Podcasts", SGNavbarURI: @"spotify:collection:podcasts", SGNavbarIcon: @"podcasts"},- @{SGNavbarTitle: @"Audiobooks", SGNavbarURI: @"spotify:collection:audiobooks", SGNavbarIcon: @"audiobook"},- @{SGNavbarTitle: @"Downloads", SGNavbarURI: @"spotify:collection:downloads", SGNavbarIcon: @"downloaded"},- @{SGNavbarTitle: @"Your Episodes", SGNavbarURI: @"spotify:collection:your-episodes", SGNavbarIcon: @"bookmark"},- @{SGNavbarTitle: @"Browse", SGNavbarURI: @"spotify:browse", SGNavbarIcon: @"browse"},- @{SGNavbarTitle: @"New Releases", SGNavbarURI: @"spotify:new-releases", SGNavbarIcon: @"star"},- @{SGNavbarTitle: @"Made For You", SGNavbarURI: @"spotify:made-for-you", SGNavbarIcon: @"user"},- @{SGNavbarTitle: @"Concerts", SGNavbarURI: @"spotify:concerts", SGNavbarIcon: @"events"},- @{SGNavbarTitle: @"Queue", SGNavbarURI: @"spotify:now-playing:queue", SGNavbarIcon: @"queue"},- @{SGNavbarTitle: @"Create", SGNavbarURI: @"spotify:create-menu", SGNavbarIcon: @"plus"},- ];-}--// The list the Navbar page edits: the saved order first, then every tab of Spotify's it does not-// name, in Spotify's order. Entries for tabs Spotify no longer has drop out.-static NSMutableArray<NSMutableDictionary *> *navbarEntries(void) {- NSArray<NSString *> *stock = SGNavbarStock();- NSMutableArray<NSMutableDictionary *> *entries = [NSMutableArray array];- NSMutableSet<NSString *> *seen = [NSMutableSet set];- for (NSDictionary *entry in SGNavbarLayout()) {- NSString *ident = entry[SGNavbarID];- if (![ident isKindOfClass:NSString.class] || [seen containsObject:ident]) continue;- if (!entry[SGNavbarURI] && ![stock containsObject:ident]) continue;- [seen addObject:ident];- [entries addObject:[entry mutableCopy]];- }- for (NSString *ident in stock) {- if ([seen containsObject:ident]) continue;- [entries addObject:[@{SGNavbarID: ident, SGNavbarTitle: ident} mutableCopy]];- }- return entries;-}--// A tab of the mod's own carries an identity of its own, so the same page can sit on the bar twice-// and renaming one does not shuffle the order.-static void appendTab(NSDictionary *tab) {- NSMutableDictionary *entry = [tab mutableCopy];- entry[SGNavbarID] = NSUUID.UUID.UUIDString;- SGSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);- SGRefreshTabBar();-}--@interface SGTabPickerPage : SGPage-@end--@implementation SGTabPickerPage {- UIView *_footer;-}--- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;- self.title = @"Add a Tab";- return self;-}--- (void)viewDidLoad {- [super viewDidLoad];- self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- self.tableView.backgroundColor = pageBackground();- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;- self.tableView.sectionHeaderTopPadding = 0;- _footer = note(@"Anything Spotify can open by link works, so a playlist, an artist or a page of "- "your own goes on the bar the same way. Icons are Spotify's own: home, search, "- "collection, heart, playlist, album, artist, podcasts, audiobook, downloaded, "- "bookmark, browse, star, user, events, queue, plus, radio, gears, spotifyLogo.");- self.tableView.tableFooterView = _footer;-}--- (void)viewWillLayoutSubviews {- [super viewWillLayoutSubviews];- fitNote(self.tableView, _footer, 16, 24);-}--- (void)viewDidLayoutSubviews {- [super viewDidLayoutSubviews];- insetForBars(self.tableView);-}--- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {- return 2;-}--- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return section == 0 ? (NSInteger)tabPresets().count : 1;-}--- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {- return sectionHeader(table, section == 0 ? @"Spotify's pages" : @"Anywhere else");-}--- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return kSectionHeaderHeight;-}--- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {- return CGFLOAT_MIN;-}--- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {- UITableViewCell *cell = dequeue(table, @"pick");- if (path.section == 0) {- NSDictionary *tab = tabPresets()[(NSUInteger)path.row];- fillCell(cell, tab[SGNavbarTitle], tab[SGNavbarURI], nil, nil);- } else {- fillCell(cell, @"Any link…", @"A name, a URI of your own and an icon", nil, @"link");- }- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- return cell;-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- [table deselectRowAtIndexPath:path animated:YES];- if (path.section == 0) {- appendTab(tabPresets()[(NSUInteger)path.row]);- [self.navigationController popViewControllerAnimated:YES];- return;- }- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Any link" message:@"Where the tab goes, and the glyph on it." preferredStyle:UIAlertControllerStyleAlert];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) { field.placeholder = @"Name"; }];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {- field.placeholder = @"spotify:playlist:…";- field.autocapitalizationType = UITextAutocapitalizationTypeNone;- field.autocorrectionType = UITextAutocorrectionTypeNo;- }];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {- field.placeholder = @"Icon";- field.text = @"star";- field.autocapitalizationType = UITextAutocapitalizationTypeNone;- field.autocorrectionType = UITextAutocorrectionTypeNo;- }];- [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- [alert addAction:[UIAlertAction actionWithTitle:@"Add" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {- NSString *title = alert.textFields[0].text, *uri = alert.textFields[1].text, *icon = alert.textFields[2].text;- if (!uri.length) return;- appendTab(@{SGNavbarTitle: title.length ? title : uri, SGNavbarURI: uri, SGNavbarIcon: icon.length ? icon : @"star"});- [self.navigationController popViewControllerAnimated:YES];- }]];- [self presentViewController:alert animated:YES completion:nil];-}--@end--// The tabs, in the order the bar shows them: drag to reorder, tap to show or hide, swipe a tab of-// your own away. Spotify's own tabs can only be hidden, never removed.-@interface SGNavbarPage : SGPage-@end--@implementation SGNavbarPage {- NSMutableArray<NSMutableDictionary *> *_entries;- UIView *_intro;-}--- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;- self.title = @"Navbar";- return self;-}--- (void)viewDidLoad {- [super viewDidLoad];- self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- self.tableView.backgroundColor = pageBackground();- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;- self.tableView.sectionHeaderTopPadding = 0;- self.tableView.allowsSelectionDuringEditing = YES;- self.tableView.editing = YES;- _intro = note(@"Drag a tab by the handle to move it, tap it to show or hide it. The bar follows straight away.");- self.tableView.tableHeaderView = _intro;- _entries = navbarEntries();-}--// The Add page writes straight to the layout, so the list is read again on the way back.-- (void)viewWillAppear:(BOOL)animated {- [super viewWillAppear:animated];- _entries = navbarEntries();- [self.tableView reloadData];-}--- (void)viewWillLayoutSubviews {- [super viewWillLayoutSubviews];- fitNote(self.tableView, _intro, 24, 0);-}--- (void)viewDidLayoutSubviews {- [super viewDidLayoutSubviews];- insetForBars(self.tableView);-}--- (void)save {- SGSetNavbarLayout(_entries);- SGRefreshTabBar();-}--- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {- return 4;-}--- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return section == 1 ? (NSInteger)_entries.count : 1;-}--- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {- return section == 1 ? sectionHeader(table, @"Tabs") : nil;-}--- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == 1 ? kSectionHeaderHeight : CGFLOAT_MIN;-}--- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {- return CGFLOAT_MIN;-}--- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {- UITableViewCell *cell = dequeue(table, @"navbar");- switch (path.section) {- case 0: {- fillCell(cell, @"Custom navbar", @"Off leaves the bar exactly as Spotify built it", nil, nil);- UISwitch *toggle = [UISwitch new];- toggle.onTintColor = green();- toggle.on = SGEnabled(SGKeyNavbar);- [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];- cell.accessoryView = toggle;- break;- }- case 1: {- NSDictionary *entry = _entries[(NSUInteger)path.row];- BOOL hidden = [entry[SGNavbarHidden] boolValue];- NSString *uri = entry[SGNavbarURI];- fillCell(cell, entry[SGNavbarTitle], hidden ? @"Hidden" : (uri ?: @"Spotify's own tab"),- hidden ? grey() : nil, hidden ? @"eye.slash" : @"eye");- break;- }- case 2:- fillCell(cell, @"Add a tab…", @"A page of Spotify's, or any link", nil, @"plus");- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- break;- default:- fillCell(cell, @"Use Spotify's order", @"Forgets the order and the tabs you added", nil, @"arrow.uturn.backward");- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- break;- }- return cell;-}--- (BOOL)tableView:(UITableView *)table canMoveRowAtIndexPath:(NSIndexPath *)path {- return path.section == 1;-}--- (BOOL)tableView:(UITableView *)table canEditRowAtIndexPath:(NSIndexPath *)path {- return path.section == 1;-}--// Spotify's own tabs stay on the list to be switched back on; only the mod's own can go.-- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)path {- if (path.section != 1) return UITableViewCellEditingStyleNone;- return _entries[(NSUInteger)path.row][SGNavbarURI] ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;-}--- (NSIndexPath *)tableView:(UITableView *)table targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)from toProposedIndexPath:(NSIndexPath *)to {- return to.section == 1 ? to : from;-}--- (void)tableView:(UITableView *)table moveRowAtIndexPath:(NSIndexPath *)from toIndexPath:(NSIndexPath *)to {- NSMutableDictionary *entry = _entries[(NSUInteger)from.row];- [_entries removeObjectAtIndex:(NSUInteger)from.row];- [_entries insertObject:entry atIndex:(NSUInteger)to.row];- [self save];-}--- (void)tableView:(UITableView *)table commitEditingStyle:(UITableViewCellEditingStyle)style forRowAtIndexPath:(NSIndexPath *)path {- if (style != UITableViewCellEditingStyleDelete) return;- [_entries removeObjectAtIndex:(NSUInteger)path.row];- [self save];- [table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- [table deselectRowAtIndexPath:path animated:YES];- if (path.section == 1) {- NSMutableDictionary *entry = _entries[(NSUInteger)path.row];- entry[SGNavbarHidden] = [entry[SGNavbarHidden] boolValue] ? nil : @YES;- [self save];- [table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];- } else if (path.section == 2) {- [self.navigationController pushViewController:[SGTabPickerPage new] animated:YES];- } else if (path.section == 3) {- [self reset];- }-}--- (void)toggled:(UISwitch *)toggle {- SGSetEnabled(SGKeyNavbar, toggle.on);- SGRefreshTabBar();-}--- (void)reset {- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Use Spotify's order"- message:@"Every tab of Spotify's comes back where Spotify put it, and the tabs you added go."- preferredStyle:UIAlertControllerStyleAlert];- [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- [alert addAction:[UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {- SGSetNavbarLayout(@[]);- SGRefreshTabBar();- self->_entries = navbarEntries();- [self.tableView reloadData];- }]];- [self presentViewController:alert animated:YES completion:nil];-}--@end--static NSString *const kRestart = @"Changes apply after you restart Spotify.";--static UIViewController *uiTweaksPage(void) {- return [[SGModPage alloc] initWithTitle:@"UI Tweaks" intro:kRestart sections:@[- section(@"Liquid Glass", @[- unstableRow(@"Tab bar", @"[WIP] Unstable", SGKeyTabBar,- @"The glass capsule does not render the way iOS draws its own, and there is no selection indicator behind the active tab. Switching this on will look wrong.\n\nIf you want to take it further, pull requests are very welcome."),- switchRow(@"Search field", @"Glass capsule instead of the white field", SGKeySearchField),- switchRow(@"Spotify's own Liquid Glass", @"The glass navigation bar, the new player slider and the new sheets, all shipped switched off", SGKeySpotifyGlass),- ]),- section(@"Theme", @[- switchRow(@"AMOLED background", @"Pure black instead of Spotify's dark grey", SGKeyAmoled),- ]),- ] footer:nil];-}--static UIViewController *homePage(void) {- return [[SGModPage alloc] initWithTitle:@"Home & Library" intro:kRestart sections:@[- section(@"Background", @[- optionRow(@"Gradient", @"A green wash behind the top of the page, fading into the background", SGKeyHomeGradient),- ]),- section(@"Hide", @[- hideRow(@"Filter pills", @"Music and Podcasts next to your avatar", SGHideHomePills),- hideRow(@"Shortcuts grid", @"The tiles at the top", SGHideHomeShortcuts),- hideRow(@"Promo cards", @"Single cards such as the next episode of a podcast", SGHideHomePromo),- hideRow(@"Preview cards", @"Album, playlist and video previews with a play button", SGHideHomePreviews),- hideRow(@"DJ card", @"Your own personal DJ", SGHideHomeDJ),- ]),- section(@"Spotify's flags", @[- flagRow(@"Pull to refresh", @"ios-home-evopage-impl.pull_to_refresh_enabled"),- flagRow(@"Hide items from Recents", @"ios-system-home-hidefromhome.is_hide_from_recents_enabled"),- flagRow(@"Hide items from Shortcuts", @"ios-system-home-hidefromhome.is_hide_from_shortcuts_enabled"),- ]),- section(@"Library", @[- flagRow(@"Denser rows", @"ios-feature-yourlibaryx.denser_rows_enabled"),- flagRow(@"Recents", @"ios-feature-yourlibaryx.recents_enabled"),- flagRow(@"Recents sort order", @"ios-feature-yourlibaryx.recents_sort_order_enabled"),- flagRow(@"Sort playlists by recently updated", @"ios-feature-yourlibaryx.recently_updated_playlists_sort_enabled"),- flagRow(@"Sort artists by recently updated", @"ios-feature-yourlibaryx.recently_updated_artists_sort_enabled"),- flagRow(@"Library settings", @"ios-feature-yourlibaryx.library_settings_enabled"),- flagRow(@"Library Pro", @"ios-feature-yourlibaryx.your_library_pro_enabled"),- ]),- ] footer:nil];-}--static UIViewController *playlistPage(void) {- return [[SGModPage alloc] initWithTitle:@"Playlist" intro:kRestart sections:@[- section(@"Hide in the header", @[- hideRow(@"Cover artwork", @"The square cover over the title", SGHidePlaylistArtwork),- hideRow(@"Description", @"The text under the title", SGHidePlaylistDescription),- hideRow(@"Creator and collaborators", @"The faces, the name and Message", SGHidePlaylistCreator),- hideRow(@"Length and saves", @"The line under the creator", SGHidePlaylistLength),- ]),- section(@"Hide header buttons", @[- hideRow(@"Video", @"The stack of clips at the start of the row", SGHidePlaylistVideo),- hideRow(@"Add to library", @"The plus", SGHidePlaylistAddTo),- hideRow(@"Download", @"The download arrow", SGHidePlaylistDownload),- hideRow(@"Share", @"The button that opens the share sheet", SGHidePlaylistShare),- hideRow(@"More", @"The three dots at the end of the row", SGHidePlaylistMore),- ]),- section(@"Hide over the tracks", @[- hideRow(@"Curation pills", @"Add, Mix, Video, Edit, Sort and the rest", SGHidePlaylistPills),- hideRow(@"Find and sort bar", @"Find on page and Sort, under the header", SGHidePlaylistFind),- ]),- ] footer:nil];-}--static UIViewController *lyricsPage(void) {- return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:kRestart sections:@[- section(@"Spotify's flags", @[- flagRow(@"Translations in the player", @"ios-feature-lyrics.enable_lyrics_multilanguage_npv"),- flagRow(@"Translations full screen", @"ios-feature-lyrics.enable_lyrics_multilanguage_fullscreen"),- flagRow(@"Keep lyrics offline", @"ios-feature-lyrics.lyrics_offline_enabled"),- flagRow(@"Vocal removal", @"ios-feature-lyrics.enable_vocal_removal"),- flagRow(@"Lyrics toggle in the context menu", @"ios-feature-lyrics.lyrics_context_menu_toggle_enabled"),- flagRow(@"Dynamic colours", @"ios-feature-lyrics.enable_dynamic_colors"),- flagRow(@"Centre a single line", @"ios-feature-lyrics.is_single_line_centering_enabled"),- flagRow(@"Full screen on track change", @"ios-feature-lyrics.enable_fullscreen_track_change"),- flagRow(@"Edit lyrics", @"ios-feature-lyrics.lyrics_edit_enabled"),- ]),- ] footer:nil];-}--static UIViewController *nowPlayingPage(void) {- return [[SGModPage alloc] initWithTitle:@"Now Playing" intro:kRestart sections:@[- section(@"Liquid Glass", @[- switchRow(@"Now playing bar", @"Glass card with round artwork", SGKeyNowPlayingBar),- optionRow(@"Artwork background", @"The cover blurred and dimmed behind the player instead of the flat album colour", SGKeyPlayerBackdrop),- switchRow(@"Header buttons", @"Glass circles behind close and more, over the artwork", SGKeyPlayer),- switchRow(@"Lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard),- ]),- section(@"Spotify's flags", @[- flagRow(@"Sheet style player", @"ios-feature-nowplaying.sheet_style_npv"),- flagRow(@"Queue as a bottom sheet", @"ios-feature-nowplaying.bottom_sheet_queue_enabled"),- flagRow(@"Queue flip transition", @"ios-feature-nowplaying.queue_flip_transition_enabled"),- flagRow(@"Mini player transition animations", @"ios-feature-nowplaying.miniplayer_transition_animations"),- flagRow(@"Bar to cover art animation", @"ios-feature-nowplaying.bartocoverart_animation_enabled"),- flagRow(@"White heart button", @"ios-feature-nowplaying.white_heart_button_in_nowplaying_screen"),- flagRow(@"Expand the sticky header on tap", @"ios-feature-nowplaying.expand_sticky_header_on_tap"),- flagRow(@"Cover art in the header", @"ios-feature-nowplaying.show_header_context_cover_art"),- flagRow(@"Redesigned header with context menu", @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled"),- 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),- hideRow(@"Connect to a device", @"The speaker and device name in the bottom row", SGHideConnect),- hideRow(@"Share", @"The share button in the bottom row", SGHideShare),- hideRow(@"Queue", @"The queue button in the bottom row", SGHideQueue),- hideRow(@"Add to playlist", @"The plus next to the track title", SGHideAddTo),- ]),- section(@"Under the artwork", @[- hideRow(@"Lyrics preview", @"The lyric lines shown under the artwork", SGHideLyricsInline),- ]),- section(@"Hide cards below the player", @[- hideRow(@"Lyrics", @"The lyrics card", SGHideLyricsCard),- hideRow(@"About the artist", @"Photo, listeners and biography", SGHideAboutArtist),- hideRow(@"Related videos", @"The video carousel", SGHideRelatedVideos),- hideRow(@"SongDNA", @"Discover the people behind the song", SGHideSongDNA),- hideRow(@"Live events", @"Concerts and tickets", SGHideLiveEvents),- hideRow(@"Explore the artist", @"The vertical video cards", SGHideExploreArtist),- hideRow(@"Credits", @"Performers and writers", SGHideCredits),- hideRow(@"Merch", @"The artist's shop", SGHideMerch),- hideRow(@"Recommendations", @"\"Artist: what you might like\", the episode and track rows", SGHideRecommendations),- ]),- section(nil, @[- pageRow(@"Lyrics", ^UIViewController *{ return lyricsPage(); }),- ]),- ] 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 *playbackPage(void) {- return [[SGModPage alloc] initWithTitle:@"Playback" intro:kRestart sections:@[- section(@"Speed", @[- flagRow(@"Speed control for music", @"ios-playbackcontrol-playbackspeed-impl.enable_playback_speed_for_music"),- flagRow(@"Trim silence", @"ios-playbackcontrol-playbackspeed-impl.enable_trim_silence"),- flagRow(@"Speed shortcuts", @"ios-playbackcontrol-playbackspeed-impl.enable_speed_shortcuts_v2"),- ]),- section(@"Queue", @[- flagRow(@"Swipe a row to play next", @"ios-feature-queue.is_swipe_to_play_next_enabled"),- flagRow(@"Play next in the context menu", @"ios-feature-queue.is_play_next_context_menu_enabled"),- flagRow(@"Reshuffle", @"ios-feature-queue.is_reshuffle_enabled"),- flagRow(@"Peek the queue when adding", @"ios-feature-queue.is_queue_peek_on_add_enabled"),- ]),- section(@"Player", @[- flagRow(@"Pinch to zoom", @"ios-feature-nowplaying-fullscreen.pinch_to_zoom"),- flagRow(@"Audio settings in the menu", @"ios-nowplaying-contextmenusettings-impl.audio_settings"),- flagRow(@"Playback settings in the menu", @"ios-nowplaying-contextmenusettings-impl.playback_settings"),- flagRow(@"Video settings in the menu", @"ios-nowplaying-contextmenusettings-impl.video_settings"),- flagRow(@"New progress slider", @"ios-feature-encoreexperiments.new_npv_slider_enabled"),- flagRow(@"Tilt the cover art", @"ios-creativeworkcommons-cover-art-tilt-configuration-kit.cover_art_tilt_enabled"),- flagRow(@"Tilt it on album and playlist pages", @"ios-creativeworkcommons-cover-art-tilt-configuration-kit.album_playlist_and_podcast_pages_enabled"),- flagRow(@"Lyrics over Canvas", @"ios-feature-canvas.lyrics_on_canvas_enabled"),- flagRow(@"Mixing transitions", @"ios-feature-canvas.mixing_transition_enabled"),- flagRow(@"Picture in picture in the app", @"ios-feature-picture-in-picture.picture_in_picture_in_app"),- flagRow(@"Connect as a bottom sheet", @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet"),- flagRow(@"Connect sheet from the video switcher", @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet"),- ]),- section(@"Now playing bar", @[- flagRow(@"Hold and drag to resize", @"ios-feature-nowplayingbar.hold_and_drag_to_resize"),- flagRow(@"Save button", @"ios-feature-nowplayingbar.add_button"),- flagRow(@"Queue badge", @"ios-feature-nowplayingbar.queue_badge"),- flagRow(@"Two lines of track info", @"ios-feature-nowplayingbar.two_lines_information_unit"),- ]),- section(@"Spotify's settings", @[- flagRow(@"Offline listening toggle", @"ios-feature-settings.enable_offline_listening_toggle"),- flagRow(@"Gapless in Playback settings", @"ios-feature-settings.use_playback_settings_gapless"),- ]),- ] footer:nil];-}--// Every switch here forces a flag Spotify ships on to off, so the switch off is Spotify's own value.-static UIViewController *adsPage(void) {- return [[SGModPage alloc] initWithTitle:@"Ads & nags" intro:kRestart sections:@[- section(@"Ads", @[- killRow(@"Ad when the app opens", @"ios-feature-adonappopen.enabled"),- killRow(@"Its CTA card", @"ios-feature-adonappopen.cta_card_enabled"),- ]),- section(@"Upsells", @[- killRow(@"Shuffle toggle upsell", @"ios-feature-shuffletoggleupsell.is_enabled_pt2"),- killRow(@"Shuffle upsell in the video player", @"ios-feature-nowplaying-modes.video_first_shuffle_upsell_enabled"),- ]),- section(@"Badges", @[- killRow(@"DJ beta badge", @"ios-home-evopage-impl.dj_mdc_beta_badge_enabled"),- killRow(@"DJ button on Home", @"ios-home-evopage-impl.idj_show_dj_button"),- ]),- section(@"Tooltips", @[- killRow(@"Data saver", @"ios-feature-nowplayingbar.data_saver_tooltip"),- killRow(@"Smart shuffle helper", @"ios-messaging-reduceinterventions-impl.enable_message_smart_shuffle_helper_tooltip"),- killRow(@"Watch feed explorer", @"ios-messaging-reduceinterventions-impl.enable_message_watch_feed_entity_explorer_tooltip"),- killRow(@"AI playlist creation", @"ios-messaging-reduceinterventions-impl.enable_message_your_library_ai_playlist_creation_tooltip"),- killRow(@"Account switching", @"ios-messaging-reduceinterventions-impl.enable_message_account_switching_tooltip"),- killRow(@"Concert notifications", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_concert_notifications_tooltip"),- killRow(@"Live event", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_safe_tooltip"),- killRow(@"Live event venue", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_venuename_header_tooltip"),- killRow(@"Player suggestions upsell", @"ios-messaging-reduceinterventions-impl.enable_message_reinvent_free_n_p_v_suggestions_upsell"),- killRow(@"Puffin nudge", @"ios-messaging-reduceinterventions-impl.enable_message_puffin_nudge_end_optimization"),- ]),- section(nil, @[- flagRow(@"Reduce interventions", @"ios-messaging-reduceinterventions-impl.enabled"),- ]),- ] footer:@"The tooltip switches belong to Spotify's own intervention-reduction system, which the last switch turns on."];-}--static UIViewController *unreleasedPage(void) {- return [[SGModPage alloc] initWithTitle:@"Unreleased" intro:kRestart sections:@[- section(@"Player", @[- flagRow(@"Snake on the cover art", @"ios-feature-cover-art-snake.enabled"),- flagRow(@"SongDNA", @"ios-songdna-featureproperties.is_song_dna_enabled"),- flagRow(@"SongDNA covers playlist", @"ios-songdna-featureproperties.enable_go_to_covers_playlist"),- ]),- section(@"Podcast comments", @[- flagRow(@"Comments card", @"ios-feature-comments.enable_comments_card"),- flagRow(@"Pinned comments", @"ios-feature-comments.enable_pinned_comments"),- flagRow(@"Several reactions", @"ios-feature-comments.enable_multi_reactions"),- ]),- section(@"Sleep timer", @[- flagRow(@"Fade out", @"ios-feature-sleeptimer.enable_fade_out"),- flagRow(@"One minute option", @"ios-feature-sleeptimer.enable_one_minute_option"),- flagRow(@"Options sheet", @"ios-feature-sleeptimer.use_options_sheet"),- ]),- section(@"Elsewhere", @[- flagRow(@"Local files from the Files app", @"ios-feature-localfiles.documents_enabled"),- flagRow(@"Progress bar in the home screen widget", @"ios-widgets-widgetremoteconfig-impl.progress_bar_enabled"),- ]),- ] footer:nil];-}--static UIViewController *martiniPage(void) {- return [[SGModPage alloc] initWithTitle:@"AI Chat (Martini)" intro:kRestart sections:@[- section(@"On Home", @[- flagRow(@"Chat entry point", @"ios-home-evopage-impl.interactive_entrypoint_enabled"),- flagRow(@"Martini behind it", @"ios-home-evopage-impl.interactive_entrypoint_martini_enabled"),- flagRow(@"Floating chat", @"ios-home-evopage-impl.interactive_entrypoint_floating_chat_enabled"),- flagRow(@"Microphone", @"ios-home-evopage-impl.interactive_entrypoint_mic_enabled"),- flagRow(@"Glowing pill", @"ios-home-evopage-impl.interactive_entrypoint_pill_glow_enabled"),- ]),- section(@"The chat", @[- flagRow(@"Intent pills", @"ios-martini-floatingchat-impl.intent_pills_enabled"),- flagRow(@"Thinking states", @"ios-martini-floatingchat-impl.thinking_states_enabled"),- flagRow(@"Voice recording", @"ios-martini-floatingchat-impl.voice_recording_enabled"),- ]),- section(@"In the player", @[- flagRow(@"Chat entry point", @"ios-martini-npvcardprovider-impl.floating_chat_entry_point_enabled"),- ]),- ] footer:nil];-}--static UIViewController *experimentalPage(void) {- return [[SGModPage alloc] initWithTitle:@"Experimental" intro:nil sections:@[- section(nil, @[- pageRow(@"AI Chat (Martini)", ^UIViewController *{ return martiniPage(); }),- ]),- ] footer:nil];-}--static UIViewController *privacyPage(void) {- NSMutableArray<SGModRow *> *counts = [NSMutableArray array];- for (NSString *label in SGBlockedLabels()) {- [counts addObject:statRow(label, ^NSString *{- return @(SGBlockedCount(label)).stringValue;- })];- }- [counts addObject:statRow(@"Total", ^NSString *{- return @(SGBlockedCount(nil)).stringValue;- })];- return [[SGModPage alloc] initWithTitle:@"Privacy" intro:kRestart sections:@[- section(@"Telemetry", @[- switchRow(@"Block telemetry", @"Answer the analytics endpoints with an empty reply instead of letting the request out", SGKeyBlockTelemetry),- ]),- section(@"Blocked so far", counts),- section(nil, @[- actionRow(@"Reset the counters", @"Start counting from zero", ^{ SGResetBlocked(); }),- ]),- ] footer:nil];-}--// Which build this is, whether the site has a newer one, and where to reach the mod: without these-// rows a build that is already installed has no way of telling its user that anything moved on.-static SGModSection *aboutSection(void) {- NSString *spotify = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"unknown";- return section(@"About", @[- statRow(@"Version", ^NSString *{ return @(SG_VERSION); }),- statRow(@"Spotify", ^NSString *{ return spotify; }),- statActionRow(@"Updates", @"Asks the site for the newest build; tap to check now", ^NSString *{- return SGUpdateStatus();- }, ^{ SGCheckForUpdate(YES); }),- linkRow(@"Website", @"Downloads, and the source to add to AltStore or SideStore", SGSiteURL),- linkRow(@"GitHub", @"Source, releases and issues", SGRepoURL),- ]);-}--static UIViewController *modSettingsPage(void) {- // Opening the page is the only thing that asks; the cache keeps it to once every six hours.- SGCheckForUpdate(NO);- return [[SGModPage alloc] initWithTitle:@"Mod Settings" intro:nil sections:@[- section(nil, @[- pageRow(@"UI Tweaks", ^UIViewController *{ return uiTweaksPage(); }),- pageRow(@"Navbar", ^UIViewController *{ return [SGNavbarPage new]; }),- pageRow(@"Home & Library", ^UIViewController *{ return homePage(); }),- pageRow(@"Playlist", ^UIViewController *{ return playlistPage(); }),- pageRow(@"Now Playing", ^UIViewController *{ return nowPlayingPage(); }),- pageRow(@"Lock screen widget", ^UIViewController *{ return lockScreenPage(); }),- pageRow(@"Playback", ^UIViewController *{ return playbackPage(); }),- pageRow(@"Ads & nags", ^UIViewController *{ return adsPage(); }),- pageRow(@"Unreleased", ^UIViewController *{ return unreleasedPage(); }),- pageRow(@"Experimental", ^UIViewController *{ return experimentalPage(); }),- pageRow(@"Privacy", ^UIViewController *{ return privacyPage(); }),- pageRow(@"All flags", ^UIViewController *{ return [SGFlagsPage new]; }),- ]),- aboutSection(),- ] footer:nil];-}--#pragma mark - row in the settings list--@interface SGModSettingsRow : UIControl-@end--@implementation SGModSettingsRow {- UIImageView *_icon;- UILabel *_title;- UIImageView *_chevron;-}--- (instancetype)initWithFrame:(CGRect)frame {- if (!(self = [super initWithFrame:frame])) return nil;- _icon = symbol(@"slider.horizontal.3", 20, UIImageSymbolWeightRegular, 24);- _title = [UILabel new];- _title.text = @"Mod Settings";- _title.textColor = UIColor.whiteColor;- _chevron = symbol(@"chevron.right", 11, UIImageSymbolWeightSemibold, 12);- for (UIView *v in @[_icon, _title, _chevron]) [self addSubview:v];- [self addTarget:self action:@selector(open) forControlEvents:UIControlEventTouchUpInside];- return self;-}--- (void)layoutSubviews {- [super layoutSubviews];- _title.font = titleFont();- CGFloat width = self.bounds.size.width, height = self.bounds.size.height;- _icon.frame = CGRectMake(12, (height - 24) / 2, 24, 24);- _title.frame = CGRectMake(48, 0, width - 96, height);- _chevron.frame = CGRectMake(width - 24, (height - 12) / 2, 12, 12);-}--- (void)setHighlighted:(BOOL)highlighted {- [super setHighlighted:highlighted];- self.alpha = highlighted ? 0.5 : 1;-}--- (void)open {- UIViewController *owner = nil;- for (UIResponder *r = self; r && !owner; r = r.nextResponder) {- if ([r isKindOfClass:UIViewController.class]) owner = (UIViewController *)r;- }- UIViewController *page = modSettingsPage();- if (owner.navigationController && sg_pagesConform) [owner.navigationController pushViewController:page animated:YES];- else [owner presentViewController:[[UINavigationController alloc] initWithRootViewController:page] animated:YES completion:nil];-}--@end--static CGFloat brightness(UIColor *color) {- CGFloat white = 0;- [color getWhite:&white alpha:NULL];- return white;-}--// Spotify's list labels carry its typeface: 13pt titles and 11pt grey subtitles.-static void captureFonts(UIView *list, UIView *row) {- SGForEachView(list, ^(UIView *v) {- if (![v isKindOfClass:UILabel.class] || SGIsInside(v, row)) return;- UILabel *label = (UILabel *)v;- if (label.text.length < 2) return;- CGFloat size = label.font.pointSize, white = brightness(label.textColor);- if (size == 13 && !sg_titleFont) sg_titleFont = label.font;- if (size == 11 && !sg_subtitleFont && white > 0.3 && white < 0.95) sg_subtitleFont = label.font;- });-}--static void placeRow(UICollectionView *list, SGModSettingsRow *row) {- if (!sg_titleFont || !sg_subtitleFont) captureFonts(list, row);- CGFloat bottom = list.contentSize.height;- row.hidden = bottom <= 0;- row.frame = CGRectMake(0, bottom, list.bounds.size.width, kRowHeight);-- // Room to scroll to the row, added again whenever Spotify resets the inset.- UIEdgeInsets inset = list.contentInset;- NSValue *applied = objc_getAssociatedObject(list, &kInsetKey);- if (applied && UIEdgeInsetsEqualToEdgeInsets(inset, applied.UIEdgeInsetsValue)) return;- inset.bottom += kRowHeight;- objc_setAssociatedObject(list, &kInsetKey, [NSValue valueWithUIEdgeInsets:inset], OBJC_ASSOCIATION_RETAIN_NONATOMIC);- list.contentInset = inset;-}--// Media quality, Playback, Account and most of the rest of settings are the same controller class-// as the list they were opened from, which is why the row turned up at the end of all of them.-// What is on the navigation stack is not that controller though: every page in the app is wrapped-// in a MusicAppPageHostingViewController (trees/settings notifications opened.txt), and Spotify-// pushes a settings sub page as a page of its own, leaving the list it came from on the stack-// underneath. So the settings list inside the lowest wrapper that holds one is the list the row-// belongs at the end of, and a controller with no stack to be found on keeps the row rather than-// losing it.-static UIViewController *settingsListIn(UIViewController *page, Class kind) {- if ([page isKindOfClass:kind]) return page;- for (UIViewController *child in page.childViewControllers) {- UIViewController *found = settingsListIn(child, kind);- if (found) return found;- }- return nil;-}--static BOOL isSettingsRoot(UIViewController *list) {- for (UIViewController *page in list.navigationController.viewControllers) {- UIViewController *found = settingsListIn(page, list.class);- if (found) return found == list;- }- return YES;-}--%hook _TtC21Settings_PlatformImpl26SettingsListViewController-- (void)viewDidLayoutSubviews {- %orig;- BOOL root = isSettingsRoot((UIViewController *)self);- for (UIView *sub in ((UIViewController *)self).view.subviews) {- if (![sub isKindOfClass:UICollectionView.class]) continue;- SGModSettingsRow *row = objc_getAssociatedObject(sub, &kRowKey);- // A page that laid itself out before it was on the stack looked like the list for as long- // as that took; the row goes again as soon as it can be seen for what it is.- if (!root) {- [row removeFromSuperview];- objc_setAssociatedObject(sub, &kRowKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- continue;- }- if (row) continue;- row = [[SGModSettingsRow alloc] initWithFrame:CGRectZero];- objc_setAssociatedObject(sub, &kRowKey, row, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- [sub addSubview:row];- }-}-%end--// The list lays out after its controller and again whenever its content changes.-%hook UICollectionView-- (void)layoutSubviews {- %orig;- SGModSettingsRow *row = objc_getAssociatedObject(self, &kRowKey);- if (row) placeRow(self, row);-}-%end--%ctor {- %init;- SGRequireClasses(@[@"_TtC21Settings_PlatformImpl26SettingsListViewController"]);- // Swift's own name for the protocol, which is what the runtime registers it under.- Protocol *page = objc_getProtocol("_TtP19Tome_PageAttributes17SPTPageController_") ?: objc_getProtocol("SPTPageController");- sg_pagesConform = page && class_addProtocol(SGPage.class, page);- if (!sg_pagesConform) SGLog(@"SPTPageController not found, the mod's pages are presented instead of pushed");-}