Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
refactor: keep the native look and the redesign apart, each with its own copies, gated by Redesigned UI and checked at build
Vojtěch Škopekeca5d784f8cc
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex f21b5f6e..e07e10a0 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -3,17 +3,17 @@## Layouttweak/ 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/Core/ what every file builds on: logging, preferences, view-tree walking, glass panes, the+ look this launch runs (SGUIMode.h) and the forced-flag registry (SGFlagForce.h)tweak/Sources/Headers/ reverse-engineered Spotify classes, one header each, only the selectors usedtweak/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+ of rows), SGPageStyle (Spotify's list look), SGGlowSwitch+ tweak/Sources/Shared/ what works the same with either look, see Layers below+ tweak/Sources/Native/ tweaks on Spotify's own screens, running only while Redesigned UI is off+ tweak/Sources/Redesigned/ the redesign, running only while Redesigned UI is on+ tweak/Sources/App/ what brings the layers together: Mod Settings' root and composed pages, the Mod page,+ backup and signing, the welcome tourtweak/Sources/Diagnostics/ screen dumps and the tree server of FLEX builds- tweak/Sources/Redesign/ screens rebuilt in Liquid Glass instead of tweaked: Kit/ (the artwork field, glass inside- Spotify's controls, glyphs, restyle helpers, player and link bridges, the switch per- screen and the flags a screen forces) and Player/, the redesigned full screen playerscripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py,record-session.py, dump-log.sh, extract-flags.py, publish.sh (release: version bump,site release.json)@@ -23,36 +23,49 @@vendor/ AutoFLEX debipa/, out/ decrypted Spotify IPA in, built IPAs out (both gitignored)-`tweak/Sources/Features/Flags/SGFlagList.m` is generated from the IPA and gitignored, as are the+`tweak/Sources/Shared/Flags/SGFlagList.m` is generated from the IPA and gitignored, as are therecorded trees: both are read out of Spotify's own binary and belong to whoever built them.-## Features+## Layers-A feature is a directory under `tweak/Sources/Features/` holding everything about one area of the-app:+The mod has two looks, picked by Redesigned UI in Appearance: Spotify's own screens with the mod's+tweaks on them, or the redesign, which starts from a clean sheet. What does not draw on Spotify's+screens works under both. So the sources are four layers, each a directory of features:++ Shared/ works the same with either look+ Native/ Spotify's own screens tweaked; every %ctor starts with `if (!SGNativeUI()) return;`+ Redesigned/ the redesign; every %ctor starts with `if (!SGRedesignedUI()) return;`+ App/ Mod Settings' root and the pages that combine the layers, the Mod page, the tour++The two looks never run together, so each hooks the same Spotify class in its own way, and a part of+the look is edited on its own side without touching the other: where both need the same thing, each+has its own copy (the karaoke view, the tab bar's composition and its editor, the lyrics page's glass,+the soft top edge), under its own names (SG… native, SGR… redesign) and its own keys. The imports run+one way, Core <- Settings <- Shared <- Native | Redesigned <- App, and `scripts/check-layers.sh`, run+by tweak/Makefile before every build, fails on any other. A layer below that needs something from one+above takes it through a registry in Core (forced flags, SGFlagForce.h) or a function declared low and+defined high (SGOpenModSettings).++A feature is a directory in its layer 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, or its sections on the page of the part it changes, built from- the rows in Settings/SGModPage.h+ <Feature>Settings.m its Mod Settings page, or its sections for the page of the part it changes, built from+ the rows in Settings/SGModPage.h; App/Pages.m puts them on the page<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; its sections sit on the Home & Library page- Declutter/ cards under the player and sections of Home collapsed, player buttons hidden; rows on the Player, Lyrics and Home & Library pages- Appearance/ AMOLED (Amoled.x), the glass search field (SearchField.x), the accent colour (Accent.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 Labs page- Privacy/ telemetry blocking and its counters+Shared:+AdBlock/ EeveeSpotify's ad blocking: the ad and upsell services silenced (AdServices.x), ad components out of theHub JSON (AdHubs.x) and the feeds (Feeds.m), Premium pop-ups dropped (AdPopups.x), and the responsesrewritten on the way in (AdNetwork.x, Premium.m over the protobuf walker in Protobuf.m), with crossfadeand automix switched on in the player core and crossfade's switch kept in step with its slider (Crossfade.x)+ Privacy/ telemetry blocking and its countersArtistBlock/ tracks by blocked artists skipped as they start (ArtistSkip.x), the list and the Blocked artists page under Player- Karaoke/ Apple Music style lyrics on the full screen page and on the card under the player: lines read from color-lyrics- and the player's clock (KaraokeSource.x), words timed by estimate inside Spotify's line times (KaraokeTiming.m),- drawn by KaraokeView.m over the page (KaraokePage.x) and, in compact, over the card (KaraokeCard.x)+ Flags/ Spotify's remote-config flags: the provider hook, the generated table, the All flags page and the Labs page+ Gestures/ the double tap zones on the player: the grid, what each cell does, the recognizer (each look hooks it on)+ Lyrics/ Apple Music style lyrics' engine: lines read from color-lyrics and the player's clock (KaraokeSource.x),+ words timed by estimate inside Spotify's line times (KaraokeTiming.m), and the Lyrics page's rowsLyricsSources/ the sources lyrics come from, asked in the order the Lyrics page puts them in and merged into thebest answer (LyricsSources.m, the list to drag in LyricsSourcesPage.m): Apple Music's TTML fromBiniLyrics.m and Unison.m, read by SGTTML.m, which is the only shape carrying a second voice and the@@ -67,8 +80,38 @@ app:lyrics and show the card. has_lyrics is forced on for every track, the walk starts at the track changefor it and the next, and the player's card-loading timeout flag is forced to its 5 s maximum while asource is on- Onboarding/ the welcome tour over Home on the first launch (Onboarding.x, the pages in Tour.m), offered again from the Mod page- About/ the update check and the Mod page: the build, its updates, the links and the reset+ LockScreenLyrics/ the line being sung in the system's now playing+ Navigation/ the page transition fix (PageTransition.x) and opening a spotify: link (Links.x)+ Player/ the player's open and close announced (PlayerEvents.x), the lock screen widget's flags++Native:++ Appearance/ AMOLED (Amoled.x), the accent colour (Accent.x), the soft top edge (EdgeEffect.x), and Repaint.x, which+ keeps what the native tweaks stripped transparent+ Navbar/ Spotify's tab bar composed (Navbar.x, NavbarLayout.m, hooked from TabBarHooks.x), the Navbar and Add a tab pages+ NowPlayingBar/ the device button hidden, the bar's flags+ Player/ the full screen player (Player.x), its cards and buttons hidden (PlayerDeclutter.x), the glass lyrics card+ (LyricsCard.x), karaoke on the card (KaraokeCard.x), the gestures' hookup, the Queue & devices flags+ Lyrics/ the full screen lyrics page on glass (LyricsPage.x), karaoke over it (KaraokePage.x, KaraokeView.m)+ Home/ the Home gradient, Home's sections and pills hidden (HomeDeclutter.x), the Home & Library page+ Playlist/ the playlist header and pills, hidden one switch each+ Album/, Artist/ their pages' parts hidden, and the cover or photo behind their headers++Redesigned:++ Kit/ what the redesign builds on (SGRKit.h lists it), the flags it forces (SGRedesign.h, SGRGlassDesign.x for+ Spotify's own glass design), its repaint hook (SGRRepaint.x) and soft top edge+ Navbar/ the glass tab bar (TabBar.x) over its own composition (Navbar.x, NavbarLayout.m) and editor, the glass search field+ NowPlayingBar/ the glass now playing bar+ Player/ the redesigned full screen player (Player.h lists its files)+ Lyrics/ the full screen lyrics page on glass and its own karaoke view (SGRKaraokeView)++App:++ ModSettings.x the root page and the rows that open it from Spotify's settings and the side drawer+ Pages.m the Appearance card with Redesigned UI, the Player and Lyrics pages, which Navbar page opens+ About/ the update check, backup, the signing warning and the Mod page with the reset+ Onboarding/ the welcome tour over Home on the first launch, offered again from the Mod pageEvery key a feature stores starts with `spotifyglass.`, whatever it holds: Reset all settings onthe Mod page removes by that prefix and has no list to keep up to date. It leaves `SGKeyStock` behind,@@ -76,7 +119,7 @@ which makes every unset switch read off, so a reset is stock Spotify whatever swA hook reads its switch when it runs (`SGEnabled`, `SGHidden`, `SGFlag` from Core/SGPrefs.h), so achange shows after Spotify restarts; the tab editor on the Navbar page is the exception and applies as soon as the bar lays-out again, as are the Home gradient's colour, strength and height, but not the switch that turns it on. The root page in `Settings/SGModSettings.x` holds the Appearance card and links the page of each part of Spotify by hand.+out again, as are the Home gradient's colour, strength and height, but not the switch that turns it on. The root page in `App/ModSettings.x` holds the Appearance card and links the page of each part of Spotify, and only the stored look's.## Make targets@@ -96,20 +139,18 @@ Mod Settings, opened by holding Home on the tab bar or from the first row of thelast row of Spotify's Settings, sorts everysetting by the part of Spotify it changes, so a part's glass, its hide switches and its flags sit onone page, the mod's own rows first and Spotify's flags below them or on a sub page named after what-they change. It opens on the Appearance card, the three switches that style the whole app: Redesigned-UI, AMOLED and the accent colour (Spotify's green is offered from the colour row once a colour-is set). Redesigned UI is the one switch between two looks: off, Spotify's own screens with the mod's-switches on them; on, the redesigned screens of Redesign/ in their place (for now the full screen-player), Spotify's newer glass design and every glass switch of the mod's. It glows (Settings/SGGlowSwitch)-and its ⓘ says what it changes. While it is on, the switches for Spotify's own version of a redesigned-screen are put away on that screen's page, the legacy hooks of that screen stand aside, and the flags-the redesign is built on are forced over any override. Then a card of parts. Navbar: the glass tab bar and search field, then the tab editor.-Player: Gestures, Lyrics (Apple Music style, glass lyrics, the ordered list of lyrics sources, lyrics-for every track, naming the source, the lyrics flags), Blocked artists (with the count on the row), Now-playing bar (its glass, its device button and its flags), and Queue & devices and Lock screen widget as-flag pages, which work with either player; then Spotify's own player screen (artwork background, glass-header buttons, Disable Canvas and the sheet, header, slider and sticky header flags, the cards under the-player and the lyrics preview and player buttons to hide), put away while Redesigned UI is on. Home & Library:+they change. It opens on the Appearance card: Redesigned UI, and in the native look AMOLED and the accent colour+(Spotify's green is offered from the colour row once a colour is set). Redesigned UI is the one switch+between the two looks (see Layers): it glows (Settings/SGGlowSwitch) and its ⓘ says what it changes.+The pages show only what the stored look has: a page opened after flipping the switch already shows+what the restart will bring. Then a card of parts. Navbar: the tab editor of the stored look, each with+its own list of tabs. Player: Gestures, Lyrics (Apple Music style, the lock screen, in the native look+glass lyrics, the ordered list of lyrics sources, lyrics for every track, naming the source, the lyrics+flags), Blocked artists (with the count on the row) and Lock screen widget, which work with either look;+in the native look also Now playing bar (its device button and its flags), Queue & devices, and+Spotify's own player screen (artwork background, glass header buttons, Disable Canvas and the sheet,+header, slider and sticky header flags, the cards under the player and the lyrics preview and player+buttons to hide). Home & Library, in the native look only:the Gradient page (the wash behind the top of Home in one of eight colours, at three strengths andfour heights) and the Home flags, the parts of Home to hide including the DJ button and badge, theplaylist header, buttons and pills to hide, and the Library flags. Then Premium, ads & privacy@@ -122,11 +163,11 @@ Auto / Off / On control per flag (a text field for the number and text ones), ancheck, the build and Spotify's version, the site and the repo, the welcome tour again and Reset allsettings. A flag switch on a page forces that one flag and off leaves Spotify's own value, so the Allflags page is where a flag goes back to Auto. Spotify ships its newer design behind several flags at-once, so Redesigned UI owns them (the glass navigation bar, the new player slider, the sheet style+once, and the redesign is built on it (the glass navigation bar, the new player slider, the sheet styleplayer, the queue and Connect sheets, the redesigned player header, the sleep timer's options sheet):-while it is on it forces each of them, and their rows elsewhere show what it forces and take no-touch, so the group has one switch. `SGGlassOwnsFlag` in Features/Flags/Flags.x holds the list. A-change shows after Spotify restarts.+while Redesigned UI is on each is forced, over an override too, and their rows elsewhere show what is+forced and take no touch. `Redesigned/Kit/SGRGlassDesign.x` holds the list; what else forces a flag+registers in `Core/SGFlagForce.h`. A change shows after Spotify restarts.The tab editor on the Navbar page 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@@ -138,14 +179,15 @@ never lights up as the tab you are on.## Adding a feature1. `make trees`, record the screen, read `trees/<screen>.txt` for the classes and frames.-2. Make `tweak/Sources/Features/<Feature>/` with `<Feature>.h` declaring the switch key+2. Decide the layer (see Layers), then make `tweak/Sources/<Layer>/<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 theswitch, use `SGGlassFor`/`SGGlassAt` + `SGShapeGlass` for glass and `SGStripBackgrounds` to clear- Spotify's paint, and end with `%ctor { %init; SGRequireClasses(@[...]); }`.+ Spotify's paint, and end with `%ctor { %init; SGRequireClasses(@[...]); }`, gated first on the layer's look+ (`SGNativeUI()` or `SGRedesignedUI()`) in Native/ and Redesigned/.4. Add `<Feature>Settings.m` returning an `SGModPage` of `SGSection`s of `SGSwitchRow`/`SGHideRow`/- `SGFlagRow` (Settings/SGModPage.h), and link it from the page of the part of Spotify it changes, or from- `Settings/SGModSettings.x` if it is a part of its own.+ `SGFlagRow` (Settings/SGModPage.h), and put it on the page of the part of Spotify it changes in `App/Pages.m`+ or `App/ModSettings.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.diff --git a/scripts/check-layers.sh b/scripts/check-layers.shnew file mode 100755index 00000000..ec79c2ba--- /dev/null+++ b/scripts/check-layers.sh@@ -0,0 +1,29 @@+#!/bin/sh+# Fails when a source file imports across the layers docs/tweaks.md lays out, so the native look and the+# redesign stay apart: Core <- Settings <- Shared <- Native | Redesigned <- App. Native and Redesigned+# never import each other; only App imports every layer. Run from tweak/Makefile before every build.+# scripts/check-layers.sh [path to tweak/Sources]+SOURCES=${1:-"$(dirname "$0")/../tweak/Sources"}+cd "$SOURCES" || exit 1+status=0++forbid() {+ layer=$1+ pattern=$2+ [ -d "$layer" ] || return+ hits=$(grep -rnE --include='*.x' --include='*.m' --include='*.h' "#import \"($pattern)/" "$layer")+ if [ -n "$hits" ]; then+ echo "layers: $layer must not import $pattern:" >&2+ echo "$hits" >&2+ status=1+ fi+}++forbid Core "Settings|Shared|Native|Redesigned|App"+forbid Headers "Core|Settings|Shared|Native|Redesigned|App"+forbid Diagnostics "Settings|Shared|Native|Redesigned|App"+forbid Settings "Shared|Native|Redesigned|App"+forbid Shared "Native|Redesigned|App"+forbid Native "Redesigned|App"+forbid Redesigned "Native|App"+exit $statusdiff --git a/tweak/Makefile b/tweak/Makefileindex 81376dbe..8c81efdf 100644--- a/tweak/Makefile+++ b/tweak/Makefile@@ -17,3 +17,8 @@ spotifyglass_FRAMEWORKS := UIKit QuartzCore UniformTypeIdentifiers MediaPlayer Cspotifyglass_LOGOS_DEFAULT_GENERATOR := internalinclude $(THEOS_MAKE_PATH)/tweak.mk++# The layers of Sources/ stay apart (scripts/check-layers.sh): an import across them fails the build.+# A copy of tweak/ made without the scripts beside it builds unchecked.+before-all::+ @if [ -x ../scripts/check-layers.sh ]; then ../scripts/check-layers.sh Sources; fidiff --git a/tweak/Sources/Shared/About/About.h b/tweak/Sources/App/About/About.hsimilarity index 93%rename from tweak/Sources/Shared/About/About.hrename to tweak/Sources/App/About/About.hindex 08124ad4..2576962b 100644--- a/tweak/Sources/Shared/About/About.h+++ b/tweak/Sources/App/About/About.h@@ -4,9 +4,7 @@#import <UIKit/UIKit.h>#import "Settings/SGModPage.h"-extern NSString *const SGSiteURL;-extern NSString *const SGRepoURL;-extern NSString *const SGUpdateURL;+extern NSString *const SGUpdateURL; // the site and the repo are in Settings/SGPageStyle.hNSString *SGUpdateVersion(void); // nil unless the site has one newer than this buildNSString *SGUpdateNotes(void);NSString *SGUpdateStatus(void);diff --git a/tweak/Sources/Shared/About/AboutSettings.m b/tweak/Sources/App/About/AboutSettings.msimilarity index 100%rename from tweak/Sources/Shared/About/AboutSettings.mrename to tweak/Sources/App/About/AboutSettings.mdiff --git a/tweak/Sources/Shared/About/Backup.m b/tweak/Sources/App/About/Backup.msimilarity index 97%rename from tweak/Sources/Shared/About/Backup.mrename to tweak/Sources/App/About/Backup.mindex bc50e414..59f93dbc 100644--- a/tweak/Sources/Shared/About/Backup.m+++ b/tweak/Sources/App/About/Backup.m@@ -8,7 +8,8 @@static BOOL isSetting(NSString *key) {if (![key hasPrefix:@"spotifyglass."]) return NO;for (NSString *local in @[@"spotifyglass.adblock.counts", @"spotifyglass.privacy.counts", @"spotifyglass.update.",- @"spotifyglass.signing.", @"spotifyglass.onboarding.", @"spotifyglass.navbar.stock"]) {+ @"spotifyglass.signing.", @"spotifyglass.onboarding.", @"spotifyglass.navbar.stock",+ @"spotifyglass.redesign.navbar.stock"]) {if ([key hasPrefix:local]) return NO;}return YES;diff --git a/tweak/Sources/Shared/About/Signing.m b/tweak/Sources/App/About/Signing.msimilarity index 100%rename from tweak/Sources/Shared/About/Signing.mrename to tweak/Sources/App/About/Signing.mdiff --git a/tweak/Sources/Shared/About/Update.m b/tweak/Sources/App/About/Update.msimilarity index 97%rename from tweak/Sources/Shared/About/Update.mrename to tweak/Sources/App/About/Update.mindex 65bda615..e440cdff 100644--- a/tweak/Sources/Shared/About/Update.m+++ b/tweak/Sources/App/About/Update.m@@ -4,8 +4,6 @@#import "Core/SGCore.h"#import "About.h"-NSString *const SGSiteURL = @"https://spoti.pw";-NSString *const SGRepoURL = @"https://github.com/skopevoj/spoti.pw";NSString *const SGUpdateURL = @"https://spoti.pw/version.json";static NSString *const kChecked = @"spotifyglass.update.checked";diff --git a/tweak/Sources/App/ModSettings.x b/tweak/Sources/App/ModSettings.xindex 60dfedd0..6781e59e 100644--- a/tweak/Sources/App/ModSettings.x+++ b/tweak/Sources/App/ModSettings.x@@ -1,6 +1,6 @@// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own page: the-// Appearance card that styles the whole app, then a page per part of Spotify, each holding that-// part's glass, hide switches and flags (Navbar, Player, Home & Library), Premium, ads & privacy+// Appearance card with Redesigned UI, then a page per part of Spotify, each holding what that part+// offers in the stored look (App/Pages.m: Navbar, Player, and Home & Library for the native look), Premium, ads & privacy// and Labs, All flags, a searchable list of every flag with an override per flag, and Mod, the// build, its updates and links. The same row leads the side drawer's list (trees/test6.txt), above// Your plan, so the page is a tap from Home, and holding Home on the tab bar opens it too. The tweaks read the switches when they run, so a change@@ -15,13 +15,11 @@#import "Settings/SGPage.h"#import "Settings/SGPageStyle.h"#import "Settings/SGModPage.h"-#import "Native/Appearance/Appearance.h"-#import "Native/Navbar/Navbar.h"#import "Native/Home/Home.h"-#import "Native/Player/NowPlaying.h"#import "Shared/AdBlock/AdBlock.h"#import "Shared/Flags/Flags.h"-#import "Shared/About/About.h"+#import "App/About/About.h"+#import "Pages.h"static const CGFloat kRowHeight = 56;static char kRowKey, kInsetKey;@@ -40,13 +38,15 @@ static UIViewController *modSettingsPage(void) {if (signing) [sections addObject:SGSection(nil, @[signing])];SGModRow *mod = pageRow(@"Mod", @"info.circle", ^UIViewController *{ return SGAboutPage(); });mod.value = ^NSString *{ return @(SG_VERSION); };+ // Home & Library holds only the native look's switches, so the redesign has no such page.+ NSMutableArray<SGModRow *> *parts = [NSMutableArray arrayWithArray:@[+ pageRow(@"Navbar", @"dock.rectangle", ^UIViewController *{ return SGNavbarPage(); }),+ pageRow(@"Player", @"play.circle", ^UIViewController *{ return SGPlayerSettingsPage(); }),+ ]];+ if (!SGRedesignedUIStored()) [parts addObject:pageRow(@"Home & Library", @"house", ^UIViewController *{ return SGHomeSettingsPage(); })];[sections addObjectsFromArray:@[SGAppearanceSection(),- SGSection(nil, @[- pageRow(@"Navbar", @"dock.rectangle", ^UIViewController *{ return SGNavbarSettingsPage(); }),- pageRow(@"Player", @"play.circle", ^UIViewController *{ return SGNowPlayingSettingsPage(); }),- pageRow(@"Home & Library", @"house", ^UIViewController *{ return SGHomeSettingsPage(); }),- ]),+ SGSection(nil, parts),SGSection(nil, @[pageRow(@"Premium, ads & privacy", @"crown", ^UIViewController *{ return SGAdsSettingsPage(); }),pageRow(@"Labs", @"testtube.2", ^UIViewController *{ return SGLabsPage(); }),diff --git a/tweak/Sources/App/Onboarding/Tour.m b/tweak/Sources/App/Onboarding/Tour.mindex 91c319ce..1c8ccd50 100644--- a/tweak/Sources/App/Onboarding/Tour.m+++ b/tweak/Sources/App/Onboarding/Tour.m@@ -1,15 +1,16 @@#import "Core/SGCore.h"#import "Settings/SGPageStyle.h"#import "Onboarding.h"-#import "Shared/About/About.h"+#import "App/About/About.h"#import "Shared/AdBlock/AdBlock.h"#import "Native/Appearance/Appearance.h"#import "Shared/Flags/Flags.h"#import "Native/Home/Home.h"-#import "Native/Player/Declutter.h"+#import "Native/Player/NowPlaying.h"#import "Native/Navbar/Navbar.h"+#import "Redesigned/Navbar/Navbar.h"#import "Shared/Privacy/Privacy.h"-#import "Redesigned/Kit/SGRedesign.h"+#import "App/Pages.h"static const CGFloat kMargin = 24;static const CGFloat kCardRadius = 22;@@ -325,7 +326,7 @@ static SGTourRow *actionRow(NSString *symbol, NSString *title, NSString *subtitl// controller of its own so Add a tab has somewhere to push.- (SGTourPage *)navbarPage {SGTourPage *page = [self pageWithSymbol:@"dock.rectangle" heading:@"Your tabs." body:@"Drag to reorder, tap to hide, add any Spotify link as a tab of its own. The bar follows straight away." rows:@[]];- UIViewController *editor = SGNavbarEditorPage();+ UIViewController *editor = SGRedesignedUIStored() ? SGRNavbarEditorPage() : SGNavbarEditorPage();editor.view.backgroundColor = UIColor.clearColor;UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editor];nav.navigationBarHidden = YES;diff --git a/tweak/Sources/App/Pages.h b/tweak/Sources/App/Pages.hnew file mode 100644index 00000000..09b6ae07--- /dev/null+++ b/tweak/Sources/App/Pages.h@@ -0,0 +1,14 @@+// The pages of Mod Settings that bring the layers together: what each look offers is its own+// (Shared/, Native/, Redesigned/), and which of it a page shows is decided here, from the stored+// Redesigned UI switch, so a page opened after flipping it shows what the restart will bring.+#import <UIKit/UIKit.h>++@class SGModSection;++// Redesigned UI, the one switch between the two looks, and what its ⓘ reads out.+void SGSetRedesignedUI(BOOL on);+extern NSString *const SGRedesignedUIInfo;++SGModSection *SGAppearanceSection(void); // the Appearance card at the top of Mod Settings+UIViewController *SGPlayerSettingsPage(void);+UIViewController *SGNavbarPage(void); // the tab editor of whichever look is storeddiff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mnew file mode 100644index 00000000..0d571ffd--- /dev/null+++ b/tweak/Sources/App/Pages.m@@ -0,0 +1,66 @@+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Pages.h"+#import "Shared/ArtistBlock/ArtistBlock.h"+#import "Shared/Gestures/Gestures.h"+#import "Shared/Lyrics/Lyrics.h"+#import "Shared/Player/PlayerSettings.h"+#import "Native/Appearance/Appearance.h"+#import "Native/Navbar/Navbar.h"+#import "Native/NowPlayingBar/NowPlayingBar.h"+#import "Native/Player/NowPlaying.h"+#import "Redesigned/Navbar/Navbar.h"++NSString *const SGRedesignedUIInfo = @"Replaces Spotify's own look with the mod's redesign, built in Liquid Glass: the glass tab bar, search field and now playing bar, the full screen player with the lyrics under it, Spotify's own glass bars and sheets, and every screen redesigned later.\n\nThe redesign starts from a clean sheet: the switches that change Spotify's own screens (the player, Home, playlists, albums, artists, AMOLED and the accent colour) are put away while it is on, and none of them runs. What works the same with either look stays: ads and privacy, lyrics sources, gestures, blocked artists.\n\nChanges apply after you restart Spotify.";++void SGSetRedesignedUI(BOOL on) {+ SGSetEnabled(SGKeyRedesign, on);+}++SGModSection *SGAppearanceSection(void) {+ SGModRow *redesign = SGOptionRow(@"Redesigned UI", @"The mod's own look in Liquid Glass, from a clean sheet", SGKeyRedesign);+ redesign.glows = YES;+ redesign.info = SGRedesignedUIInfo;+ redesign.changed = ^(BOOL on) { SGSetRedesignedUI(on); };+ NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObject:SGWithSymbol(redesign, @"sparkles")];+ if (!SGRedesignedUIStored()) [rows addObjectsFromArray:SGNativeAppearanceRows()];+ return SGNotedSection(@"Appearance", rows, @"Changes apply after you restart Spotify.");+}++UIViewController *SGNavbarPage(void) {+ return SGRedesignedUIStored() ? SGRNavbarSettingsPage() : SGNavbarSettingsPage();+}++static UIViewController *lyricsPage(void) {+ NSMutableArray<SGModRow *> *look = [SGLyricsLookRows() mutableCopy];+ if (!SGRedesignedUIStored()) [look insertObject:SGGlassLyricsRow() atIndex:1];+ NSArray<SGModSection *> *sections = [@[SGSection(nil, look)] arrayByAddingObjectsFromArray:SGLyricsSourceSections()];+ return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:SGRestartNote sections:sections footer:nil];+}++UIViewController *SGPlayerSettingsPage(void) {+ SGModRow *blocked = SGPageRow(@"Blocked artists", ^UIViewController *{ return SGArtistBlockSettingsPage(); });+ blocked.value = ^NSString *{+ return SGFlag(SGKeyArtistBlock, NO) ? @(SGBlockedArtists().count).stringValue : @"Off";+ };+ BOOL native = !SGRedesignedUIStored();++ NSMutableArray<SGModSection *> *sections = [NSMutableArray arrayWithObject:SGSection(nil, @[+ SGWithSymbol(SGPageRow(@"Gestures", ^UIViewController *{ return SGGesturesSettingsPage(); }), @"hand.tap"),+ SGWithSymbol(SGPageRow(@"Lyrics", ^UIViewController *{ return lyricsPage(); }), @"quote.bubble"),+ SGWithSymbol(blocked, @"person.crop.circle.badge.xmark"),+ ])];+ NSMutableArray<SGModRow *> *pages = [NSMutableArray array];+ if (native) {+ [pages addObject:SGWithSymbol(SGPageRow(@"Now playing bar", ^UIViewController *{ return SGNowPlayingBarSettingsPage(); }), @"rectangle.bottomthird.inset.filled")];+ [pages addObject:SGWithSymbol(SGPageRow(@"Queue & devices", ^UIViewController *{ return SGQueueSettingsPage(); }), @"text.line.first.and.arrowtriangle.forward")];+ }+ [pages addObject:SGWithSymbol(SGPageRow(@"Lock screen widget", ^UIViewController *{ return SGLockScreenWidgetPage(); }), @"lock")];+ [sections addObject:SGSection(nil, pages)];+ if (native) [sections addObjectsFromArray:SGNativePlayerScreenSections()];++ return [[SGModPage alloc] initWithTitle:@"Player"+ intro:@"Changes apply after you restart Spotify. Gestures and Blocked artists apply straight away."+ sections:sections+ footer:nil];+}diff --git a/tweak/Sources/Core/SGBackdrop.h b/tweak/Sources/Core/SGBackdrop.hindex 498c3c31..2bf7c3dd 100644--- a/tweak/Sources/Core/SGBackdrop.h+++ b/tweak/Sources/Core/SGBackdrop.h@@ -1,5 +1,5 @@// The cover art as a background: shrunk until no shape of it survives, blurred, under a scrim-// darkening towards the bottom. NowPlaying/Player.x puts one behind the player, Playlist/Playlist.x+// darkening towards the bottom. Native/Player/Player.x puts one behind the player, Native/Playlist/Playlist.x// behind the playlist header.#import <UIKit/UIKit.h>diff --git a/tweak/Sources/Core/SGCore.h b/tweak/Sources/Core/SGCore.hindex 16e1f652..47cda85f 100644--- a/tweak/Sources/Core/SGCore.h+++ b/tweak/Sources/Core/SGCore.h@@ -1,8 +1,10 @@// 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.+// header under Shared/, Native/ or Redesigned/, next to the keys it reads.#import "SGRuntime.h"#import "SGLog.h"#import "SGPrefs.h"#import "SGViewTree.h"#import "SGGlass.h"#import "SGBackdrop.h"+#import "SGUIMode.h"+#import "SGFlagForce.h"diff --git a/tweak/Sources/Core/SGFlagForce.h b/tweak/Sources/Core/SGFlagForce.hnew file mode 100644index 00000000..3780048c--- /dev/null+++ b/tweak/Sources/Core/SGFlagForce.h@@ -0,0 +1,21 @@+// The flags something of the mod's forces, gathered in one place so that the flag provider+// (Shared/Flags/Flags.x) and the flag rows of the settings pages (Settings/SGModPage.m) ask here+// rather than knowing every feature that forces one: the ad blocking, the lyrics sources, the redesign.+//+// A forcer answers a flag key with the value it forces, or nil. `atLaunch` answers for the running+// app, from the switches as they were at launch; `locked`, which may be nil, answers for a settings+// row, from the switches as they are stored now, and a row it answers for shows that value and takes+// no touch. A forcer that `beatsOverride` is asked before an override from the All flags page, the+// rest after it; within each group in the order they were registered.+// Threading: register from a %ctor or a constructor, before Spotify reads a flag; ask from any thread.+#import <Foundation/Foundation.h>++typedef id (^SGFlagForcer)(NSString *key);++void SGRegisterFlagForcer(BOOL beatsOverride, SGFlagForcer atLaunch, SGFlagForcer locked);++// The value the provider hands Spotify: forcers that beat an override, the override, then the rest.+id SGForcedFlagValue(NSString *key);+// The value a settings row is locked at, nil when none; `beatsOverride` says whether an override+// from the All flags page gives way to it.+id SGLockedFlagValue(NSString *key, BOOL *beatsOverride);diff --git a/tweak/Sources/Core/SGFlagForce.m b/tweak/Sources/Core/SGFlagForce.mnew file mode 100644index 00000000..897d3f03--- /dev/null+++ b/tweak/Sources/Core/SGFlagForce.m@@ -0,0 +1,68 @@+#import <os/lock.h>+#import "SGFlagForce.h"+#import "SGPrefs.h"++@interface SGFlagForcerEntry : NSObject+@property (nonatomic) BOOL beatsOverride;+@property (nonatomic, copy) SGFlagForcer atLaunch, locked;+@end++@implementation SGFlagForcerEntry+@end++// Swapped whole under the lock, so a reader walks an immutable array.+static os_unfair_lock sg_lock = OS_UNFAIR_LOCK_INIT;+static NSArray<SGFlagForcerEntry *> *sg_forcers;++void SGRegisterFlagForcer(BOOL beatsOverride, SGFlagForcer atLaunch, SGFlagForcer locked) {+ if (!atLaunch) return;+ SGFlagForcerEntry *entry = [SGFlagForcerEntry new];+ entry.beatsOverride = beatsOverride;+ entry.atLaunch = atLaunch;+ entry.locked = locked;+ os_unfair_lock_lock(&sg_lock);+ sg_forcers = [(sg_forcers ?: @[]) arrayByAddingObject:entry];+ os_unfair_lock_unlock(&sg_lock);+}++static NSArray<SGFlagForcerEntry *> *forcers(void) {+ os_unfair_lock_lock(&sg_lock);+ NSArray *list = sg_forcers;+ os_unfair_lock_unlock(&sg_lock);+ return list;+}++id SGForcedFlagValue(NSString *key) {+ if (!key) return nil;+ NSArray<SGFlagForcerEntry *> *list = forcers();+ for (SGFlagForcerEntry *entry in list) {+ if (!entry.beatsOverride) continue;+ id value = entry.atLaunch(key);+ if (value) return value;+ }+ id value = SGFlagOverride(key);+ if (value) return value;+ for (SGFlagForcerEntry *entry in list) {+ if (entry.beatsOverride) continue;+ value = entry.atLaunch(key);+ if (value) return value;+ }+ return nil;+}++id SGLockedFlagValue(NSString *key, BOOL *beatsOverride) {+ if (beatsOverride) *beatsOverride = NO;+ if (!key) return nil;+ NSArray<SGFlagForcerEntry *> *list = forcers();+ for (int pass = 0; pass < 2; pass++) {+ BOOL first = pass == 0;+ for (SGFlagForcerEntry *entry in list) {+ if (entry.beatsOverride != first || !entry.locked) continue;+ id value = entry.locked(key);+ if (!value) continue;+ if (beatsOverride) *beatsOverride = first;+ return value;+ }+ }+ return nil;+}diff --git a/tweak/Sources/Core/SGGlass.h b/tweak/Sources/Core/SGGlass.hindex c1ebee35..06a6d001 100644--- a/tweak/Sources/Core/SGGlass.h+++ b/tweak/Sources/Core/SGGlass.h@@ -10,18 +10,5 @@ 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);+// The areas each look keeps transparent are its own: Native/Appearance/Repaint.h and+// Redesigned/Kit/SGRRepaint.h.diff --git a/tweak/Sources/Core/SGGlass.m b/tweak/Sources/Core/SGGlass.mindex 5023d9bf..39096964 100644--- a/tweak/Sources/Core/SGGlass.m+++ b/tweak/Sources/Core/SGGlass.m@@ -1,25 +1,6 @@#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.diff --git a/tweak/Sources/Core/SGPrefs.h b/tweak/Sources/Core/SGPrefs.hindex 5e76e146..f0e2f8a1 100644--- a/tweak/Sources/Core/SGPrefs.h+++ b/tweak/Sources/Core/SGPrefs.h@@ -19,7 +19,7 @@ NSInteger SGInt(NSString *key, NSInteger fallback);void SGSetInt(NSString *key, NSInteger value);// 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.+// nil keeps Spotify's value. Shared/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/SGUIMode.h b/tweak/Sources/Core/SGUIMode.hnew file mode 100644index 00000000..94a5a938--- /dev/null+++ b/tweak/Sources/Core/SGUIMode.h@@ -0,0 +1,18 @@+// Which of the two looks runs: Spotify's own screens with the mod's tweaks on them (Native/), or the+// redesign (Redesigned/), picked by Redesigned UI in Appearance. What does not draw on Spotify's+// screens (Shared/) runs under both. The switch is read once, the first time anything asks, so the+// hooks, the flags and the pages see one answer for the whole launch and a change waits for the restart.+//+// Every hook file of Native/ starts its %ctor with `if (!SGNativeUI()) return;`, every one of+// Redesigned/ with `if (!SGRedesignedUI()) return;`: the two never run together, which is what lets+// each hook the same Spotify class in its own way.+// Threading: safe from any thread.+#import <Foundation/Foundation.h>++#define SGKeyRedesign @"spotifyglass.redesign"++BOOL SGRedesignedUI(void);+BOOL SGNativeUI(void);+// The stored switch rather than the launch's, for settings pages opened after it was flipped: they+// show what the restart will bring.+BOOL SGRedesignedUIStored(void);diff --git a/tweak/Sources/Core/SGUIMode.m b/tweak/Sources/Core/SGUIMode.mnew file mode 100644index 00000000..9450ea76--- /dev/null+++ b/tweak/Sources/Core/SGUIMode.m@@ -0,0 +1,21 @@+#import "SGUIMode.h"+#import "SGLog.h"+#import "SGPrefs.h"++BOOL SGRedesignedUI(void) {+ static BOOL on;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ on = SGFlag(SGKeyRedesign, NO);+ SGLog(@"ui: %@", on ? @"redesigned" : @"native");+ });+ return on;+}++BOOL SGNativeUI(void) {+ return !SGRedesignedUI();+}++BOOL SGRedesignedUIStored(void) {+ return SGFlag(SGKeyRedesign, NO);+}diff --git a/tweak/Sources/Core/SGViewTree.m b/tweak/Sources/Core/SGViewTree.mindex e21ac337..eb57b47b 100644--- a/tweak/Sources/Core/SGViewTree.m+++ b/tweak/Sources/Core/SGViewTree.m@@ -40,8 +40,9 @@ BOOL SGKeepsColor(UIView *view) {void SGStripBackgrounds(UIView *view) {if ([view isKindOfClass:UIVisualEffectView.class]) return;- // The karaoke view paints nothing to strip and holds a label for every word in sight.- if ([NSStringFromClass(view.class) hasPrefix:@"SGKaraoke"]) return;+ // The karaoke views paint nothing to strip and hold a label for every word in sight.+ NSString *name = NSStringFromClass(view.class);+ if ([name hasPrefix:@"SGKaraoke"] || [name hasPrefix:@"SGRKaraoke"]) 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) {diff --git a/tweak/Sources/Diagnostics/Diagnostics.x b/tweak/Sources/Diagnostics/Diagnostics.xindex dd1fde45..d244d32e 100644--- a/tweak/Sources/Diagnostics/Diagnostics.x+++ b/tweak/Sources/Diagnostics/Diagnostics.x@@ -63,7 +63,7 @@ static void appendModState(NSMutableString *out) {NSDictionary *stored = [NSUserDefaults.standardUserDefaults persistentDomainForName:NSBundle.mainBundle.bundleIdentifier] ?: @{};[out appendFormat:@"== mod\nstock %@\n", [stored[SGKeyStock] boolValue] ? @"yes" : @"no"];NSArray<NSString *> *local = @[@"spotifyglass.adblock.counts", @"spotifyglass.privacy.counts", @"spotifyglass.update.",- @"spotifyglass.signing.", @"spotifyglass.onboarding.", @"spotifyglass.navbar.stock",+ @"spotifyglass.signing.", @"spotifyglass.onboarding.", @"spotifyglass.navbar.stock", @"spotifyglass.redesign.navbar.stock",@"spotifyglass.musixmatch.token"];for (NSString *key in [stored.allKeys sortedArrayUsingSelector:@selector(compare:)]) {if (![key hasPrefix:@"spotifyglass."] || [key isEqualToString:SGKeyStock]) continue;diff --git a/tweak/Sources/Native/Album/Album.x b/tweak/Sources/Native/Album/Album.xindex fa804798..53bcf17c 100644--- a/tweak/Sources/Native/Album/Album.x+++ b/tweak/Sources/Native/Album/Album.x@@ -190,6 +190,7 @@ static BOOL collapsed(UICollectionViewCell *cell, NSIndexPath *path) {%end%ctor {+ if (!SGNativeUI()) return;%init;SGRequireClasses(@[@"_TtC28CreativeWorkPlatform_PageKit24CreativeWorkTemplateView",diff --git a/tweak/Sources/Native/Appearance/Accent.x b/tweak/Sources/Native/Appearance/Accent.xindex fa788dc3..335714f7 100644--- a/tweak/Sources/Native/Appearance/Accent.x+++ b/tweak/Sources/Native/Appearance/Accent.x@@ -165,6 +165,7 @@ static id swappedValue(id value) {%end%ctor {+ if (!SGNativeUI()) return;sg_accent = chosen();if (sg_accent >= 0) %init;}diff --git a/tweak/Sources/Native/Appearance/Amoled.x b/tweak/Sources/Native/Appearance/Amoled.xindex 0f4d9bb4..bd1296b3 100644--- a/tweak/Sources/Native/Appearance/Amoled.x+++ b/tweak/Sources/Native/Appearance/Amoled.x@@ -63,7 +63,7 @@ static CGColorRef copyBlack(CGColorRef color) {%end%ctor {- if (SGFlag(SGKeyAmoled, NO)) {+ if (SGNativeUI() && SGFlag(SGKeyAmoled, NO)) {%init;}}diff --git a/tweak/Sources/Native/Appearance/Appearance.h b/tweak/Sources/Native/Appearance/Appearance.hindex 3a84be5e..0ba3fdf0 100644--- a/tweak/Sources/Native/Appearance/Appearance.h+++ b/tweak/Sources/Native/Appearance/Appearance.h@@ -1,23 +1,14 @@-// Appearance: the AMOLED background (Amoled.x), the glass search field (SearchField.x), the-// accent colour in place of Spotify's green (Accent.x) and Repaint.x, which keeps what the other-// features stripped transparent when Spotify repaints it. The switches are off until asked for,-// as are the tab bar's and Spotify's own glass.+// The native look's appearance: the AMOLED background (Amoled.x), the accent colour in place of+// Spotify's green (Accent.x), the soft top edge (EdgeEffect.x) and Repaint.x, which keeps what the+// native tweaks stripped transparent when Spotify repaints it. The switches are off until asked for.#import <UIKit/UIKit.h>#define SGKeyAmoled @"spotifyglass.amoled"-#define SGKeySearchField @"spotifyglass.searchField"#define SGKeyAccent @"spotifyglass.accent" // 0xRRGGBB; unset or negative keeps Spotify's own greenUIColor *SGAccentColor(void); // nil while Spotify's own green is keptNSString *SGAccentLabel(void); // "#RRGGBB", or the name of Spotify's ownvoid SGPickAccent(void); // the system colour picker over the top of the app, stored on the way out-// Redesigned UI, the one switch of Appearance that sets others: the redesigned screens-// (Redesign/Kit/SGRedesign.h), Spotify's own glass and, with it, the tab bar, the search field, the now-// playing bar, the artwork background and the lyrics card. Each glass switch stays a switch of its own-// afterwards, on the page of the part it styles. SGRedesignedUIInfo is what its ⓘ reads out.-void SGSetRedesignedUI(BOOL on);-extern NSString *const SGRedesignedUIInfo;--@class SGModSection;-SGModSection *SGAppearanceSection(void); // the Appearance card at the top of Mod Settings+@class SGModRow;+NSArray<SGModRow *> *SGNativeAppearanceRows(void); // AMOLED and the accent colour, for the Appearance carddiff --git a/tweak/Sources/Native/Appearance/AppearanceSettings.m b/tweak/Sources/Native/Appearance/AppearanceSettings.mindex 4762abdd..2df5344c 100644--- a/tweak/Sources/Native/Appearance/AppearanceSettings.m+++ b/tweak/Sources/Native/Appearance/AppearanceSettings.m@@ -2,18 +2,6 @@#import "Settings/SGModPage.h"#import "Settings/SGPageStyle.h"#import "Appearance.h"-#import "Native/Navbar/Navbar.h"-#import "Shared/Flags/Flags.h"-#import "Native/Player/NowPlaying.h"-#import "Redesigned/Kit/SGRedesign.h"--NSString *const SGRedesignedUIInfo = @"Replaces Spotify's own screens with the mod's redesign, built in Liquid Glass: for now the full screen player with the lyrics under it, and every screen redesigned later joins it here. It also turns on Spotify's own glass bars, slider and sheets, and the mod's glass tab bar, search field and now playing bar.\n\nWhile it is on, the switches that change Spotify's own version of a redesigned screen are put away on that screen's page, since the screen is no longer Spotify's. Off, Spotify looks the way it does with the switches you set.\n\nChanges apply after you restart Spotify.";--void SGSetRedesignedUI(BOOL on) {- for (NSString *key in @[SGKeyRedesign, SGKeySpotifyGlass, SGKeyTabBar, SGKeySearchField, SGKeyNowPlayingBar, SGKeyPlayer, SGKeyPlayerBackdrop, SGKeyLyricsCard]) {- SGSetEnabled(key, on);- }-}// Going back to Spotify's green is offered only once a colour of the mod's is set, so a stray tap// cannot wipe it.@@ -33,14 +21,10 @@ static void chooseAccent(void) {[top presentViewController:sheet animated:YES completion:nil];}-SGModSection *SGAppearanceSection(void) {- SGModRow *redesign = SGOptionRow(@"Redesigned UI", @"The mod's own screens in Liquid Glass, and every glass switch with them", SGKeyRedesign);- redesign.glows = YES;- redesign.info = SGRedesignedUIInfo;- redesign.changed = ^(BOOL on) { SGSetRedesignedUI(on); };- return SGNotedSection(@"Appearance", @[- SGWithSymbol(redesign, @"sparkles"),+// The native look's rows of the Appearance card (App/Pages.m).+NSArray<SGModRow *> *SGNativeAppearanceRows(void) {+ return @[SGWithSymbol(SGOptionRow(@"AMOLED background", nil, SGKeyAmoled), @"moon"),SGWithSymbol(SGStatActionRow(@"Accent colour", nil, ^NSString *{ return SGAccentLabel(); }, ^{ chooseAccent(); }), @"paintpalette"),- ], @"Redesigned UI turns every glass switch of the mod's on or off with it. Changes apply after you restart Spotify.");+ ];}diff --git a/tweak/Sources/Native/Appearance/EdgeEffect.x b/tweak/Sources/Native/Appearance/EdgeEffect.xindex 053ef9b4..4232a265 100644--- a/tweak/Sources/Native/Appearance/EdgeEffect.x+++ b/tweak/Sources/Native/Appearance/EdgeEffect.x@@ -30,3 +30,8 @@ static void soften(UIScrollView *scrollView) {if (self.window) soften(self);}%end++%ctor {+ if (!SGNativeUI()) return;+ %init;+}diff --git a/tweak/Sources/Native/Appearance/Repaint.h b/tweak/Sources/Native/Appearance/Repaint.hnew file mode 100644index 00000000..cfc1be19--- /dev/null+++ b/tweak/Sources/Native/Appearance/Repaint.h@@ -0,0 +1,8 @@+// The areas the native look's tweaks stripped and Repaint.x keeps transparent when Spotify repaints+// them, each set by the tweak that owns it.+#import <UIKit/UIKit.h>++extern __weak UIView *sg_lyricsCardRoot; // Native/Player/LyricsCard.x+extern __weak UIView *sg_lyricsPageRoot; // Native/Lyrics/LyricsPage.x+extern __weak UIView *sg_homeRoot; // Native/Home/HomeGradient.x, the base surface only+extern __weak UIView *sg_npvBackdropRoot; // Native/Player/Player.x, the plane behind the playerdiff --git a/tweak/Sources/Native/Appearance/Repaint.x b/tweak/Sources/Native/Appearance/Repaint.xindex bbb8c205..605456d0 100644--- a/tweak/Sources/Native/Appearance/Repaint.x+++ b/tweak/Sources/Native/Appearance/Repaint.x@@ -1,31 +1,25 @@-// 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.+// Keeps the areas the native look's tweaks stripped transparent when Spotify repaints them.#import "Core/SGCore.h"-#import "Appearance.h"+#import "Repaint.h"++__weak UIView *sg_lyricsCardRoot = nil;+__weak UIView *sg_lyricsPageRoot = nil;+__weak UIView *sg_homeRoot = nil;+__weak UIView *sg_npvBackdropRoot = nil;%hook CALayer- (void)setBackgroundColor:(CGColorRef)color {- if (color && (sg_nowPlayingRoot || sg_tabBarRoot || sg_lyricsCardRoot || sg_lyricsPageRoot || sg_homeRoot || sg_npvBackdropRoot)) {+ if (color && (sg_lyricsCardRoot || sg_lyricsPageRoot || sg_homeRoot || sg_npvBackdropRoot)) {UIView *view = (UIView *)self.delegate;if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {- if (SGIsInside(view, sg_nowPlayingRoot)) {- if (SGLooksLikeCard(view, color) && sg_nowPlayingCard != view) {- sg_nowPlayingCard = view;- UIView *bar = sg_nowPlayingRoot;- dispatch_async(dispatch_get_main_queue(), ^{ [bar.superview setNeedsLayout]; });- }- if (view == sg_nowPlayingCard) SGRememberCardColor(color);- // While the full screen player animates, the bar is Spotify's own again.- if (!sg_nowPlayingStock) color = NULL;- } else if (SGIsInside(view, sg_tabBarRoot) || SGIsInside(view, sg_lyricsCardRoot)- || SGIsInside(view, sg_lyricsPageRoot)) {+ if (SGIsInside(view, sg_lyricsCardRoot) || SGIsInside(view, sg_lyricsPageRoot)) {color = NULL;} else if (SGIsInside(view, sg_npvBackdropRoot)) {// The album colour arrives on the plane per track, outside any layout pass.color = NULL;} else if (SGIsBaseSurface(color) && SGIsInside(view, sg_homeRoot)) {// Home keeps its cards and its placeholders; only the base surface the gradient- // of Home/HomeGradient.x sits behind goes.+ // of Native/Home/HomeGradient.x sits behind goes.color = NULL;}}@@ -35,5 +29,6 @@%end%ctor {+ if (!SGNativeUI()) return;%init;}diff --git a/tweak/Sources/Native/Artist/Artist.x b/tweak/Sources/Native/Artist/Artist.xindex aa9af478..0b3974cd 100644--- a/tweak/Sources/Native/Artist/Artist.x+++ b/tweak/Sources/Native/Artist/Artist.x@@ -329,6 +329,7 @@ static BOOL collapsed(UICollectionViewCell *cell, NSIndexPath *path) {%end%ctor {+ if (!SGNativeUI()) return;%init;SGRequireClasses(@[@"_TtC35CreativeWorkPlatform_ImageHeaderKit15ImageHeaderView",diff --git a/tweak/Sources/Native/Home/Home.h b/tweak/Sources/Native/Home/Home.hindex 3487a977..9fad65ad 100644--- a/tweak/Sources/Native/Home/Home.h+++ b/tweak/Sources/Native/Home/Home.h@@ -4,6 +4,13 @@#define SGKeyHomeGradient @"spotifyglass.homeGradient"+// Parts of Home to hide, one switch each (HomeDeclutter.x). An unset switch is off.+#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"+// Every setting the gradient is shaped by. One entry per setting in HomeGradientChoices.m holds the// names the Gradient page offers, the key it is stored under and the one it falls back to, so a// name and what it does cannot drift apart.diff --git a/tweak/Sources/Native/Home/HomeDeclutter.x b/tweak/Sources/Native/Home/HomeDeclutter.xnew file mode 100644index 00000000..470ee274--- /dev/null+++ b/tweak/Sources/Native/Home/HomeDeclutter.x@@ -0,0 +1,70 @@+// Home declutter: sections of Home collapsed and the filter pills hidden, one switch each on the Home &+// Library page. A section is an Element_List cell; a hidden one reports zero height when the list sizes+// it, so the list closes up around it.+//+// Trees (trees/home*.txt): every section is a CollectionViewCell whose content view names the page+// (Home_EvoPageImpl) and whose subtree names the section.+#import "Core/SGCore.h"+#import "Home.h"++static const struct { __unsafe_unretained NSString *marker, *key; } sections[] = {+ {@"Home_AnchorsAndShortcutsKit", SGHideHomeShortcuts},+ {@"Discovery_PromoElement", SGHideHomePromo},+ {@"Discovery_PreviewElement", SGHideHomePreviews},+ {@"Discovery_DJElement", SGHideHomeDJ},+};++// Class names of everything in the cell. Lists nested in the cell are laid out first so the+// cells that name the section (shortcut tiles) exist.+static NSString *classNamesIn(UIView *cell) {+ NSMutableString *names = [NSMutableString string];+ SGForEachView(cell, ^(UIView *v) {+ if (v != cell && [v isKindOfClass:UICollectionView.class]) [v layoutIfNeeded];+ [names appendString:NSStringFromClass(v.class)];+ [names appendString:@"\n"];+ });+ return names;+}++static NSString *hiddenKeyFor(UICollectionViewCell *cell) {+ // A cell inside another section's list: the outer section decides.+ for (UIView *v = cell.superview; v; v = v.superview) {+ if ([v isKindOfClass:cell.class]) return nil;+ }+ NSString *names = nil;+ for (size_t i = 0; i < sizeof(sections) / sizeof(sections[0]); i++) {+ if (!SGHidden(sections[i].key)) continue;+ if (!names) names = classNamesIn(cell);+ if ([names containsString:@"Home_EvoPageImpl"] && [names containsString:sections[i].marker]) return sections[i].key;+ }+ return nil;+}++%hook _TtC12Element_List18CollectionViewCell+- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)attributes {+ UICollectionViewLayoutAttributes *result = %orig;+ NSString *key = hiddenKeyFor((UICollectionViewCell *)self);+ if (!key) return result;+ result.size = CGSizeMake(result.size.width, 0);+ ((UIView *)self).clipsToBounds = YES;+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"home: collapsed the first section, %@", key); });+ return result;+}+%end++%hook _TtC14Home_PillUIKit14PillScrollView+- (void)didMoveToWindow {+ %orig;+ if (SGHidden(SGHideHomePills)) ((UIView *)self).hidden = YES;+}+%end++%ctor {+ if (!SGNativeUI()) return;+ %init;+ SGRequireClasses(@[+ @"_TtC12Element_List18CollectionViewCell",+ @"_TtC14Home_PillUIKit14PillScrollView",+ ]);+}diff --git a/tweak/Sources/Native/Home/HomeGradient.x b/tweak/Sources/Native/Home/HomeGradient.xindex 63a255c1..0862549c 100644--- a/tweak/Sources/Native/Home/HomeGradient.x+++ b/tweak/Sources/Native/Home/HomeGradient.x@@ -1,7 +1,7 @@// Home gradient: a 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 Appearance/Repaint.x, and+// base grey the page and the shelves paint over it goes clear in Native/Appearance/Repaint.x, and// Spotify's own scrim behind the header goes with it, since it would only mute the colour.//// Which colour it fades, how strong it is and how far down it reaches come from the choice tables@@ -15,6 +15,7 @@// top for the header, painted #121212; the shelves inside it are collection views of their own,// painted #121212 as well.#import "Core/SGCore.h"+#import "Native/Appearance/Repaint.h"#import "Home.h"// Colour level behind the header before it starts to go, and colour above the content as well, for@@ -90,7 +91,7 @@ static uint32_t strengthened(uint32_t rgb, CGFloat factor) {@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 Appearance/Repaint.x cannot+// the wash. A cell paints itself before the page puts it in, where the hook in Native/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) {@@ -175,7 +176,7 @@ static UIScrollView *pageList(UIView *view) {%end%ctor {- if (!SGFlag(SGKeyHomeGradient, NO)) return;+ if (!SGNativeUI() || !SGFlag(SGKeyHomeGradient, NO)) return;%init;SGRequireClasses(@[@"_TtC16Home_EvoPageImpl33EvoLoadableResourceViewController",diff --git a/tweak/Sources/Native/Home/HomeSettings.m b/tweak/Sources/Native/Home/HomeSettings.mindex 35e00f1d..a5a8ff08 100644--- a/tweak/Sources/Native/Home/HomeSettings.m+++ b/tweak/Sources/Native/Home/HomeSettings.m@@ -1,7 +1,6 @@#import "Core/SGCore.h"#import "Settings/SGModPage.h"#import "Home.h"-#import "Native/Player/Declutter.h"#import "Native/Playlist/Playlist.h"#import "Native/Artist/Artist.h"#import "Native/Album/Album.h"diff --git a/tweak/Sources/Native/Lyrics/KaraokePage.x b/tweak/Sources/Native/Lyrics/KaraokePage.xindex 455961c8..135d19df 100644--- a/tweak/Sources/Native/Lyrics/KaraokePage.x+++ b/tweak/Sources/Native/Lyrics/KaraokePage.x@@ -3,7 +3,7 @@// header, close button and controls stay working. It is laid over rather than swapped in: Spotify's// list keeps running underneath and comes back the moment a track has no synced lyrics.#import "Core/SGCore.h"-#import "Shared/Lyrics/Lyrics.h"+#import "Native/Lyrics/KaraokeView.h"static char kKaraokeKey;@@ -25,7 +25,7 @@ static char kKaraokeKey;%end%ctor {- if (!SGFlag(SGKeyKaraokeLyrics, NO)) return;+ if (!SGNativeUI() || !SGFlag(SGKeyKaraokeLyrics, NO)) return;%init;SGRequireClasses(@[@"_TtC32Lyrics_FullscreenElementPageImpl10LyricsView"]);}diff --git a/tweak/Sources/Native/Lyrics/KaraokeView.h b/tweak/Sources/Native/Lyrics/KaraokeView.hnew file mode 100644index 00000000..e764c205--- /dev/null+++ b/tweak/Sources/Native/Lyrics/KaraokeView.h@@ -0,0 +1,13 @@+// The native look's Apple Music style lyrics view, over Spotify's full screen lyrics page+// (KaraokePage.x) and, compact, over the card under the player (Native/Player/KaraokeCard.x). The+// lines and the clock are Shared/Lyrics/Lyrics.h's.+#import <UIKit/UIKit.h>+#import "Shared/Lyrics/Lyrics.h"++@interface SGKaraokeView : UIView+// Compact is the card under the player: Spotify's own type size, no seeking by tap and no margin of+// its own, since the card already insets what it holds. initWithFrame: is the full screen page.+- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact;+// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.+- (void)syncSiblings;+@enddiff --git a/tweak/Sources/Native/Lyrics/KaraokeView.m b/tweak/Sources/Native/Lyrics/KaraokeView.mindex 5670aff4..0f4f88ed 100644--- a/tweak/Sources/Native/Lyrics/KaraokeView.m+++ b/tweak/Sources/Native/Lyrics/KaraokeView.m@@ -1,7 +1,7 @@#import "Core/SGCore.h"-#import "Shared/Lyrics/Lyrics.h"+#import "Native/Lyrics/KaraokeView.h"#import "Shared/LyricsSources/LyricsSources.h"-#import "Native/Player/NowPlaying.h"+#import "Shared/Player/PlayerEvents.h"static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;// The card under the player is a seventh of the page's height, so it gets Spotify's own card typediff --git a/tweak/Sources/Native/Lyrics/LyricsPage.x b/tweak/Sources/Native/Lyrics/LyricsPage.xnew file mode 100644index 00000000..19dfbd93--- /dev/null+++ b/tweak/Sources/Native/Lyrics/LyricsPage.x@@ -0,0 +1,60 @@+// The full screen lyrics page on glass ("Glass lyrics" on the Lyrics page): the card under the player+// reads as having grown to the screen (Native/Player/LyricsCard.x).+//+// Page (trees/lyrics.txt): a page of its own, presented over the player by a+// _UIOverFullscreenPresentationController, which is why the card's glass stops at the card's edge.+// Tome_PageTemplateImpl paints the template view #121212 and FullscreenView paints itself the+// album colour on top, both opaque; clearing them lets the player's blurred artwork through.+//+// The album colour is the stubborn one: it arrives per track, after the page has laid out, and it+// comes back through a path Native/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 "Core/SGCore.h"+#import "Native/Player/NowPlaying.h"+#import "Native/Appearance/Repaint.h"++static char kPageGlassKey;++// Up to the presentation: the template views in between paint themselves opaque once, at setup.+// Only the chain is cleared, not the subtree -- nothing else on the page is painted.+static UIView *clearAncestors(UIView *view) {+ UIView *top = view;+ for (UIView *v = view; v && ![v isKindOfClass:UIWindow.class]+ && ![NSStringFromClass(v.class) hasPrefix:@"UITransition"]; v = v.superview) {+ v.layer.backgroundColor = NULL;+ top = v;+ }+ return top;+}++%hook _TtC32Lyrics_FullscreenElementPageImpl14FullscreenView+// A colour kept here is re-applied whenever UIKit feels like it, so it is refused outright.+- (void)setBackgroundColor:(UIColor *)color {+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"lyrics page paints itself %@ through UIView", color); });+ %orig(SGFlag(SGKeyLyricsCard, NO) ? nil : color);+}++- (void)layoutSubviews {+ %orig;+ if (!SGFlag(SGKeyLyricsCard, NO)) return;+ UIView *page = (UIView *)self;+ if (page.bounds.size.height < 200) return;++ page.layer.backgroundColor = NULL;+ sg_lyricsPageRoot = clearAncestors(page);++ UIVisualEffectView *glass = SGGlassFor(page, &kPageGlassKey);+ glass.frame = page.bounds;+ glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ // Full bleed, so the shape is spelled out: a fresh pane does not promise square corners.+ SGShapeGlass(glass, 0, NO);+}+%end++%ctor {+ if (!SGNativeUI()) return;+ %init;+ SGRequireClasses(@[@"_TtC32Lyrics_FullscreenElementPageImpl14FullscreenView"]);+}diff --git a/tweak/Sources/Native/Navbar/Navbar.h b/tweak/Sources/Native/Navbar/Navbar.hindex 07377ab5..3491c4dd 100644--- a/tweak/Sources/Native/Navbar/Navbar.h+++ b/tweak/Sources/Native/Navbar/Navbar.h@@ -1,9 +1,8 @@-// 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+// The native look's navbar: Spotify's own tab bar composed (Navbar.x, hooked from TabBarHooks.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@@ -17,11 +16,11 @@ void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);NSArray<NSString *> *SGNavbarStock(void);void SGSetNavbarStock(NSArray<NSString *> *stock);-// Navbar.x, called from the tab bar's layout passes in TabBar.x.+// Navbar.x, called from the tab bar's layout passes in TabBarHooks.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); // the glass switches of the bar, then the tab editor+UIViewController *SGNavbarSettingsPage(void); // the tab editor, in Mod SettingsUIViewController *SGNavbarEditorPage(void); // the tab editor alone, for the welcome tourdiff --git a/tweak/Sources/Native/Navbar/Navbar.x b/tweak/Sources/Native/Navbar/Navbar.xindex 96f97f2a..5346e2e6 100644--- a/tweak/Sources/Native/Navbar/Navbar.x+++ b/tweak/Sources/Native/Navbar/Navbar.x@@ -16,7 +16,7 @@#import "Core/SGCore.h"#import "Navbar.h"#import "Headers/SPTEncoreIconView.h"-#import "Redesigned/Kit/SGRBridges.h"+#import "Shared/Navigation/Links.h"#import <objc/message.h>static const CGFloat kIconSize = 24;@@ -25,9 +25,8 @@ 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. 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.+// Where Spotify's own items keep their icon and label, read off one of them every pass, so an item of+// the mod's own sits on the same line as its neighbours.static CGRect sg_iconBox = {{0, kIconTop}, {kIconSize, kIconSize}};static CGRect sg_labelBox = {{0, kLabelTop}, {0, kLabelHeight}};@@ -102,12 +101,11 @@ static UIView *iconView(NSString *name) {[self addSubview:_icon];}-// 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.+// Both boxes come off a neighbour, so whatever Spotify 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];CGFloat width = self.bounds.size.width;- _title.hidden = SGFlag(SGKeyTabBar, NO);_title.font = sg_tabFont ?: [UIFont systemFontOfSize:10];_title.frame = CGRectMake(0, CGRectGetMinY(sg_labelBox), width, CGRectGetHeight(sg_labelBox));_icon.frame = CGRectMake((width - CGRectGetWidth(sg_iconBox)) / 2, CGRectGetMinY(sg_iconBox),@@ -125,10 +123,10 @@ static UIView *iconView(NSString *name) {self.alpha = highlighted ? 0.5 : 1;}-// Through the link dispatcher the Kit keeps (Redesign/Kit/SGRBridges.x).+// Through the app's own link dispatcher (Shared/Navigation/Links.h).- (void)open {NSURL *url = self.uri.length ? [NSURL URLWithString:self.uri] : nil;- if (!SGROpenURI(url)) SGLog(@"navbar: cannot open %@, dispatcher %@", self.uri, SGRLinkDispatcher());+ if (!SGOpenSpotifyURI(url)) SGLog(@"navbar: cannot open %@, dispatcher %@", self.uri, SGLinkDispatcher());}@end@@ -363,6 +361,7 @@ void SGLogTabBarRow(UIView *tabBar) {%end%ctor {+ if (!SGNativeUI()) return;%init;SGRequireClasses(@[@"SPTEncoreIcon",diff --git a/tweak/Sources/Native/Navbar/NavbarSettings.m b/tweak/Sources/Native/Navbar/NavbarSettings.mindex 84f5355e..55ba04db 100644--- a/tweak/Sources/Native/Navbar/NavbarSettings.m+++ b/tweak/Sources/Native/Navbar/NavbarSettings.m@@ -2,7 +2,6 @@#import "Settings/SGPage.h"#import "Settings/SGPageStyle.h"#import "Navbar.h"-#import "Native/Appearance/Appearance.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.@@ -154,7 +153,6 @@ static void appendTab(NSDictionary *tab) {@endtypedef NS_ENUM(NSInteger, SGNavbarSection) {- SGNavbarSectionGlass,SGNavbarSectionSwitch,SGNavbarSectionTabs,SGNavbarSectionAdd,@@ -162,30 +160,20 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {SGNavbarSectionCount,};-static NSArray<NSArray<NSString *> *> *glassRows(void) {- return @[- @[@"Glass tab bar", SGKeyTabBar],- @[@"Glass search field", SGKeySearchField],- ];-}-// 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. In Mod Settings the glass-// switches of the bar sit above them; the welcome tour embeds the editor without.+// your own away. Spotify's own tabs can only be hidden, never removed. Mod Settings and the welcome+// tour show the same editor.@interface SGNavbarPage : SGPage-- (instancetype)initWithGlass:(BOOL)glass;@end@implementation SGNavbarPage {NSMutableArray<NSMutableDictionary *> *_entries;UIView *_intro;- BOOL _glass;}-- (instancetype)initWithGlass:(BOOL)glass {+- (instancetype)init {if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;self.title = @"Navbar";- _glass = glass;return self;}@@ -193,8 +181,7 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {[super viewDidLoad];self.tableView.allowsSelectionDuringEditing = YES;self.tableView.editing = YES;- _intro = SGNote(_glass ? @"Drag a tab by the handle to move it, tap it to show or hide it. The bar follows straight away; the glass switches apply after you restart Spotify."- : @"Drag a tab by the handle to move it, tap it to show or hide it. The bar follows straight away.");+ _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();}@@ -226,15 +213,11 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {}- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- if (section == SGNavbarSectionGlass) return _glass ? (NSInteger)glassRows().count : 0;return section == SGNavbarSectionTabs ? (NSInteger)_entries.count : 1;}- (NSString *)headerFor:(NSInteger)section {- if (section == SGNavbarSectionGlass && _glass) return @"Liquid Glass";- if (section == SGNavbarSectionSwitch && _glass) return @"Tabs";- if (section == SGNavbarSectionTabs && !_glass) return @"Tabs";- return nil;+ return section == SGNavbarSectionTabs ? @"Tabs" : nil;}- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {@@ -254,17 +237,6 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {UITableViewCell *cell = SGDequeueCell(table, @"navbar");switch (path.section) {- case SGNavbarSectionGlass: {- NSArray<NSString *> *row = glassRows()[(NSUInteger)path.row];- SGFillCell(cell, row[0], nil, nil, nil);- UISwitch *toggle = [UISwitch new];- toggle.onTintColor = SGGreen();- toggle.on = SGFlag(row[1], NO);- toggle.tag = path.row;- [toggle addTarget:self action:@selector(glassToggled:) forControlEvents:UIControlEventValueChanged];- cell.accessoryView = toggle;- break;- }case SGNavbarSectionSwitch: {SGFillCell(cell, @"Custom navbar", nil, nil, nil);UISwitch *toggle = [UISwitch new];@@ -345,10 +317,6 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {SGRefreshTabBar();}-- (void)glassToggled:(UISwitch *)toggle {- SGSetEnabled(glassRows()[(NSUInteger)toggle.tag][1], toggle.on);-}-- (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."@@ -366,9 +334,9 @@ static NSArray<NSArray<NSString *> *> *glassRows(void) {@endUIViewController *SGNavbarSettingsPage(void) {- return [[SGNavbarPage alloc] initWithGlass:YES];+ return [SGNavbarPage new];}UIViewController *SGNavbarEditorPage(void) {- return [[SGNavbarPage alloc] initWithGlass:NO];+ return [SGNavbarPage new];}diff --git a/tweak/Sources/Native/Navbar/TabBarHooks.x b/tweak/Sources/Native/Navbar/TabBarHooks.xnew file mode 100644index 00000000..98843cd3--- /dev/null+++ b/tweak/Sources/Native/Navbar/TabBarHooks.x@@ -0,0 +1,75 @@+// What drives the native look's navbar: Spotify's tab bar composed on its layout passes (Navbar.x), and+// holding Home opens Mod Settings.+//+// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView of+// ElementContentView<TabBarItemElement>, each with an SPTEncoreIconView and an SPTEncoreLabel.+#import "Core/SGCore.h"+#import "Navbar.h"+#import "Settings/SGPage.h"++@interface SGHomeHold : UILongPressGestureRecognizer+@end++@implementation SGHomeHold++ (void)held:(SGHomeHold *)hold {+ if (hold.state == UIGestureRecognizerStateBegan) SGOpenModSettings(hold.view);+}+@end++// On Spotify's own bar a hold that begins fails the item's tap recognizer, so Home is not tapped too.+static void holdHome(UIView *stockBar) {+ UIView *home = SGRowIn(stockBar).arrangedSubviews.firstObject;+ if (!home) return;+ for (UIGestureRecognizer *recognizer in home.gestureRecognizers) {+ if ([recognizer isKindOfClass:SGHomeHold.class]) return;+ }+ [home addGestureRecognizer:[[SGHomeHold alloc] initWithTarget:SGHomeHold.class action:@selector(held:)]];+}++static UIView *tabBarOf(UIView *item) {+ Class barClass = NSClassFromString(@"_TtC23NavigationUI_TabBarImpl10TabBarView");+ for (UIView *v = item.superview; v; v = v.superview) if ([v isKindOfClass:barClass]) return v;+ return nil;+}++%hook _TtC23NavigationUI_TabBarImpl10TabBarView+- (void)layoutSubviews {+ %orig;+ SGComposeTabBar((UIView *)self);+ holdHome((UIView *)self);+ SGLogTabBarRow((UIView *)self);+}+%end++// The bar's own pass runs before Spotify has filled the row; the items lay out as they arrive.+static void itemDidLayOut(UIView *item) {+ UIView *bar = tabBarOf(item);+ if (!bar) return;+ SGComposeTabBar(bar);+ holdHome(bar);+ SGLogTabBarRow(bar);+}++%hook _TtC23NavigationUI_TabBarImpl21TabBarItemElementView+- (void)layoutSubviews {+ %orig;+ itemDidLayOut((UIView *)self);+}+%end++%hook _TtC25CreateMenu_TabBarItemImpl24CreateMenuTabBarItemView+- (void)layoutSubviews {+ %orig;+ itemDidLayOut((UIView *)self);+}+%end++%ctor {+ if (!SGNativeUI()) return;+ %init;+ SGRequireClasses(@[+ @"_TtC23NavigationUI_TabBarImpl10TabBarView",+ @"_TtC23NavigationUI_TabBarImpl21TabBarItemElementView",+ @"_TtC25CreateMenu_TabBarItemImpl24CreateMenuTabBarItemView",+ ]);+}diff --git a/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.h b/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.hnew file mode 100644index 00000000..9679c771--- /dev/null+++ b/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.h@@ -0,0 +1,7 @@+// The native look's now playing bar: Spotify's own bar with its device button hidden on request+// (NowPlayingBar.x), and the bar's flags (NowPlayingBarSettings.m).+#import <UIKit/UIKit.h>++#define SGHideBarConnect @"spotifyglass.hide.barConnect" // the device button in the now playing bar++UIViewController *SGNowPlayingBarSettingsPage(void);diff --git a/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.xnew file mode 100644index 00000000..a5ac60c6--- /dev/null+++ b/tweak/Sources/Native/NowPlayingBar/NowPlayingBar.x@@ -0,0 +1,36 @@+// The device button of Spotify's own now playing bar, hidden on request.+//+// Tree (trees/test6.txt): the button row is a UIStackView holding Connect_EntryPointsImpl.ConnectStateView+// (the connected device) and .ConnectButtonView, each wrapped; hiding the wrapper closes the gap.+// The ConnectStateView under the title ("playing on ...") sits in InformationContainer and stays.+#import "Core/SGCore.h"+#import "NowPlayingBar.h"++static BOOL insideClass(UIView *view, NSString *marker) {+ for (UIView *v = view; v; v = v.superview) if ([NSStringFromClass(v.class) containsString:marker]) return YES;+ return NO;+}++static void hideConnectButton(UIView *bar) {+ SGForEachView(bar, ^(UIView *v) {+ NSString *name = NSStringFromClass(v.class);+ if (![name containsString:@"ConnectButtonView"] && ![name containsString:@"ConnectStateView"]) return;+ if (insideClass(v, @"InformationContainer")) return;+ UIView *item = v;+ while (item.superview && ![item.superview isKindOfClass:UIStackView.class]) item = item.superview;+ if (item.superview && !item.hidden) item.hidden = YES;+ });+}++%hook _TtC18NowPlaying_BarImpl27NowPlayingBarViewController+- (void)viewDidLayoutSubviews {+ %orig;+ hideConnectButton(((UIViewController *)self).view);+}+%end++%ctor {+ if (!SGNativeUI() || !SGHidden(SGHideBarConnect)) return;+ %init;+ SGRequireClasses(@[@"_TtC18NowPlaying_BarImpl27NowPlayingBarViewController"]);+}diff --git a/tweak/Sources/Native/NowPlayingBar/NowPlayingBarSettings.m b/tweak/Sources/Native/NowPlayingBar/NowPlayingBarSettings.mnew file mode 100644index 00000000..9c215b58--- /dev/null+++ b/tweak/Sources/Native/NowPlayingBar/NowPlayingBarSettings.m@@ -0,0 +1,20 @@+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "NowPlayingBar.h"++UIViewController *SGNowPlayingBarSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Now playing bar" intro:SGRestartNote sections:@[+ SGSection(nil, @[+ SGHideRow(@"Hide the device button", @"The speaker icon in the bar", SGHideBarConnect),+ ]),+ SGSection(@"Spotify's flags", @[+ SGFlagRow(@"Two lines of track info", @"ios-feature-nowplayingbar.two_lines_information_unit"),+ SGFlagRow(@"Save button", @"ios-feature-nowplayingbar.add_button"),+ SGFlagRow(@"Queue badge", @"ios-feature-nowplayingbar.queue_badge"),+ SGFlagRow(@"Hold and drag to resize", @"ios-feature-nowplayingbar.hold_and_drag_to_resize"),+ SGFlagRow(@"Video in the mini player", @"ios-feature-nowplaying.video_in_miniplayer"),+ SGFlagRow(@"Bar to cover art animation", @"ios-feature-nowplaying.bartocoverart_animation_enabled"),+ SGFlagRow(@"Mini player transition animations", @"ios-feature-nowplaying.miniplayer_transition_animations"),+ ]),+ ] footer:nil];+}diff --git a/tweak/Sources/Native/Player/Declutter.h b/tweak/Sources/Native/Player/Declutter.hdeleted file mode 100644index c43e7f25..00000000--- a/tweak/Sources/Native/Player/Declutter.h+++ /dev/null@@ -1,31 +0,0 @@-// Declutter: cards under the player and sections of Home collapsed, player buttons hidden, one-// switch each (Declutter.x). The rows live on the Player, Lyrics and Home & Library 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"--// The welcome tour's one switch for the player: on hides every card under the player but the-// lyrics, off shows them again. The player's buttons are not its business. Only the tour reads-// it; the hooks read the keys above.-#define SGKeyPlayerLyricsOnly @"spotifyglass.hide.playerLyricsOnly"-void SGSetPlayerLyricsOnly(BOOL on);diff --git a/tweak/Sources/Native/Player/KaraokeCard.x b/tweak/Sources/Native/Player/KaraokeCard.xindex ba77a873..c71b1287 100644--- a/tweak/Sources/Native/Player/KaraokeCard.x+++ b/tweak/Sources/Native/Player/KaraokeCard.x@@ -11,7 +11,7 @@// underneath and comes back the moment a track has no synced lyrics. It takes no touches, so the// tap that opens the full screen page is still Spotify's to answer.#import "Core/SGCore.h"-#import "Shared/Lyrics/Lyrics.h"+#import "Native/Lyrics/KaraokeView.h"// Below this the card is collapsed, by Declutter or while it is still being laid out.static const CGFloat kLivingHeight = 40;@@ -37,7 +37,7 @@ static char kKaraokeKey;%end%ctor {- if (!SGFlag(SGKeyKaraokeLyrics, NO)) return;+ if (!SGNativeUI() || !SGFlag(SGKeyKaraokeLyrics, NO)) return;%init;SGRequireClasses(@[@"_TtC22Lyrics_CardElementImpl15CardContentView"]);}diff --git a/tweak/Sources/Native/Player/LyricsCard.x b/tweak/Sources/Native/Player/LyricsCard.xindex 109f8810..222e2b57 100644--- a/tweak/Sources/Native/Player/LyricsCard.x+++ b/tweak/Sources/Native/Player/LyricsCard.x@@ -1,25 +1,15 @@-// The lyrics card under the player and the page it expands into, both on glass.+// The lyrics card under the player on glass ("Glass lyrics" on the Lyrics page).//// Card (trees/now-playing.txt): a Lyrics_CardElementImpl.CardView inside an// Element_List.CollectionViewCell 370x316. The cell is the painted surface with the 16pt corners,-// so the pane fills it and the cell's own clipping cuts the corners.-//-// Page (trees/lyrics.txt): a page of its own, presented over the player by a-// _UIOverFullscreenPresentationController, which is why the card's glass stops at the card's edge.-// Tome_PageTemplateImpl paints the template view #121212 and FullscreenView paints itself the-// album colour on top, both opaque; clearing them lets the player's blurred artwork through, so-// 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 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.+// so the pane fills it and the cell's own clipping cuts the corners. The page the card expands into+// is Native/Lyrics/LyricsPage.x's.#import "Core/SGCore.h"#import "NowPlaying.h"-#import "Redesigned/Kit/SGRedesign.h"+#import "Native/Appearance/Repaint.h"static const CGFloat kCardRadius = 16;-static char kCardGlassKey, kPageGlassKey;+static char kCardGlassKey;#pragma mark - the card in the player's scroll list@@ -32,19 +22,15 @@ static UIView *cellAround(UIView *view) {return nil;}-// The card is a content surface of the player redesign's own (Redesign/Player/PlayerCards.x) while it-// is on, so its glass stands aside; the page below is not the player's and keeps it.-%group Card-%hook _TtC22Lyrics_CardElementImpl8CardView- (void)layoutSubviews {%orig;if (!SGFlag(SGKeyLyricsCard, NO)) return;UIView *cell = cellAround((UIView *)self);- // A card Declutter/Declutter.x collapsed reports no height; leave it alone.+ // A card PlayerDeclutter.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; Appearance/Repaint.x keeps it clear in between.+ // pass of its own; Native/Appearance/Repaint.x keeps it clear in between.sg_lyricsCardRoot = cell;SGStripBackgrounds(cell);UIVisualEffectView *glass = SGGlassFor(cell, &kCardGlassKey);@@ -54,53 +40,11 @@ static UIView *cellAround(UIView *view) {}%end-%end--#pragma mark - the expanded page--// Up to the presentation: the template views in between paint themselves opaque once, at setup.-// Only the chain is cleared, not the subtree -- nothing else on the page is painted.-static UIView *clearAncestors(UIView *view) {- UIView *top = view;- for (UIView *v = view; v && ![v isKindOfClass:UIWindow.class]- && ![NSStringFromClass(v.class) hasPrefix:@"UITransition"]; v = v.superview) {- v.layer.backgroundColor = NULL;- top = v;- }- return top;-}--%hook _TtC32Lyrics_FullscreenElementPageImpl14FullscreenView-// A colour kept here is re-applied whenever UIKit feels like it, so it is refused outright.-- (void)setBackgroundColor:(UIColor *)color {- static dispatch_once_t once;- dispatch_once(&once, ^{ SGLog(@"lyrics page paints itself %@ through UIView", color); });- %orig(SGFlag(SGKeyLyricsCard, NO) ? nil : color);-}--- (void)layoutSubviews {- %orig;- if (!SGFlag(SGKeyLyricsCard, NO)) return;- UIView *page = (UIView *)self;- if (page.bounds.size.height < 200) return;-- page.layer.backgroundColor = NULL;- sg_lyricsPageRoot = clearAncestors(page);-- UIVisualEffectView *glass = SGGlassFor(page, &kPageGlassKey);- glass.frame = page.bounds;- glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;- // Full bleed, so the shape is spelled out: a fresh pane does not promise square corners.- SGShapeGlass(glass, 0, NO);-}-%end-%ctor {+ if (!SGNativeUI()) return;%init;- if (!SGRedesignOn(@"player")) %init(Card);SGRequireClasses(@[@"_TtC22Lyrics_CardElementImpl8CardView",@"_TtC12Element_List18CollectionViewCell",- @"_TtC32Lyrics_FullscreenElementPageImpl14FullscreenView",]);}diff --git a/tweak/Sources/Native/Player/NowPlaying.h b/tweak/Sources/Native/Player/NowPlaying.hindex 4f669a17..1c964920 100644--- a/tweak/Sources/Native/Player/NowPlaying.h+++ b/tweak/Sources/Native/Player/NowPlaying.h@@ -1,19 +1,40 @@-// 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). The bar, the backdrop and the lyrics card are off-// until asked for, together through Redesigned UI in Appearance; the header buttons are on.+// The native look's player: Spotify's full screen player with the artwork background and glass header+// buttons (Player.x), the glass lyrics card (LyricsCard.x), karaoke on the card (KaraokeCard.x), the+// gestures' hookup (PlayerGestures.x) and the parts of it to hide (PlayerDeclutter.x). The glass+// lyrics page is Native/Lyrics/LyricsPage.x's and shares SGKeyLyricsCard ("Glass lyrics").#import <UIKit/UIKit.h>-#define SGKeyNowPlayingBar @"spotifyglass.nowPlayingBar"#define SGKeyPlayer @"spotifyglass.player"#define SGKeyPlayerBackdrop @"spotifyglass.playerBackdrop"#define SGKeyLyricsCard @"spotifyglass.lyricsCard"-#define SGHideBarConnect @"spotifyglass.hide.barConnect" // the device button in the now playing bar-UIViewController *SGNowPlayingSettingsPage(void); // the Player page+// Parts of the player to hide, one switch each (PlayerDeclutter.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"-// Posted by NowPlayingBar.x as the full screen player starts to open or close, before the animation-// runs, and again once it is over; SGPlayerTransitionEnds says when it is expected to be over (as-// CACurrentMediaTime), 0 when none runs.-extern NSString *const SGPlayerTransitionNotification;-extern NSString *const SGPlayerTransitionEndedNotification;-CFTimeInterval SGPlayerTransitionEnds(void);+// The welcome tour's one switch for the player: on hides every card under the player but the+// lyrics, off shows them again. The player's buttons are not its business. Only the tour reads+// it; the hooks read the keys above.+#define SGKeyPlayerLyricsOnly @"spotifyglass.hide.playerLyricsOnly"+void SGSetPlayerLyricsOnly(BOOL on);++@class SGModRow, SGModSection;+// PlayerSettings.m: the player screen's sections of the Player page, the Queue & devices page and the+// "Glass lyrics" row of the Lyrics page.+NSArray<SGModSection *> *SGNativePlayerScreenSections(void);+UIViewController *SGQueueSettingsPage(void);+SGModRow *SGGlassLyricsRow(void);diff --git a/tweak/Sources/Native/Player/Player.x b/tweak/Sources/Native/Player/Player.xindex e065053e..9779413f 100644--- a/tweak/Sources/Native/Player/Player.x+++ b/tweak/Sources/Native/Player/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 NowPlaying/Lyrics.x.+// player are surfaces rather than controls; the lyrics one is in LyricsCard.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.@@ -21,9 +21,9 @@// 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 "Core/SGCore.h"+#import "Native/Appearance/Repaint.h"#import "NowPlaying.h"#import "Native/Appearance/Appearance.h"-#import "Redesigned/Kit/SGRedesign.h"static const CGFloat kButtonMin = 36, kButtonMax = 48;static const CGFloat kArtRadius = 12;@@ -36,7 +36,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-// Declutter/Declutter.x made invisible.+// PlayerDeclutter.x made invisible.static void glassBehindRoundButtons(UIViewController *unit) {if (!SGFlag(SGKeyPlayer, NO)) return;UIView *host = unit.viewIfLoaded;@@ -165,7 +165,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. Declutter/Declutter.x hides the same view outright.+ // the title it sits above. PlayerDeclutter.x hides the same view outright.if (backdropOn()) ((UIView *)self).alpha = 0.72;}%end@@ -193,8 +193,7 @@ static UIFont *timeFont(void) {%end%ctor {- // The player redesign (Redesign/Player/) owns this screen while it is on.- if (SGRedesignOn(@"player")) return;+ if (!SGNativeUI()) return;%init;SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit",diff --git a/tweak/Sources/Native/Player/PlayerDeclutter.x b/tweak/Sources/Native/Player/PlayerDeclutter.xindex 0411204c..083d1d26 100644--- a/tweak/Sources/Native/Player/PlayerDeclutter.x+++ b/tweak/Sources/Native/Player/PlayerDeclutter.x@@ -1,37 +1,31 @@-// Declutter: hides parts of the full screen player and of Home, one switch each in Mod Settings.-// Cards under the player and sections on Home are Element_List cells; a hidden one reports zero-// height when the list sizes it, so the list closes up around it (the 24pt gap between cards-// stays). Player buttons go invisible but keep their place, so their row stays centred.+// Player declutter: hides parts of the full screen player, one switch each on the Player page. Cards+// under the player are Element_List cells; a hidden one reports zero height when the list sizes it,+// so the list closes up around it (the 24pt gap between cards stays). Player buttons go invisible but+// keep their place, so their row stays centred.//-// Trees (trees/now-playing*.txt, trees/home*.txt): every card is a CollectionViewCell whose-// content view names the page (NowPlaying_ScrollAPI, Home_EvoPageImpl) and whose subtree names-// the card. Player rows are the UIStackView of each NowPlaying_ModesImpl unit: playback controls+// Trees (trees/now-playing*.txt): every card is a CollectionViewCell whose content view names the+// page (NowPlaying_ScrollAPI) and whose subtree names 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 "Core/SGCore.h"-#import "Declutter.h"-#import "Redesigned/Kit/SGRedesign.h"+#import "NowPlaying.h"#pragma mark - cards and sections-static const struct { __unsafe_unretained NSString *page, *marker, *key; } cards[] = {- {@"NowPlaying_ScrollAPI", @"Lyrics_CardElementImpl", SGHideLyricsCard},- {@"NowPlaying_ScrollAPI", @"CreatorBiography", SGHideAboutArtist},- {@"NowPlaying_ScrollAPI", @"VideoRecommendations", SGHideRelatedVideos},- {@"NowPlaying_ScrollAPI", @"SongDNA_", SGHideSongDNA},- {@"NowPlaying_ScrollAPI", @"LiveEvents_", SGHideLiveEvents},- {@"NowPlaying_ScrollAPI", @"WatchFeed_", SGHideExploreArtist},- {@"NowPlaying_ScrollAPI", @"Creator_Credits", SGHideCredits},- {@"NowPlaying_ScrollAPI", @"Merch_", SGHideMerch},- {@"NowPlaying_ScrollAPI", @"RelatedContentRecommendations", SGHideRecommendations},- {@"Home_EvoPageImpl", @"Home_AnchorsAndShortcutsKit", SGHideHomeShortcuts},- {@"Home_EvoPageImpl", @"Discovery_PromoElement", SGHideHomePromo},- {@"Home_EvoPageImpl", @"Discovery_PreviewElement", SGHideHomePreviews},- {@"Home_EvoPageImpl", @"Discovery_DJElement", SGHideHomeDJ},+static const struct { __unsafe_unretained NSString *marker, *key; } cards[] = {+ {@"Lyrics_CardElementImpl", SGHideLyricsCard},+ {@"CreatorBiography", SGHideAboutArtist},+ {@"VideoRecommendations", SGHideRelatedVideos},+ {@"SongDNA_", SGHideSongDNA},+ {@"LiveEvents_", SGHideLiveEvents},+ {@"WatchFeed_", SGHideExploreArtist},+ {@"Creator_Credits", SGHideCredits},+ {@"Merch_", SGHideMerch},+ {@"RelatedContentRecommendations", SGHideRecommendations},};// Class names of everything in the cell. Lists nested in the cell are laid out first so the-// cells that name the card (shortcut tiles, video cards) exist.+// cells that name the card (video cards) exist.static NSString *classNamesIn(UIView *cell) {NSMutableString *names = [NSMutableString string];SGForEachView(cell, ^(UIView *v) {@@ -48,13 +42,10 @@ static NSString *hiddenKeyFor(UICollectionViewCell *cell) {if ([v isKindOfClass:cell.class]) return nil;}NSString *names = nil;- // The cards under a redesigned player are Redesign/Player/PlayerCards.x's.- BOOL playerRedesigned = SGRedesignOn(@"player");for (size_t i = 0; i < sizeof(cards) / sizeof(cards[0]); i++) {if (!SGHidden(cards[i].key)) continue;- if (playerRedesigned && [cards[i].page isEqualToString:@"NowPlaying_ScrollAPI"]) continue;if (!names) names = classNamesIn(cell);- if ([names containsString:cards[i].page] && [names containsString:cards[i].marker]) return cards[i].key;+ if ([names containsString:@"NowPlaying_ScrollAPI"] && [names containsString:cards[i].marker]) return cards[i].key;}return nil;}@@ -81,15 +72,11 @@ static BOOL vanish(UIView *view) {return YES;}-// Re-layout once something went invisible, so the glass panes of NowPlaying/Player.x follow.+// Re-layout once something went invisible, so the glass panes of Player.x follow.static void finish(UIViewController *unit, BOOL changed) {if (changed) [unit.viewIfLoaded setNeedsLayout];}-// The player's buttons and the lyric preview under the artwork, left to the player redesign-// (Redesign/Player/) while it is on.-%group PlayerButtons-%hook _TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit- (void)viewDidLayoutSubviews {%orig;@@ -142,17 +129,6 @@ static void finish(UIViewController *unit, BOOL changed) {}%end-%end--#pragma mark - Home filter pills--%hook _TtC14Home_PillUIKit14PillScrollView-- (void)didMoveToWindow {- %orig;- if (SGHidden(SGHideHomePills)) ((UIView *)self).hidden = YES;-}-%end-void SGSetPlayerLyricsOnly(BOOL on) {for (NSString *key in @[SGHideAboutArtist, SGHideRelatedVideos, SGHideSongDNA, SGHideLiveEvents,SGHideExploreArtist, SGHideCredits, SGHideMerch, SGHideRecommendations]) {@@ -161,14 +137,13 @@ void SGSetPlayerLyricsOnly(BOOL on) {}%ctor {+ if (!SGNativeUI()) return;%init;- if (!SGRedesignOn(@"player")) %init(PlayerButtons);SGRequireClasses(@[@"_TtC12Element_List18CollectionViewCell",@"_TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit",@"_TtC20NowPlaying_ModesImpl18FooterElementsUnit",@"_TtC20NowPlaying_ModesImpl23InformationElementsUnit",@"_TtC22Lyrics_NPVContainerKit19LyricsContainerView",- @"_TtC14Home_PillUIKit14PillScrollView",]);}diff --git a/tweak/Sources/Native/Player/PlayerGestures.x b/tweak/Sources/Native/Player/PlayerGestures.xnew file mode 100644index 00000000..71e35f52--- /dev/null+++ b/tweak/Sources/Native/Player/PlayerGestures.x@@ -0,0 +1,33 @@+// The native player's hookup of the gestures (Shared/Gestures): the double tap goes on the player's artwork list.+//+// Tree (trees/now-playing.txt): the artwork sits in AccessibleCollectionView, a full screen list of+// the queue scrolled sideways, so the recognizer goes on that and the grid is the screen. Spotify's+// controls are sibling units rather than children of it, so a tap on a button never reaches it.+#import "Core/SGCore.h"+#import "Shared/Gestures/Gestures.h"++// A single tap on the cover is Spotify's way into the tilt mode, the artwork alone in 3D. That is+// the half of a double tap that misses, so while the zones are on it would open on the way to every+// gesture; the tap goes back to Spotify with the switch.+%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView+- (void)handleTap {+ if (SGFlag(SGKeyGestures, NO)) return;+ %orig;+}+%end++%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView+- (void)layoutSubviews {+ %orig;+ SGGestureAttach((UIView *)self);+}+%end++%ctor {+ if (!SGNativeUI()) return;+ %init;+ SGRequireClasses(@[+ @"_TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView",+ @"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView",+ ]);+}diff --git a/tweak/Sources/Native/Player/PlayerSettings.m b/tweak/Sources/Native/Player/PlayerSettings.mindex 50b73d9f..bcf75d98 100644--- a/tweak/Sources/Native/Player/PlayerSettings.m+++ b/tweak/Sources/Native/Player/PlayerSettings.m@@ -1,64 +1,8 @@+// The native player's settings: Spotify's own player screen and the parts of it to hide, and the queue+// and devices flags. The Player page that holds them is App/Pages.m's.#import "Core/SGCore.h"#import "Settings/SGModPage.h"#import "NowPlaying.h"-#import "Declutter.h"-#import "Shared/Gestures/Gestures.h"-#import "Shared/ArtistBlock/ArtistBlock.h"-#import "Shared/Lyrics/Lyrics.h"-#import "Shared/LockScreenLyrics/LockScreenLyrics.h"-#import "Shared/LyricsSources/LyricsSources.h"-#import "Redesigned/Kit/SGRedesign.h"--static UIViewController *nowPlayingBarPage(void) {- return [[SGModPage alloc] initWithTitle:@"Now playing bar" intro:SGRestartNote sections:@[- SGSection(nil, @[- SGOptionRow(@"Glass now playing bar", @"Glass card with round artwork", SGKeyNowPlayingBar),- SGHideRow(@"Hide the device button", @"The speaker icon in the bar", SGHideBarConnect),- ]),- SGSection(@"Spotify's flags", @[- SGFlagRow(@"Two lines of track info", @"ios-feature-nowplayingbar.two_lines_information_unit"),- SGFlagRow(@"Save button", @"ios-feature-nowplayingbar.add_button"),- SGFlagRow(@"Queue badge", @"ios-feature-nowplayingbar.queue_badge"),- SGFlagRow(@"Hold and drag to resize", @"ios-feature-nowplayingbar.hold_and_drag_to_resize"),- SGFlagRow(@"Video in the mini player", @"ios-feature-nowplaying.video_in_miniplayer"),- SGFlagRow(@"Bar to cover art animation", @"ios-feature-nowplaying.bartocoverart_animation_enabled"),- SGFlagRow(@"Mini player transition animations", @"ios-feature-nowplaying.miniplayer_transition_animations"),- ]),- ] footer:nil];-}--static UIViewController *lyricsPage(void) {- // The row reads the order out, so which sources are on is visible without opening it.- SGModRow *sources = SGPageRow(@"Lyrics sources", ^UIViewController *{ return SGLyricsSourcesPage(); });- sources.subtitle = @"BiniLyrics, Musixmatch, Unison, NetEase and LRCLIB, in the order you put them";- sources.value = ^NSString *{- NSMutableArray<NSString *> *names = [NSMutableArray array];- for (NSString *key in SGLyricsOrder()) [names addObject:SGLyricsProviderFor(key).name];- return names.count ? [names componentsJoinedByString:@", "] : @"Off";- };-- return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:SGRestartNote sections:@[- SGSection(nil, @[- SGOptionRow(@"Apple Music style", @"Word by word on the full screen page; timing inside a line is estimated unless Musixmatch has it", SGKeyKaraokeLyrics),- SGOptionRow(@"Glass lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard),- SGOptionRow(@"Lyrics on the lock screen", @"The line being sung in place of the artist, also in the Dynamic Island, Control Center and CarPlay", SGKeyLockScreenLyrics),- ]),- SGNotedSection(@"Where lyrics come from", @[- sources,- SGOptionRow(@"Lyrics for every track", @"Offers the lyrics card on tracks Spotify has no lyrics for; needs a source above", SGKeyLyricsAllTracks),- SGOptionRow(@"Name the source", @"Reads out which source the lines on the full screen page came from", SGKeyLyricsCredit),- ], @"With no source on, Spotify's own lyrics are left alone."),- 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(@"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(@"Lyrics toggle in the context menu", @"ios-feature-lyrics.lyrics_context_menu_toggle_enabled"),- ]),- ] footer:nil];-}// Flag rows show the flag's name as their subtitle by default.static SGModRow *bare(SGModRow *row) {@@ -66,46 +10,9 @@ static SGModRow *bare(SGModRow *row) {return row;}-static UIViewController *queuePage(void) {- return [[SGModPage alloc] initWithTitle:@"Queue & devices" intro:SGRestartNote sections:@[- SGNotedSection(@"Bottom sheets", @[- bare(SGFlagRow(@"Queue as a bottom sheet", @"ios-feature-nowplaying.bottom_sheet_queue_enabled")),- bare(SGFlagRow(@"Connect as a bottom sheet", @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet")),- bare(SGFlagRow(@"Connect sheet from the video switcher", @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet")),- ], @"Locked on while Redesigned UI is on."),- SGSection(@"Queue", @[- bare(SGFlagRow(@"Queue flip transition", @"ios-feature-nowplaying.queue_flip_transition_enabled")),- bare(SGFlagRow(@"Play next in the context menu", @"ios-feature-queue.is_play_next_context_menu_enabled")),- ]),- ] footer:nil];-}--static UIViewController *lockScreenPage(void) {- return [[SGModPage alloc] initWithTitle:@"Lock screen widget" intro:SGRestartNote sections:@[- SGSection(@"Controls", @[- bare(SGFlagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled")),- bare(SGFlagRow(@"Skip button on podcasts", @"ios-feature-lockscreen.skip_button_on_podcasts")),- bare(SGFlagRow(@"Chapter skip controls", @"ios-feature-lockscreen.enable_chapter_skip_controls")),- bare(SGFlagRow(@"Burst skip", @"ios-feature-lockscreen.burst_skip_enabled")),- ]),- SGSection(@"Artwork", @[- bare(SGFlagRow(@"Animated artwork", @"ios-feature-lockscreen.animated_artwork_enabled")),- bare(SGFlagRow(@"Video artwork", @"ios-feature-lockscreen.vit_artwork_enabled")),- bare(SGFlagRow(@"Companion content", @"ios-feature-lockscreen.companion_content_enabled")),- ]),- ] footer:nil];-}--// The pages at the top work with either player. Under them, Spotify's own player screen and its-// switches (Player.x and Declutter.x), which are put away while Redesigned UI is on: the player is the-// redesign's then (Redesign/Player), and none of them would change it. The stored switch decides, so a-// page opened after flipping it and before the restart already shows what the restart will bring.-static NSArray<SGModSection *> *playerScreenSections(void) {- if (SGFlag(SGKeyRedesign, NO)) {- return @[SGNotedSection(@"Player screen", @[], @"Redesigned UI is on, so the player is the redesign's own and the switches for Spotify's player are put away. Turn it off in Appearance to change Spotify's player again.")];- }+NSArray<SGModSection *> *SGNativePlayerScreenSections(void) {return @[- SGNotedSection(@"Player screen", @[+ SGSection(@"Player screen", @[SGOptionRow(@"Artwork background", @"The cover blurred and dimmed behind the player instead of the flat album colour", SGKeyPlayerBackdrop),SGOptionRow(@"Glass header buttons", nil, SGKeyPlayer),bare(SGKillRow(@"Disable Canvas", @"ios-feature-canvas.canvas_enabled")),@@ -113,7 +20,7 @@ static NSArray<SGModSection *> *playerScreenSections(void) {bare(SGFlagRow(@"Redesigned header", @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled")),bare(SGFlagRow(@"New progress slider", @"ios-feature-encoreexperiments.new_npv_slider_enabled")),bare(SGFlagRow(@"Expand the sticky header on tap", @"ios-feature-nowplaying.expand_sticky_header_on_tap")),- ], @"Redesigned UI turns the first two on or off with it."),+ ]),SGSection(@"Hide cards below the player", @[SGHideRow(@"Lyrics", nil, SGHideLyricsCard),SGHideRow(@"About the artist", nil, SGHideAboutArtist),@@ -137,26 +44,20 @@ static NSArray<SGModSection *> *playerScreenSections(void) {];}-UIViewController *SGNowPlayingSettingsPage(void) {- SGModRow *blocked = SGPageRow(@"Blocked artists", ^UIViewController *{ return SGArtistBlockSettingsPage(); });- blocked.value = ^NSString *{- return SGFlag(SGKeyArtistBlock, NO) ? @(SGBlockedArtists().count).stringValue : @"Off";- };+SGModRow *SGGlassLyricsRow(void) {+ return SGOptionRow(@"Glass lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard);+}- NSArray<SGModSection *> *sections = @[- SGSection(nil, @[- SGWithSymbol(SGPageRow(@"Gestures", ^UIViewController *{ return SGGesturesSettingsPage(); }), @"hand.tap"),- SGWithSymbol(SGPageRow(@"Lyrics", ^UIViewController *{ return lyricsPage(); }), @"quote.bubble"),- SGWithSymbol(blocked, @"person.crop.circle.badge.xmark"),+UIViewController *SGQueueSettingsPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Queue & devices" intro:SGRestartNote sections:@[+ SGSection(@"Bottom sheets", @[+ bare(SGFlagRow(@"Queue as a bottom sheet", @"ios-feature-nowplaying.bottom_sheet_queue_enabled")),+ bare(SGFlagRow(@"Connect as a bottom sheet", @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet")),+ bare(SGFlagRow(@"Connect sheet from the video switcher", @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet")),]),- SGSection(nil, @[- SGWithSymbol(SGPageRow(@"Now playing bar", ^UIViewController *{ return nowPlayingBarPage(); }), @"rectangle.bottomthird.inset.filled"),- SGWithSymbol(SGPageRow(@"Queue & devices", ^UIViewController *{ return queuePage(); }), @"text.line.first.and.arrowtriangle.forward"),- SGWithSymbol(SGPageRow(@"Lock screen widget", ^UIViewController *{ return lockScreenPage(); }), @"lock"),+ SGSection(@"Queue", @[+ bare(SGFlagRow(@"Queue flip transition", @"ios-feature-nowplaying.queue_flip_transition_enabled")),+ bare(SGFlagRow(@"Play next in the context menu", @"ios-feature-queue.is_play_next_context_menu_enabled")),]),- ];- return [[SGModPage alloc] initWithTitle:@"Player"- intro:@"Changes apply after you restart Spotify. Gestures and Blocked artists apply straight away."- sections:[sections arrayByAddingObjectsFromArray:playerScreenSections()]- footer:nil];+ ] footer:nil];}diff --git a/tweak/Sources/Native/Playlist/Playlist.x b/tweak/Sources/Native/Playlist/Playlist.xindex 71be7018..d9f7a259 100644--- a/tweak/Sources/Native/Playlist/Playlist.x+++ b/tweak/Sources/Native/Playlist/Playlist.x@@ -234,6 +234,7 @@ static void applyBackdrop(UIView *layout) {%end%ctor {+ if (!SGNativeUI()) return;%init;SGRequireClasses(@[@"_TtC28EncoreConsumerMobile_BaseKit19HeaderContentLayout",diff --git a/tweak/Sources/Redesigned/Kit/SGRBridges.h b/tweak/Sources/Redesigned/Kit/SGRBridges.hindex c284a635..e4c7326c 100644--- a/tweak/Sources/Redesigned/Kit/SGRBridges.h+++ b/tweak/Sources/Redesigned/Kit/SGRBridges.h@@ -1,5 +1,5 @@// What the redesigned screens read from Spotify and ask of it, through one hook each, so no screen-// hooks the player or the link dispatcher a second time.+// hooks the player a second time.//// Player state: -[_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation player:stateDidChange:]// (objc-methods.txt:60654), the now playing platform's own player observer, and until that has reported,@@ -8,8 +8,6 @@// Artwork: the now playing bar's 40pt cover (trees/clean/artist/01.txt: id=SPTNowPlayingBar > Encore.ImageView >// UIImageView 40x40), read after the bar's layout and after a track change; installed while the player// is redesigned. Screens publish better copies of their own (the player's cover).-// Links: -[SPTLinkDispatcherImplementation setMainUILoaded:] (:38809), the last call of the singleton's-// setup, always installed: the Navbar's own tabs open through it too.//// Threading: everything here is main thread only; the player's reports are moved onto it.#import <UIKit/UIKit.h>@@ -43,16 +41,9 @@ void SGRSetNowPlayingArtwork(UIImage *image, NSString *trackURI, SGRArtworkQuali// -[SGRArtworkField setArtwork:identity:animated:]) are filled when asked for.UIImage *SGRNowPlayingArtwork(NSString **trackURI, NSString **identity);-#pragma mark - links--// Opens a spotify: URI the way the app opens a link of its own. NO before the dispatcher is set up or-// for a nil URI.-BOOL SGROpenURI(NSURL *uri);-id SGRLinkDispatcher(void); // SPTLinkDispatcherImplementation, nil until it is set up-#pragma mark - the player's open and close-// While the full screen player opens or closes (NowPlaying/NowPlayingBar.x announces it).+// While the full screen player opens or closes (Shared/Player/PlayerEvents.x announces it).BOOL SGRPlayerIsTransitioning(void);// SGPlayerTransitionNotification and SGPlayerTransitionEndedNotification as blocks, for as long as// `owner` lives. The blocks are handed the owner so they need not capture it.diff --git a/tweak/Sources/Redesigned/Kit/SGRBridges.x b/tweak/Sources/Redesigned/Kit/SGRBridges.xindex ade01d51..47c0fa21 100644--- a/tweak/Sources/Redesigned/Kit/SGRBridges.x+++ b/tweak/Sources/Redesigned/Kit/SGRBridges.x@@ -1,8 +1,8 @@-// The Kit's bridges into Spotify: the player's state, the now playing artwork and the link dispatcher.+// The Kit's bridges into Spotify: the player's state and the now playing artwork. Links and the+// player's open and close are Shared's (Shared/Navigation/Links.h, Shared/Player/PlayerEvents.h).// SGRBridges.h names the hooks and why they are the ones.#import "Core/SGCore.h"-#import "Headers/SPTLinkDispatcherImplementation.h"-#import "Native/Player/NowPlaying.h"+#import "Shared/Player/PlayerEvents.h"#import "SGRBridges.h"#import "SGRedesign.h"#import "SGRRestyle.h"@@ -189,29 +189,6 @@ static SGRBarArtworkWatcher *sg_barWatcher;%end%end-#pragma mark - links--static __weak SPTLinkDispatcherImplementation *sg_linkDispatcher;--id SGRLinkDispatcher(void) {- return sg_linkDispatcher;-}--BOOL SGROpenURI(NSURL *uri) {- SPTLinkDispatcherImplementation *dispatcher = sg_linkDispatcher;- if (!uri || ![dispatcher respondsToSelector:@selector(navigateToURI:options:interactionID:)]) return NO;- [dispatcher navigateToURI:uri options:0 interactionID:nil];- return YES;-}--// The dispatcher is a singleton the app builds at startup; this is the last call of its setup.-%hook SPTLinkDispatcherImplementation-- (void)setMainUILoaded:(BOOL)loaded {- %orig;- sg_linkDispatcher = (SPTLinkDispatcherImplementation *)self;-}-%end-#pragma mark - the player's open and closeBOOL SGRPlayerIsTransitioning(void) {@@ -258,12 +235,9 @@ void SGRObservePlayerTransition(id owner, void (^began)(id owner), void (^ended)}%ctor {- %init;- SGRequireClasses(@[@"SPTLinkDispatcherImplementation"]);- if (!SGRedesignAnyOn()) return;+ if (!SGRedesignedUI()) return;%init(SGRPlayerStateHooks);SGRequireClasses(@[@"_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation", @"SPTEsperantoPlayer", @"SPTPlayerState"]);- if (!SGRedesignOn(@"player")) return;sg_barWatcher = [SGRBarArtworkWatcher new];SGRAddPlayerStateObserver(sg_barWatcher);%init(SGRBarArtworkHooks);diff --git a/tweak/Sources/Redesigned/Kit/SGREdgeEffect.x b/tweak/Sources/Redesigned/Kit/SGREdgeEffect.xnew file mode 100644index 00000000..12587195--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGREdgeEffect.x@@ -0,0 +1,38 @@+// The redesign's copy of Native/Appearance/EdgeEffect.x.+// Soft top edge: iOS 27 resolves a scroll view's automatic top edge effect to the hard style, the+// flat dark band under the navigation bar (UIKit.ScrollEdgeEffectView in trees/continuous/1.txt).+// Setting the soft style brings back iOS 26's thin fading blur. Set on every layout pass as well as+// on arrival, in case UIKit resolves the style again after the page appears.+#import <objc/runtime.h>+#import "Core/SGCore.h"++static void soften(UIScrollView *scrollView) {+ if (@available(iOS 26.0, *)) {+ // The style last set here, so a layout pass the setter itself causes does not set it again.+ static char setKey;+ UIScrollEdgeEffect *top = scrollView.topEdgeEffect;+ if (top.style == objc_getAssociatedObject(scrollView, &setKey)) return;+ UIScrollEdgeEffectStyle *soft = UIScrollEdgeEffectStyle.softStyle;+ top.style = soft;+ objc_setAssociatedObject(scrollView, &setKey, top.style, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"soft top edge: first scroll view %@", NSStringFromClass(scrollView.class)); });+ }+}++%hook UIScrollView+- (void)didMoveToWindow {+ %orig;+ if (self.window) soften(self);+}++- (void)layoutSubviews {+ %orig;+ if (self.window) soften(self);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+}diff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.hindex 363b4282..cb8447b7 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.h+++ b/tweak/Sources/Redesigned/Kit/SGRField.h@@ -2,9 +2,8 @@// a whole redesigned page, with no card and no seam anywhere. The player's field also carries the// artwork itself at the top, blurred and dimmed and dissolving into the colour (showsBackdrop).//-// Nothing is blurred live and nothing is masked: the view draws a solid colour layer, a black-// gradient layer under AMOLED and at most one bitmap layer rendered off the main thread, so it costs-// one composited layer or two while the page moves. A new colour or bitmap crossfades over+// Nothing is blurred live and nothing is masked: the view draws a solid colour layer and at most one+// bitmap layer rendered off the main thread, so it costs one composited layer or two while the page moves. A new colour or bitmap crossfades over// SGRCrossfade; the same image again is a no-op.//// Ownership: the screen that installs a field owns it (usually retained by its superview and an@@ -17,15 +16,12 @@extern NSNotificationName const SGRFieldColorDidChangeNotification;@interface SGRArtworkField : UIView-// Where the colour, the AMOLED fade and the backdrop reach past the bounds (overscroll, a plane+// Where the colour and the backdrop reach past the bounds (overscroll, a plane// that does not clip): positive values draw outside. The field never clips.@property (nonatomic) UIEdgeInsets bleed;@property (nonatomic) BOOL showsBackdrop;// The backdrop's height in points from the top of the bounds; 0 is the window's height.@property (nonatomic) CGFloat backdropHeight;-// With AMOLED on: where the colour starts fading to black and where it is black, in points from the-// top of the bounds; 0 is 55% and 100% of the window's height.-@property (nonatomic) CGFloat amoledFadeFrom, amoledFadeTo;// SGRNeutralField until a colour arrives.@property (nonatomic, readonly) UIColor *fieldColor;diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.mindex 5c884511..e9a7e645 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.m+++ b/tweak/Sources/Redesigned/Kit/SGRField.m@@ -1,12 +1,10 @@#import "Core/SGCore.h"-#import "Native/Appearance/Appearance.h"#import "SGRField.h"#import "SGRPalette.h"#import "SGRTokens.h"NSNotificationName const SGRFieldColorDidChangeNotification = @"spotifyglass.redesign.fieldColorDidChange";-static const CGFloat kAmoledFrom = 0.55;static const CGFloat kFallbackHeight = 874; // a window-less field sizes for an iPhone 17 Prostatic CGFloat windowHeight(UIView *view) {@@ -14,9 +12,8 @@ static CGFloat windowHeight(UIView *view) {return height > 0 ? height : kFallbackHeight;}-// The field paints on sublayers of its own rather than on the view's layer: Appearance/Repaint.x only-// clears the paint of a view's own layer, so the neutral colour cannot be taken for Spotify's base-// surface inside a page registered as a clear root.+// The field paints on sublayers of its own rather than on the view's layer: a repaint hook only clears+// the paint of a view's own layer, so the neutral colour cannot be taken for Spotify's base surface.static NSDictionary *noActions(void) {static NSDictionary *none;static dispatch_once_t once;@@ -29,7 +26,6 @@ static NSDictionary *noActions(void) {@implementation SGRArtworkField {CALayer *_solid;- CAGradientLayer *_amoled;CALayer *_backdrop;UIColor *_color;UIImage *_image;@@ -50,13 +46,6 @@ static NSDictionary *noActions(void) {_solid.backgroundColor = _color.CGColor;[self.layer addSublayer:_solid];- if (SGFlag(SGKeyAmoled, NO)) {- _amoled = [CAGradientLayer layer];- _amoled.actions = noActions();- _amoled.colors = @[(id)[UIColor colorWithWhite:0 alpha:0].CGColor, (id)UIColor.blackColor.CGColor];- [self.layer addSublayer:_amoled];- }-_backdrop = [CALayer layer];_backdrop.actions = noActions();_backdrop.contentsGravity = kCAGravityResize;@@ -91,13 +80,6 @@ static NSDictionary *noActions(void) {[CATransaction begin];[CATransaction setDisableActions:YES];_solid.frame = painted;- if (_amoled) {- CGFloat height = windowHeight(self), total = MAX(1, painted.size.height);- CGFloat from = (_amoledFadeFrom > 0 ? _amoledFadeFrom : height * kAmoledFrom) + bleed.top;- CGFloat to = MAX(from + 1, (_amoledFadeTo > 0 ? _amoledFadeTo : height) + bleed.top);- _amoled.frame = painted;- _amoled.locations = @[@(MIN(1, from / total)), @(MIN(1, to / total))];- }_backdrop.frame = CGRectMake(0, 0, bounds.size.width, [self backdropHeightNow]);[CATransaction commit];}@@ -114,7 +96,6 @@ static NSDictionary *noActions(void) {if (animated && from) {CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];fade.fromValue = from;- // Read back rather than the colour asked for: Appearance/Amoled.x may have swapped it for black.fade.toValue = (__bridge id)_solid.backgroundColor;fade.duration = SGRCrossfade;fade.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];@@ -133,7 +114,7 @@ static NSDictionary *noActions(void) {_image = image;_identity = [identity copy];NSUInteger generation = ++_generation;- SGRPaletteRequest request = {CGSizeZero, NO, _amoled != nil};+ SGRPaletteRequest request = {CGSizeZero, NO, NO};if (_showsBackdrop) request.backdropSize = CGSizeMake(self.bounds.size.width > 0 ? self.bounds.size.width : 402, [self backdropHeightNow]);__weak SGRArtworkField *weakSelf = self;[SGRPalette paletteForImage:image request:request completion:^(SGRPalette *palette) {diff --git a/tweak/Sources/Redesigned/Kit/SGRGlassDesign.x b/tweak/Sources/Redesigned/Kit/SGRGlassDesign.xnew file mode 100644index 00000000..b373c32a--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRGlassDesign.x@@ -0,0 +1,28 @@+// Spotify's own newer design, which it ships behind several flags switched off: the glass navigation+// bar, the new player slider, the sheet style player, the queue and Connect sheets, the redesigned+// player header, the sleep timer's options sheet. The redesign is built on all of it, so while+// Redesigned UI is on each is forced and its row elsewhere shows it locked.+#import "Core/SGCore.h"+#import "SGRedesign.h"++%hook SPTHubViewController+- (BOOL)prefersLiquidGlassNavigationBar {+ return YES;+}+%end++%ctor {+ SGRedesignForceFlags(@"glass design", @{+ @"ios-reprise-liquid-glass-properties.context_menu_in_navigation_bar_enabled": @YES,+ @"ios-feature-encoreexperiments.new_npv_slider_enabled": @YES,+ @"ios-feature-nowplaying.sheet_style_npv": @YES,+ @"ios-feature-nowplaying.bottom_sheet_queue_enabled": @YES,+ @"ios-feature-nowplaying.new_redesign_header_with_context_menu_enabled": @YES,+ @"ios-feature-nowplaying-elements.enable_connect_bottom_sheet": @YES,+ @"ios-playbackcontrol-audiovideoswitcher-impl.enable_connect_bottom_sheet": @YES,+ @"ios-feature-sleeptimer.use_options_sheet": @YES,+ });+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[@"SPTHubViewController"]);+}diff --git a/tweak/Sources/Redesigned/Kit/SGRKit.h b/tweak/Sources/Redesigned/Kit/SGRKit.hindex 8c5bf1fb..a085093b 100644--- a/tweak/Sources/Redesigned/Kit/SGRKit.h+++ b/tweak/Sources/Redesigned/Kit/SGRKit.h@@ -1,4 +1,4 @@-// The Redesign Kit: what every redesigned screen (Redesign/<Screen>/) builds on, so the screens share+// The Redesign Kit: what every part of the redesign (Redesigned/<Part>/) builds on, so the screens share// one look and nothing is hand-rolled per screen. A screen imports this and Core/SGCore.h.//// SGRedesign.h Redesigned UI, the one switch, and the flags the redesigned screens force@@ -8,12 +8,11 @@// SGRGlass.h glass inside Spotify's round controls// SGRGlyph.h bare glyph overlays and glyph buttons// SGRRestyle.h keeping Spotify's views restyled: suppress, digits, lookups, shadows, firing controls-// SGRBridges.h player state, now playing artwork, links, the player's open and close+// SGRBridges.h player state, now playing artwork, the player's open and close+// SGRRepaint.h the areas the redesign keeps transparent when Spotify repaints them//-// A screen's hooks install only while Redesigned UI is on: every .x of a screen ends with-// %ctor { if (!SGRedesignOn(@"<screen>")) return; %init; SGRequireClasses(@[...]); }-// and the legacy hooks of that screen stand aside with the same test, so with the switch off the mod-// behaves exactly as it did before the Kit.+// Every hook file of the redesign starts its %ctor with `if (!SGRedesignedUI()) return;` and every one+// of Native/ with `if (!SGNativeUI()) return;` (Core/SGUIMode.h), so the two looks never run together.#import "SGRedesign.h"#import "SGRTokens.h"#import "SGRPalette.h"@@ -22,3 +21,4 @@#import "SGRGlyph.h"#import "SGRRestyle.h"#import "SGRBridges.h"+#import "SGRRepaint.h"diff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.h b/tweak/Sources/Redesigned/Kit/SGRRepaint.hnew file mode 100644index 00000000..533f1270--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.h@@ -0,0 +1,8 @@+// The areas the redesign stripped and SGRRepaint.x keeps transparent when Spotify repaints them, each+// set by the part of the redesign that owns it.+#import <UIKit/UIKit.h>++extern __weak UIView *sgr_nowPlayingRoot; // Redesigned/NowPlayingBar/NowPlayingBar.x, the bar+extern __weak UIView *sgr_nowPlayingCard; // the bar's painted card, learnt from the album-colour paint+extern __weak UIView *sgr_lyricsCardRoot; // Redesigned/Player/PlayerCards.x, the cell of the lyrics card+extern __weak UIView *sgr_lyricsPageRoot; // Redesigned/Lyrics/LyricsPage.xdiff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.x b/tweak/Sources/Redesigned/Kit/SGRRepaint.xnew file mode 100644index 00000000..bda641e7--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.x@@ -0,0 +1,35 @@+// Keeps the areas the redesign stripped transparent when Spotify repaints them, and learns which view+// is the now playing bar's card from the album-colour paint.+#import "Core/SGCore.h"+#import "SGRRepaint.h"++__weak UIView *sgr_nowPlayingRoot = nil;+__weak UIView *sgr_nowPlayingCard = nil;+__weak UIView *sgr_lyricsCardRoot = nil;+__weak UIView *sgr_lyricsPageRoot = nil;++%hook CALayer+- (void)setBackgroundColor:(CGColorRef)color {+ if (color && (sgr_nowPlayingRoot || sgr_lyricsCardRoot || sgr_lyricsPageRoot)) {+ UIView *view = (UIView *)self.delegate;+ if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {+ if (SGIsInside(view, sgr_nowPlayingRoot)) {+ if (SGLooksLikeCard(view, color) && sgr_nowPlayingCard != view) {+ sgr_nowPlayingCard = view;+ UIView *bar = sgr_nowPlayingRoot;+ dispatch_async(dispatch_get_main_queue(), ^{ [bar.superview setNeedsLayout]; });+ }+ color = NULL;+ } else if (SGIsInside(view, sgr_lyricsCardRoot) || SGIsInside(view, sgr_lyricsPageRoot)) {+ color = NULL;+ }+ }+ }+ %orig(color);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+}diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.h b/tweak/Sources/Redesigned/Kit/SGRTokens.hindex b47c859b..0c0d3619 100644--- a/tweak/Sources/Redesigned/Kit/SGRTokens.h+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.h@@ -27,7 +27,7 @@ UIColor *SGRPrimary(void); // whiteUIColor *SGRSecondary(void); // white 65%, 80% with Increase ContrastUIColor *SGRTertiary(void); // white 40%, 60% with Increase ContrastUIColor *SGRAccent(void); // the accent colour of Appearance, else Spotify's green-UIColor *SGRNeutralField(void); // #121212, the field before a colour arrives; AMOLED turns it black+UIColor *SGRNeutralField(void); // #121212, the field before a colour arrives// Where glass cannot be (Reduce Transparency), the shape it would have had: white 16% over the field.UIColor *SGRSolidGlassFill(void);// A content surface on the field (a card), a step lighter than the field it sits on.diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.m b/tweak/Sources/Redesigned/Kit/SGRTokens.mindex dd67acbb..cc2c8f3c 100644--- a/tweak/Sources/Redesigned/Kit/SGRTokens.m+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.m@@ -1,6 +1,5 @@#import <CoreText/SFNTLayoutTypes.h>#import "Core/SGCore.h"-#import "Native/Appearance/Appearance.h"#import "SGRTokens.h"const CGFloat SGRSideMargin = 16;@@ -31,9 +30,9 @@ UIColor *SGRTertiary(void) {return [UIColor colorWithWhite:1 alpha:SGRIncreaseContrast() ? 0.60 : 0.40];}-// Read per call: the accent is stored as it is picked, and the colour row reads it the same way.+// Spotify's green: the accent colour is the native look's.UIColor *SGRAccent(void) {- return SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];+ return [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];}UIColor *SGRNeutralField(void) {@@ -47,7 +46,7 @@ UIColor *SGRSolidGlassFill(void) {UIColor *SGRElevated(UIColor *field) {CGFloat r = 0, g = 0, b = 0, a = 1;if (![field getRed:&r green:&g blue:&b alpha:&a]) return [UIColor colorWithWhite:1 alpha:0.08];- // 12% towards white keeps a card on a black AMOLED field clear of the greys Amoled.x turns black.+ // 12% towards white keeps a card clear of a dark field.CGFloat lift = 0.12;return [UIColor colorWithRed:r + (1 - r) * lift green:g + (1 - g) * lift blue:b + (1 - b) * lift alpha:1];}diff --git a/tweak/Sources/Redesigned/Kit/SGRedesign.h b/tweak/Sources/Redesigned/Kit/SGRedesign.hindex 9fa40f8b..3e93b91a 100644--- a/tweak/Sources/Redesigned/Kit/SGRedesign.h+++ b/tweak/Sources/Redesigned/Kit/SGRedesign.h@@ -1,30 +1,9 @@-// Redesign: Redesigned UI, one switch in Appearance, puts every redesigned screen (Redesign/<Screen>/)-// in place of Spotify's own and turns on Spotify's glass and the mod's glass switches (Appearance/AppearanceSettings.m).-// Off until asked for and read once per launch like every other switch, so a screen never changes-// hands while it is on screen. While it is on, the legacy hooks of the redesigned screens stand aside-// (each gates itself with SGRedesignOn), their switches are put away on their pages, and the-// redesign forces the remote-config flags it is built on, over any override, with their rows locked.-//-// Threading: SGRedesignOn, SGRedesignAnyOn and SGRedesignForcedFlag are safe from any thread (the-// configuration provider asks from several). Registration happens in a %ctor, before Spotify reads a-// flag.-#import <UIKit/UIKit.h>+// The flags the redesign is built on. A redesigned screen, and the glass design Spotify ships switched+// off (SGRGlassDesign.x), register theirs from a %ctor whether or not Redesigned UI is on: the settings+// rows need the list to lock theirs. Only while Redesigned UI was on at launch is anything forced,+// and then over an override from the All flags page too (Core/SGFlagForce.h). The switch itself is+// Core/SGUIMode.h's.+// Threading: register from a %ctor, before Spotify reads a flag.+#import <Foundation/Foundation.h>-#define SGKeyRedesign @"spotifyglass.redesign"--// Whether the screen ("player") is one Redesigned UI replaces and the switch was on when Spotify started.-BOOL SGRedesignOn(NSString *screen);-BOOL SGRedesignAnyOn(void);-// The screens Redesigned UI replaces.-NSArray<NSString *> *SGRedesignScreens(void);--// The flags a screen's redesign forces, flag key to @YES/@NO/number/string, registered from the-// screen's %ctor whether or not the screen is on: the settings rows need the list to lock theirs.-// Only while Redesigned UI was on at launch does anything get forced, and then over an override from-// the All flags page too: the redesign is built on these values.-void SGRedesignForceFlags(NSString *screen, NSDictionary<NSString *, id> *flags);-// For Features/Flags/Flags.x, before SGFlagOverride: the value a screen on at launch forces, or nil.-id SGRedesignForcedFlag(NSString *key);-// For the flag rows of Settings/SGModPage.m: the value a redesigned screen forces while the stored-// switch is on, or nil. It follows the stored switch rather than the launch, as the glass lock does.-id SGRedesignOwnedFlag(NSString *key);+void SGRedesignForceFlags(NSString *owner, NSDictionary<NSString *, id> *flags);diff --git a/tweak/Sources/Redesigned/Kit/SGRedesign.m b/tweak/Sources/Redesigned/Kit/SGRedesign.mindex 328c382b..d4410324 100644--- a/tweak/Sources/Redesigned/Kit/SGRedesign.m+++ b/tweak/Sources/Redesigned/Kit/SGRedesign.m@@ -1,82 +1,35 @@-// The one switch of the redesign, Redesigned UI in Appearance, and the flags the redesigned screens-// force. The switch turns every redesigned screen on together: two looks, Spotify's with the mod's-// switches on it or the redesign, rather than a mix of both whose switches would cross.#import <os/lock.h>#import "Core/SGCore.h"#import "SGRedesign.h"-// The screens Redesigned UI turns on; a screen added later needs only its name here.-NSArray<NSString *> *SGRedesignScreens(void) {- return @[@"player"];-}+// Written from the constructors, read by the configuration provider on whatever thread it asks from;+// the lock only guards the swap of the immutable table.+static os_unfair_lock sg_flagsLock = OS_UNFAIR_LOCK_INIT;+static NSDictionary<NSString *, id> *sg_flags;-#pragma mark - switch+static id forcedNow(NSString *key) {+ os_unfair_lock_lock(&sg_flagsLock);+ id value = sg_flags[key];+ os_unfair_lock_unlock(&sg_flagsLock);+ return value;+}-// Read once, the first time anything asks, so a switch flipped in Mod Settings waits for the restart-// like every other; the hooks, the flags and the pages all see the same answer for the whole launch.-static BOOL onAtLaunch(void) {- static BOOL on;+void SGRedesignForceFlags(NSString *owner, NSDictionary<NSString *, id> *flags) {+ if (!flags.count) return;static dispatch_once_t once;dispatch_once(&once, ^{- on = SGFlag(SGKeyRedesign, NO);- if (on) SGLog(@"redesign: on for %@", [SGRedesignScreens() componentsJoinedByString:@", "]);+ SGRegisterFlagForcer(YES, ^id(NSString *key) { return SGRedesignedUI() ? forcedNow(key) : nil; },+ ^id(NSString *key) { return SGRedesignedUIStored() ? forcedNow(key) : nil; });});- return on;-}--BOOL SGRedesignOn(NSString *screen) {- return screen && onAtLaunch() && [SGRedesignScreens() containsObject:screen];-}--BOOL SGRedesignAnyOn(void) {- return onAtLaunch();-}--#pragma mark - forced flags--// Written from the screens' constructors, read by the configuration provider on whatever thread it-// asks from; the lock only guards the swap of the immutable tables.-static os_unfair_lock sg_flagsLock = OS_UNFAIR_LOCK_INIT;-static NSDictionary<NSString *, NSDictionary<NSString *, id> *> *sg_flagsByScreen;-static NSDictionary<NSString *, id> *sg_forcedNow;--void SGRedesignForceFlags(NSString *screen, NSDictionary<NSString *, id> *flags) {- if (!screen.length || !flags.count) return;- BOOL on = SGRedesignOn(screen);os_unfair_lock_lock(&sg_flagsLock);- NSMutableDictionary *byScreen = [sg_flagsByScreen mutableCopy] ?: [NSMutableDictionary dictionary];- byScreen[screen] = [flags copy];- sg_flagsByScreen = [byScreen copy];- if (on) {- NSMutableDictionary *forced = [sg_forcedNow mutableCopy] ?: [NSMutableDictionary dictionary];- [forced addEntriesFromDictionary:flags];- sg_forcedNow = [forced copy];- }+ NSMutableDictionary *all = [sg_flags mutableCopy] ?: [NSMutableDictionary dictionary];+ [all addEntriesFromDictionary:flags];+ sg_flags = [all copy];os_unfair_lock_unlock(&sg_flagsLock);- if (!on) return;- SGLog(@"redesign %@: forcing %lu flags", screen, (unsigned long)flags.count);+ if (!SGRedesignedUI()) return;+ SGLog(@"redesign %@: forcing %lu flags", owner, (unsigned long)flags.count);[flags enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {id override = SGFlagOverride(key);- if (override) SGLog(@"redesign %@: flag %@ forced %@ over the All flags override %@", screen, key, value, override);+ if (override) SGLog(@"redesign %@: flag %@ forced %@ over the All flags override %@", owner, key, value, override);}];}--id SGRedesignForcedFlag(NSString *key) {- if (!key || !SGRedesignAnyOn()) return nil;- os_unfair_lock_lock(&sg_flagsLock);- id value = sg_forcedNow[key];- os_unfair_lock_unlock(&sg_flagsLock);- return value;-}--id SGRedesignOwnedFlag(NSString *key) {- if (!key || !SGFlag(SGKeyRedesign, NO)) return nil;- os_unfair_lock_lock(&sg_flagsLock);- NSDictionary<NSString *, NSDictionary<NSString *, id> *> *byScreen = sg_flagsByScreen;- os_unfair_lock_unlock(&sg_flagsLock);- for (NSString *screen in SGRedesignScreens()) {- id value = byScreen[screen][key];- if (value) return value;- }- return nil;-}diff --git a/tweak/Sources/Redesigned/Lyrics/KaraokePage.x b/tweak/Sources/Redesigned/Lyrics/KaraokePage.xnew file mode 100644index 00000000..3b6093ad--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/KaraokePage.x@@ -0,0 +1,31 @@+// The karaoke view goes over the lyrics part of the full screen lyrics page (trees/lyrics.txt:+// Lyrics_FullscreenElementPageImpl.LyricsView, between the header and the controls), so Spotify's+// header, close button and controls stay working. It is laid over rather than swapped in: Spotify's+// list keeps running underneath and comes back the moment a track has no synced lyrics.+#import "Core/SGCore.h"+#import "SGRKaraokeView.h"++static char kKaraokeKey;++%hook _TtC32Lyrics_FullscreenElementPageImpl10LyricsView+- (void)layoutSubviews {+ %orig;+ UIView *host = (UIView *)self;+ SGRKaraokeView *view = objc_getAssociatedObject(host, &kKaraokeKey);+ if (!view) {+ SGLog(@"karaoke: page opened, playing %@", SGKaraokePlayingTrack());+ view = [[SGRKaraokeView alloc] initWithFrame:host.bounds];+ objc_setAssociatedObject(host, &kKaraokeKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ if (view.superview == host) [host bringSubviewToFront:view];+ else [host addSubview:view];+ view.frame = host.bounds;+ [view syncSiblings];+}+%end++%ctor {+ if (!SGRedesignedUI() || !SGFlag(SGKeyKaraokeLyrics, NO)) return;+ %init;+ SGRequireClasses(@[@"_TtC32Lyrics_FullscreenElementPageImpl10LyricsView"]);+}diff --git a/tweak/Sources/Redesigned/Lyrics/LyricsPage.x b/tweak/Sources/Redesigned/Lyrics/LyricsPage.xnew file mode 100644index 00000000..d770d72e--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/LyricsPage.x@@ -0,0 +1,59 @@+// The redesign's full screen lyrics page, on glass over the redesigned player, which shows through it:+// the lyrics card under the player reads as having grown to the screen. A copy of+// Native/Lyrics/LyricsPage.x without its switch.+//+// Page (trees/lyrics.txt): a page of its own, presented over the player by a+// _UIOverFullscreenPresentationController, which is why the card's glass stops at the card's edge.+// Tome_PageTemplateImpl paints the template view #121212 and FullscreenView paints itself the+// album colour on top, both opaque; clearing them lets the player's blurred artwork through.+//+// The album colour is the stubborn one: it arrives per track, after the page has laid out, and it+// comes back through a path SGRRepaint.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 "Core/SGCore.h"+#import "Redesigned/Kit/SGRRepaint.h"++static char kPageGlassKey;++// Up to the presentation: the template views in between paint themselves opaque once, at setup.+// Only the chain is cleared, not the subtree -- nothing else on the page is painted.+static UIView *clearAncestors(UIView *view) {+ UIView *top = view;+ for (UIView *v = view; v && ![v isKindOfClass:UIWindow.class]+ && ![NSStringFromClass(v.class) hasPrefix:@"UITransition"]; v = v.superview) {+ v.layer.backgroundColor = NULL;+ top = v;+ }+ return top;+}++%hook _TtC32Lyrics_FullscreenElementPageImpl14FullscreenView+// A colour kept here is re-applied whenever UIKit feels like it, so it is refused outright.+- (void)setBackgroundColor:(UIColor *)color {+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"lyrics page paints itself %@ through UIView", color); });+ %orig(nil);+}++- (void)layoutSubviews {+ %orig;+ UIView *page = (UIView *)self;+ if (page.bounds.size.height < 200) return;++ page.layer.backgroundColor = NULL;+ sgr_lyricsPageRoot = clearAncestors(page);++ UIVisualEffectView *glass = SGGlassFor(page, &kPageGlassKey);+ glass.frame = page.bounds;+ glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ // Full bleed, so the shape is spelled out: a fresh pane does not promise square corners.+ SGShapeGlass(glass, 0, NO);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[@"_TtC32Lyrics_FullscreenElementPageImpl14FullscreenView"]);+}diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.hnew file mode 100644index 00000000..5692ad63--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h@@ -0,0 +1,13 @@+// The redesign's Apple Music style lyrics view, over Spotify's full screen lyrics page (KaraokePage.x)+// and, compact, over the card under the redesigned player (Redesigned/Player/KaraokeCard.x). The+// lines and the clock are Shared/Lyrics/Lyrics.h's.+#import <UIKit/UIKit.h>+#import "Shared/Lyrics/Lyrics.h"++@interface SGRKaraokeView : UIView+// Compact is the card under the player: Spotify's own type size, no seeking by tap and no margin of+// its own, since the card already insets what it holds. initWithFrame: is the full screen page.+- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact;+// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.+- (void)syncSiblings;+@enddiff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mnew file mode 100644index 00000000..644ccef0--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -0,0 +1,744 @@+// The redesign's copy of Native/Lyrics/KaraokeView.m, to be changed for the redesign without touching+// the native look's.+#import "Core/SGCore.h"+#import "SGRKaraokeView.h"+#import "Shared/LyricsSources/LyricsSources.h"+#import "Shared/Player/PlayerEvents.h"++static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;+// The card under the player is a seventh of the page's height, so it gets Spotify's own card type+// size and the spacing its rows sit on, and no blur: at that size the dimming does the work, and a+// blur filter on every line in sight, under the card's glass, made the player stutter as it opened.+static const CGFloat kCardFontSize = 21, kCardMargin = 0, kCardLineGap = 16;+static const CGFloat kDimAlpha = 0.3, kFillEdge = 22, kLift = 2.5, kDimScale = 0.97;+static const CGFloat kAnchor = 0.28; // where the sung line rests, as a share of the height+static const CGFloat kEdgeFade = 0.1; // the lines fade out over this share at the top and bottom+static const CGFloat kBlurPerLine = 1.4, kMaxBlur = 6;+// The (oh, aye) hanging under a line: smaller, a little dimmer, and just clear of it.+static const CGFloat kBackingScale = 0.62, kBackingAlpha = 0.8, kBackingGap = 4;+// The line naming the source, under the lyrics and outside the fade so it does not dim with them.+static const CGFloat kCreditSize = 12, kCreditAlpha = 0.4, kCreditBottom = 10;+static const NSTimeInterval kBrowseHold = 3; // after scrolling by hand, how long until it follows the song again+static const double kFloatMinMs = 700, kFloatLeadMs = 80; // a short word still floats up this slowly+static const double kClockSnapMs = 250, kClockPull = 0.08;+// Lines get views this far outside the visible part, in screen heights: half a screen above it+// and below, and a quarter more before a view is let go. The card under the player is in the tree+// for every open and close of the player, and every view it holds is one more for the window to+// take in and let go; a line comes into view about once in three seconds, and a page flung by+// hand fills in at a few lines a frame.+static const CGFloat kSightBehind = 0.5, kSightAhead = 0.5, kSightSlack = 0.25;+static const NSTimeInterval kTransitionSlack = 0.05; // after the player's animation, before the link is back+static NSString *const kBlurPath = @"filters.gaussianBlur.inputRadius";++@interface CAFilter : NSObject++ (instancetype)filterWithType:(NSString *)type;+@end++static UILabel *wordLabel(NSString *text, UIFont *font, UIColor *color, CGRect frame) {+ UILabel *label = [[UILabel alloc] initWithFrame:frame];+ label.text = text;+ label.font = font;+ label.textColor = color;+ return label;+}++#pragma mark - a word++// The word twice: dim underneath, white on top behind a mask whose feathered edge slides across it.+@interface SGRKaraokeWordView : UIView+@property (nonatomic, readonly) SGKaraokeWord *word;+@property (nonatomic, readonly) UILabel *lit;+@property (nonatomic) CGFloat offset; // where the word starts along its line, rows laid end to end+- (void)fillTo:(CGFloat)cursor;+- (void)floatAt:(double)ms;+- (void)settle;+@end++@implementation SGRKaraokeWordView {+ CAGradientLayer *_fill;+ CGFloat _filled, _lift;+}++- (instancetype)initWithWord:(SGKaraokeWord *)word font:(UIFont *)font {+ CGSize size = [word.text sizeWithAttributes:@{NSFontAttributeName: font}];+ self = [super initWithFrame:CGRectMake(0, 0, ceil(size.width), ceil(font.lineHeight))];+ if (!self) return nil;+ _word = word;+ [self addSubview:wordLabel(word.text, font, [UIColor colorWithWhite:1 alpha:kDimAlpha], self.bounds)];+ _lit = wordLabel(word.text, font, UIColor.whiteColor, self.bounds);+ // Hidden until the line is sung: a masked layer is drawn offscreen every frame even when the+ // mask leaves nothing of it, and a song has hundreds of words waiting their turn.+ _lit.hidden = YES;+ [self addSubview:_lit];++ CGFloat width = self.bounds.size.width + kFillEdge;+ _fill = [CAGradientLayer layer];+ _fill.colors = @[(id)UIColor.whiteColor.CGColor, (id)UIColor.whiteColor.CGColor, (id)UIColor.clearColor.CGColor];+ _fill.locations = @[@0, @((width - kFillEdge) / width), @1];+ _fill.startPoint = CGPointMake(0, 0.5);+ _fill.endPoint = CGPointMake(1, 0.5);+ _lit.layer.mask = _fill;+ _filled = NAN;+ [self fillTo:-CGFLOAT_MAX];+ return self;+}++// The cursor is in line units and the feathered edge is centred on it, so the edge runs on through+// the space into the next word instead of starting over at each one.+- (void)fillTo:(CGFloat)cursor {+ CGFloat width = self.bounds.size.width, height = self.bounds.size.height;+ CGFloat local = MAX(-kFillEdge / 2, MIN(width + kFillEdge / 2, cursor - _offset));+ if (local == _filled) return;+ _filled = local;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _fill.frame = CGRectMake(local - kFillEdge / 2 - width, -height / 2, width + kFillEdge, height * 2);+ [CATransaction commit];+}++// Rises like a critically damped spring let go as the word starts: no jolt, a long soft landing.+// x = 5 at the end of the word is 96 % of the way up.+- (void)floatAt:(double)ms {+ double x = MAX(0, ms - _word.start + kFloatLeadMs) / MAX(_word.end - _word.start, kFloatMinMs) * 5;+ CGFloat lift = kLift * (1 - (1 + x) * exp(-x));+ if (lift == _lift) return;+ _lift = lift;+ self.transform = CGAffineTransformMakeTranslation(0, -lift);+}++- (void)settle {+ _lift = 0;+ self.transform = CGAffineTransformIdentity;+}++@end++#pragma mark - a line++@interface SGRKaraokeLineView : UIView+@property (nonatomic, readonly) SGKaraokeLine *line;+@property (nonatomic) BOOL active;+@property (nonatomic) CGFloat blur;+- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width font:(UIFont *)font backing:(BOOL)backing blurred:(BOOL)blurred;+- (void)showTime:(double)ms;+@end++typedef struct {+ double ms, x, slope;+} SGSweepKnot;++@implementation SGRKaraokeLineView {+ NSArray<SGRKaraokeWordView *> *_words;+ NSUInteger _generation;+ SGSweepKnot *_knots;+ NSUInteger _knotCount;+ SGRKaraokeLineView *_backing;+}++- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width font:(UIFont *)font backing:(BOOL)backing blurred:(BOOL)blurred {+ self = [super initWithFrame:CGRectZero];+ if (!self) return nil;+ _line = line;+ CGFloat space = ceil([@" " sizeWithAttributes:@{NSFontAttributeName: font}].width);+ CGFloat row = ceil(font.lineHeight) - kRowTighten, x = 0, y = 0, offset = 0;+ NSMutableArray<SGRKaraokeWordView *> *words = [NSMutableArray array];+ NSMutableArray<NSMutableArray<SGRKaraokeWordView *> *> *rows = [NSMutableArray arrayWithObject:[NSMutableArray array]];+ for (SGKaraokeWord *word in line.words) {+ SGRKaraokeWordView *view = [[SGRKaraokeWordView alloc] initWithWord:word font:font];+ CGSize size = view.bounds.size;+ // A joined word follows the one before it flush: the scripts that do not space their words+ // would otherwise read with a gap between every syllable.+ CGFloat lead = x > 0 && !word.joined ? space : 0;+ if (x > 0 && x + lead + size.width > width) {+ x = lead = 0;+ y += row;+ [rows addObject:[NSMutableArray array]];+ }+ x += lead;+ offset += lead;+ view.center = CGPointMake(x + size.width / 2, y + size.height / 2);+ view.offset = offset;+ x += size.width;+ offset += size.width;+ [self addSubview:view];+ [words addObject:view];+ [rows.lastObject addObject:view];+ }+ // A second voice is laid against the far edge, as Apple Music sets the two sides of a duet apart.+ if (line.align == SGKaraokeAlignTrailing) {+ for (NSArray<SGRKaraokeWordView *> *wrapped in rows) {+ if (!wrapped.count) continue;+ CGFloat shift = width - CGRectGetMaxX(wrapped.lastObject.frame);+ if (shift <= 0) continue;+ for (SGRKaraokeWordView *view in wrapped) view.center = CGPointMake(view.center.x + shift, view.center.y);+ }+ }+ _words = words;++ CGFloat height = y + ceil(font.lineHeight);+ if (line.backing.words.count && !backing) {+ UIFont *smaller = [UIFont systemFontOfSize:round(font.pointSize * kBackingScale) weight:UIFontWeightBold];+ _backing = [[SGRKaraokeLineView alloc] initWithLine:line.backing width:width font:smaller backing:YES blurred:NO];+ _backing.alpha = kBackingAlpha;+ _backing.frame = CGRectMake(0, height + kBackingGap, width, _backing.bounds.size.height);+ [self addSubview:_backing];+ height = CGRectGetMaxY(_backing.frame);+ }+ self.frame = CGRectMake(0, 0, width, height);+ [self buildSweep];++ // Scales toward the edge its text is aligned to, and a backing row rides its line's blur.+ if (backing) return self;+ self.layer.anchorPoint = CGPointMake(line.align == SGKaraokeAlignTrailing ? 1 : 0, 0.5);+ if (!blurred) return self;+ CAFilter *blur = [NSClassFromString(@"CAFilter") filterWithType:@"gaussianBlur"];+ if (blur) self.layer.filters = @[blur];+ return self;+}++// The height a line takes at a width, its rows counted the way initWithLine:width:font:backing:blurred:+// lays them, so the page can place every line of a song while making views for the few in sight.+static CGFloat lineHeight(SGKaraokeLine *line, CGFloat width, UIFont *font, BOOL backing) {+ CGFloat space = ceil([@" " sizeWithAttributes:@{NSFontAttributeName: font}].width);+ CGFloat row = ceil(font.lineHeight) - kRowTighten, x = 0, y = 0;+ for (SGKaraokeWord *word in line.words) {+ CGFloat wordWidth = ceil([word.text sizeWithAttributes:@{NSFontAttributeName: font}].width);+ CGFloat lead = x > 0 && !word.joined ? space : 0;+ if (x > 0 && x + lead + wordWidth > width) {+ x = lead = 0;+ y += row;+ }+ x += lead + wordWidth;+ }+ CGFloat height = y + ceil(font.lineHeight);+ if (line.backing.words.count && !backing) {+ UIFont *smaller = [UIFont systemFontOfSize:round(font.pointSize * kBackingScale) weight:UIFontWeightBold];+ height += kBackingGap + lineHeight(line.backing, width, smaller, YES);+ }+ return height;+}++// Where each line starts in the stack, from the heights alone. Measuring text is safe off the main+// thread, and a song's worth of it is kept off it: the first card of a track lays out while the+// player is opening, and a frame that measured every line then was a frame the animation lost.+static NSArray<NSNumber *> *topsOf(NSArray<SGKaraokeLine *> *lines, CGFloat width, UIFont *font, CGFloat gap) {+ NSMutableArray<NSNumber *> *tops = [NSMutableArray arrayWithCapacity:lines.count];+ CGFloat top = 0;+ for (SGKaraokeLine *line in lines) {+ [tops addObject:@(top)];+ top += lineHeight(line, width, font, NO) + gap;+ }+ return tops;+}++// How many line views are made in one frame: the rest follow on the next, nearest the sung line first.+static const NSUInteger kLinesPerFrame = 4;++- (void)dealloc {+ free(_knots);+}++static double secant(SGSweepKnot *knots, NSUInteger i) {+ return (knots[i + 1].x - knots[i].x) / (knots[i + 1].ms - knots[i].ms);+}++// The fill cursor reaches each word's left edge as the word starts and clears the last word as it+// ends, on a monotone cubic through those points, so the pace changes between words without a kink.+- (void)buildSweep {+ _knots = calloc(_words.count + 1, sizeof(SGSweepKnot));+ if (!_words.count) return;+ for (NSUInteger i = 0; i <= _words.count; i++) {+ SGRKaraokeWordView *word = _words[MIN(i, _words.count - 1)];+ double ms = i < _words.count ? word.word.start : word.word.end;+ double x = i == 0 ? -kFillEdge / 2 : i < _words.count ? word.offset : word.offset + word.bounds.size.width + kFillEdge / 2;+ if (_knotCount && ms <= _knots[_knotCount - 1].ms) {+ _knots[_knotCount - 1].x = x;+ continue;+ }+ _knots[_knotCount++] = (SGSweepKnot){ms, x, 0};+ }+ // Fritsch-Carlson slopes: capped so the cursor never runs backwards or overshoots a word.+ for (NSUInteger k = 0; k < _knotCount; k++) {+ BOOL first = k == 0, last = k + 1 == _knotCount;+ if (first && last) break;+ if (first || last) {+ _knots[k].slope = secant(_knots, first ? 0 : k - 1);+ continue;+ }+ double before = secant(_knots, k - 1), after = secant(_knots, k);+ double h0 = _knots[k].ms - _knots[k - 1].ms, h1 = _knots[k + 1].ms - _knots[k].ms;+ _knots[k].slope = MIN(MIN(2 * before, 2 * after), (before * h1 + after * h0) / (h0 + h1));+ }+}++- (CGFloat)cursorAt:(double)ms {+ if (!_knotCount) return -CGFLOAT_MAX;+ if (ms <= _knots[0].ms) return _knots[0].x;+ if (_knotCount == 1 || ms >= _knots[_knotCount - 1].ms) return _knots[_knotCount - 1].x;+ NSUInteger k = 0;+ while (ms >= _knots[k + 1].ms) k++;+ SGSweepKnot a = _knots[k], b = _knots[k + 1];+ double h = b.ms - a.ms, u = (ms - a.ms) / h, u2 = u * u, u3 = u2 * u;+ return (2 * u3 - 3 * u2 + 1) * a.x + (u3 - 2 * u2 + u) * h * a.slope+ + (3 * u2 - 2 * u3) * b.x + (u3 - u2) * h * b.slope;+}++// Eases from wherever the blur is on screen, so a line coming into focus sharpens instead of snapping.+- (void)setBlur:(CGFloat)blur {+ if (blur == _blur) return;+ id shown = [self.layer.presentationLayer valueForKeyPath:kBlurPath];+ CGFloat from = [shown isKindOfClass:NSNumber.class] ? [shown doubleValue] : _blur;+ _blur = blur;+ if (!self.layer.filters) return;+ [self.layer setValue:@(blur) forKeyPath:kBlurPath];+ CABasicAnimation *ease = [CABasicAnimation animationWithKeyPath:kBlurPath];+ ease.fromValue = @(from);+ ease.toValue = @(blur);+ ease.duration = 0.6;+ ease.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];+ [self.layer addAnimation:ease forKey:@"blur"];+}++- (void)setActive:(BOOL)active {+ if (active == _active) return;+ _active = active;+ _backing.active = active;+ NSUInteger generation = ++_generation;+ if (active) {+ for (SGRKaraokeWordView *word in _words) {+ [word.layer removeAllAnimations];+ [word.lit.layer removeAllAnimations];+ word.lit.alpha = 1;+ word.lit.hidden = NO;+ [word fillTo:-CGFLOAT_MAX];+ [word settle];+ }+ return;+ }+ // A sung line fades back to dim rather than dropping its fill at once, and its words sink back+ // on a spring slow enough to still be seen doing it.+ [UIView animateWithDuration:0.9 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0+ options:UIViewAnimationOptionAllowUserInteraction+ animations:^{+ for (SGRKaraokeWordView *word in self->_words) [word settle];+ } completion:nil];+ [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{+ for (SGRKaraokeWordView *word in self->_words) word.lit.alpha = 0;+ } completion:^(BOOL finished) {+ if (generation != self->_generation) return;+ for (SGRKaraokeWordView *word in self->_words) {+ [word fillTo:-CGFLOAT_MAX];+ word.lit.hidden = YES;+ word.lit.alpha = 1;+ }+ }];+}++- (void)showTime:(double)ms {+ CGFloat cursor = [self cursorAt:ms];+ for (SGRKaraokeWordView *word in _words) {+ [word fillTo:cursor];+ [word floatAt:ms];+ }+ [_backing showTime:ms]; // timed on its own, so it lags the line as it is sung+}++@end++#pragma mark - the page++@interface SGRKaraokeView () <UIScrollViewDelegate>+@end++@implementation SGRKaraokeView {+ UIScrollView *_scroll;+ BOOL _browsing;+ CADisplayLink *_link;+ NSString *_track;+ NSArray<SGKaraokeLine *> *_lines;+ // The song is placed from its lines' heights alone; views exist for the lines in and near sight.+ NSArray<NSNumber *> *_tops; // where each line starts in the stack+ NSMutableDictionary<NSNumber *, SGRKaraokeLineView *> *_shown; // the views there are, by line+ CGFloat _focusTop; // the top of the line the stack is arranged around+ CGFloat _sightOffset, _sightFocus; // what the views in sight were last chosen for+ NSInteger _sightActive;+ NSUInteger _build; // counts the songs and widths measured, so a measurement that is late is dropped+ UIFont *_font;+ NSInteger _active;+ CGFloat _builtWidth;+ BOOL _showing;+ CAGradientLayer *_fade;+ UILabel *_credit;+ CGFloat _fontSize, _margin, _lineGap, _blurPerLine, _maxBlur;+ BOOL _compact;+ BOOL _crediting; // the switch is read once: the page asks for the source on every frame until it has one+ double _clock;+ NSInteger _reported;+ CFTimeInterval _clockTime;+}++- (instancetype)initWithFrame:(CGRect)frame {+ return [self initWithFrame:frame compact:NO];+}++- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact {+ self = [super initWithFrame:frame];+ if (!self) return nil;+ self.hidden = YES;+ _active = -1;+ _compact = compact;+ _fontSize = compact ? kCardFontSize : kFontSize;+ _margin = compact ? kCardMargin : kMargin;+ _lineGap = compact ? kCardLineGap : kLineGap;+ _blurPerLine = compact ? 0 : kBlurPerLine;+ _maxBlur = compact ? 0 : kMaxBlur;+ _shown = [NSMutableDictionary dictionary];+ _sightActive = -2;+ _fade = [CAGradientLayer layer];+ _fade.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.whiteColor.CGColor,+ (id)UIColor.whiteColor.CGColor, (id)UIColor.clearColor.CGColor];+ _fade.locations = @[@0, @(kEdgeFade), @(1 - kEdgeFade), @1];+ _scroll = [[UIScrollView alloc] initWithFrame:self.bounds];+ _scroll.layer.mask = _fade;+ _scroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ _scroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;+ _scroll.showsVerticalScrollIndicator = NO;+ _scroll.alwaysBounceVertical = YES;+ _scroll.scrollsToTop = NO;+ _scroll.delegate = self;+ [self addSubview:_scroll];+ _credit = [[UILabel alloc] initWithFrame:CGRectZero];+ _credit.font = [UIFont systemFontOfSize:kCreditSize weight:UIFontWeightSemibold];+ _credit.textColor = [UIColor colorWithWhite:1 alpha:kCreditAlpha];+ _credit.hidden = YES;+ _crediting = !compact && SGFlag(SGKeyLyricsCredit, NO); // the card has no room to name a source+ [self addSubview:_credit];+ // A tap on the card is Spotify's, and opens the full screen page; seeking by tap is the page's.+ if (compact) self.userInteractionEnabled = NO;+ else [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionNotification object:nil];+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionEndedNotification object:nil];+ return self;+}++- (void)dealloc {+ [NSNotificationCenter.defaultCenter removeObserver:self];+}++- (void)tapped:(UITapGestureRecognizer *)tap {+ CGPoint point = [tap locationInView:_scroll];+ for (SGRKaraokeLineView *view in _shown.allValues) {+ if (!CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), point)) continue;+ SGKaraokeSeek(view.line.start);+ [self followSong];+ return;+ }+}++#pragma mark - scrolling by hand++// Lines are placed for a content offset of 0, so following the song means scrolling back to 0.+// While the user browses, placement stands still and every line is sharp.+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(followSong) object:nil];+ _browsing = YES;+ for (SGRKaraokeLineView *view in _shown.allValues) view.blur = 0;+}++- (void)scrollViewDidScroll:(UIScrollView *)scrollView {+ [self showLinesInSight];+}++- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {+ if (!decelerate) [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];+}++- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {+ [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];+}++- (void)followSong {+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(followSong) object:nil];+ if (!_browsing) return;+ _browsing = NO;+ [UIView animateWithDuration:0.7 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:0+ options:UIViewAnimationOptionAllowUserInteraction+ animations:^{ self->_scroll.contentOffset = CGPointZero; } completion:nil];+ [self placeLinesAnimated:YES];+}++- (void)didMoveToWindow {+ [super didMoveToWindow];+ if (!self.window) {+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(followSong) object:nil];+ _browsing = NO;+ }+ [self scheduleLink];+}++// The player opens and closes in animations that run at 120 Hz, and while a display link asked+// for 30 to 60, the range Apple's ProMotion guide says Core Animation gives priority to, those+// animations ran rough; the player and the lyrics themselves were smooth throughout. The card's+// link now asks for 60 but takes 120, and is put down for as long as the player animates, which+// NowPlayingBar.x announces as each animation starts and again as it ends; the card holds still+// under it, where nobody sees it. The timer is for an end that is never announced.+- (void)scheduleLink {+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startLink) object:nil];+ [_link invalidate];+ _link = nil;+ if (!self.window) return;+ NSTimeInterval wait = SGPlayerTransitionEnds() - CACurrentMediaTime();+ if (wait <= 0) [self startLink];+ else [self performSelector:@selector(startLink) withObject:nil afterDelay:wait + kTransitionSlack inModes:@[NSRunLoopCommonModes]];+}++- (void)startLink {+ if (!self.window || _link) return;+ _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick)];+ // The card stays in the window behind the full screen page, so both sweep at once; the card is+ // a few lines tall and is content with 60, the page keeps the high refresh rate.+ _link.preferredFrameRateRange = _compact ? CAFrameRateRangeMake(30, 120, 60) : CAFrameRateRangeMake(80, 120, 120);+ [_link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];+}++- (void)playerTransitionChanged:(NSNotification *)note {+ [self scheduleLink];+}++// The mask sits in the scroll view's own coordinates, which move with the content as it scrolls, so+// it is put back over the visible part on every frame, where the presentation layer says the+// content is: that holds through a drag and through the animated scroll home alike. Left where+// layout put it, it covered the first screenful of lines only, and a scroll past them showed nothing.+- (void)alignFade {+ CALayer *shown = (CALayer *)_scroll.layer.presentationLayer ?: _scroll.layer;+ CGRect frame = CGRectMake(0, shown.bounds.origin.y, self.bounds.size.width, self.bounds.size.height);+ if (CGRectEqualToRect(frame, _fade.frame)) return;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _fade.frame = frame;+ [CATransaction commit];+}++- (void)layoutSubviews {+ [super layoutSubviews];+ [self alignFade];+ _scroll.contentSize = self.bounds.size;+ [_credit sizeToFit];+ _credit.frame = CGRectMake(_margin, self.bounds.size.height - _credit.bounds.size.height - kCreditBottom,+ _credit.bounds.size.width, _credit.bounds.size.height);+ if (_lines && self.bounds.size.width != _builtWidth) [self rebuild];+}++- (void)dropLineViews {+ for (UIView *view in _shown.allValues) [view removeFromSuperview];+ [_shown removeAllObjects];+ _tops = nil;+ _sightActive = -2;+ _build++;+}++// Measures the song for the width and, once that is in, places it; Spotify's own lines stay in view+// until then, since the page shows nothing of its own before it has lines to show.+- (void)rebuild {+ [self dropLineViews];+ _active = -1;+ _browsing = NO;+ _scroll.contentOffset = CGPointZero;+ _builtWidth = self.bounds.size.width;+ CGFloat width = _builtWidth - 2 * _margin;+ if (width <= 0) return;+ _font = [UIFont systemFontOfSize:_fontSize weight:UIFontWeightBold];+ UIFont *font = _font;+ NSArray<SGKaraokeLine *> *lines = _lines;+ CGFloat gap = _lineGap;+ NSUInteger build = _build;+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{+ NSArray<NSNumber *> *tops = topsOf(lines, width, font, gap);+ dispatch_async(dispatch_get_main_queue(), ^{+ if (build != self->_build) return; // the song or the width moved on meanwhile+ self->_tops = tops;+ [self placeLinesAnimated:NO];+ });+ });+}++// Where a line starts on the page, for the stack as it is arranged now.+- (CGFloat)topOfLine:(NSInteger)index {+ return self.bounds.size.height * kAnchor + _tops[index].doubleValue - _focusTop;+}++// The view of a line, made the first time it is asked for and placed where the stack has it.+- (SGRKaraokeLineView *)viewForLine:(NSInteger)index {+ SGRKaraokeLineView *view = _shown[@(index)];+ if (view || !_tops || index < 0 || index >= (NSInteger)_tops.count) return view;+ view = [[SGRKaraokeLineView alloc] initWithLine:_lines[index] width:_builtWidth - 2 * _margin font:_font backing:NO blurred:_maxBlur > 0];+ [_scroll addSubview:view];+ _shown[@(index)] = view;+ [self placeLine:view at:index animated:NO];+ return view;+}++// Views for the lines just outside the visible part as well as in it, wherever that is: around the+// sung line while following the song, around wherever the page has been scrolled to while browsing.+// The ones further off are let go, so a long song costs a couple of dozen line views rather than+// one for every line, and the lines in sight are the only ones the compositor has to draw.+- (void)showLinesInSight {+ if (!_tops.count) return;+ CGFloat offset = ((CALayer *)_scroll.layer.presentationLayer ?: _scroll.layer).bounds.origin.y;+ if (offset == _sightOffset && _focusTop == _sightFocus && _active == _sightActive) return;+ _sightOffset = offset;+ _sightFocus = _focusTop;+ _sightActive = _active;+ CGFloat height = self.bounds.size.height;+ CGFloat from = offset - kSightBehind * height, to = offset + (1 + kSightAhead) * height, slack = kSightSlack * height;+ NSMutableArray<NSNumber *> *gone = [NSMutableArray array];+ for (NSNumber *key in _shown) {+ NSInteger index = key.integerValue;+ CGFloat top = [self topOfLine:index], bottom = top + _shown[key].bounds.size.height;+ if (index != _active && (bottom < from - slack || top > to + slack)) [gone addObject:key];+ }+ for (NSNumber *key in gone) {+ [_shown[key] removeFromSuperview];+ [_shown removeObjectForKey:key];+ }+ NSInteger count = (NSInteger)_tops.count;+ NSMutableArray<NSNumber *> *wanted = [NSMutableArray array];+ for (NSInteger index = 0; index < count; index++) {+ if (_shown[@(index)]) continue;+ CGFloat top = [self topOfLine:index];+ CGFloat bottom = index + 1 < count ? [self topOfLine:index + 1] - _lineGap : top + height;+ if (bottom < from || top > to) continue;+ [wanted addObject:@(index)];+ }+ // A few a frame, the nearest the middle of the visible part first, so a page scrolled by hand+ // fills in what is in view before what is not; the next frame picks up where this one left off.+ CGFloat middle = offset + height / 2;+ [wanted sortUsingComparator:^NSComparisonResult(NSNumber *a, NSNumber *b) {+ CGFloat da = fabs([self topOfLine:a.integerValue] - middle), db = fabs([self topOfLine:b.integerValue] - middle);+ return da < db ? NSOrderedAscending : da > db ? NSOrderedDescending : NSOrderedSame;+ }];+ NSUInteger made = 0;+ for (NSNumber *index in wanted) {+ if (made++ == kLinesPerFrame) {+ _sightOffset = -CGFLOAT_MAX;+ break;+ }+ [self viewForLine:index.integerValue];+ }+}++// One line's place in the stack: the anchor sits on the edge its text is aligned to, so it scales+// toward its own text, and it dims and blurs with its distance from the sung line.+- (void)placeLine:(SGRKaraokeLineView *)view at:(NSInteger)index animated:(BOOL)animated {+ CGFloat height = self.bounds.size.height;+ NSInteger distance = index - _active;+ CGRect frame = CGRectMake(_margin, [self topOfLine:index], view.bounds.size.width, view.bounds.size.height);+ BOOL trailing = view.line.align == SGKaraokeAlignTrailing;+ CGPoint center = CGPointMake(trailing ? CGRectGetMaxX(frame) : _margin, CGRectGetMidY(frame));+ CGFloat scale = distance == 0 ? 1 : kDimScale;+ CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);+ view.blur = distance == 0 || _browsing ? 0 : MIN(_maxBlur, labs(distance) * _blurPerLine);+ BOOL near = CGRectIntersectsRect(CGRectInset(self.bounds, 0, -height / 2), frame)+ || CGRectIntersectsRect(CGRectInset(self.bounds, 0, -height / 2), view.frame);+ if (!animated || !near) {+ view.center = center;+ view.transform = transform;+ return;+ }+ NSTimeInterval delay = distance > 0 ? MIN(0.3, distance * 0.04) : 0;+ [UIView animateWithDuration:0.7 delay:delay usingSpringWithDamping:0.86 initialSpringVelocity:0+ options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction+ animations:^{+ view.center = center;+ view.transform = transform;+ } completion:nil];+}++// The sung line rests at the anchor and the rest stack around it; lines below it follow a beat+// later, the further down the later, as Apple Music's do.+- (void)placeLinesAnimated:(BOOL)animated {+ if (_browsing || !_tops.count) return;+ _focusTop = _tops[(NSUInteger)MAX(_active, 0)].doubleValue;+ [self showLinesInSight];+ for (NSNumber *key in _shown) [self placeLine:_shown[key] at:key.integerValue animated:animated];+ // Room to scroll until the first line or the last one reaches the anchor.+ CGFloat lastTop = _tops.lastObject.doubleValue;+ _scroll.contentInset = UIEdgeInsetsMake(_focusTop, 0, MAX(0, lastTop - _focusTop), 0);+}++- (void)creditTo:(NSString *)source {+ NSString *text = source.length && _crediting ? [NSString stringWithFormat:@"Lyrics from %@", source] : nil;+ if (text == _credit.text || [text isEqualToString:_credit.text]) return;+ _credit.text = text;+ _credit.hidden = !_showing || !text.length;+ [self setNeedsLayout];+}++- (void)syncSiblings {+ for (UIView *sibling in self.superview.subviews) {+ if (sibling != self && _showing) sibling.alpha = 0;+ }+}++- (void)setShowing:(BOOL)showing {+ if (showing == _showing) return;+ _showing = showing;+ self.hidden = !showing;+ _credit.hidden = !showing || !_credit.text.length;+ for (UIView *sibling in self.superview.subviews) {+ if (sibling != self) sibling.alpha = showing ? 0 : 1;+ }+}++// The player's position run on by the frame times the display will show and eased toward each new+// reading, so the sweep follows neither the callback's jitter nor the small jumps of the core's+// corrections. A seek or a new track is too far off to ease and is taken at once.+- (double)clockMs {+ NSInteger raw = SGKaraokePositionMs();+ CFTimeInterval shown = _link.targetTimestamp;+ BOOL running = raw != _reported; // a paused player reports the same position every frame+ double reported = raw + (running ? (shown - CACurrentMediaTime()) * 1000 : 0);+ double predicted = _clock + (running ? (shown - _clockTime) * 1000 : 0);+ double error = reported - predicted;+ _clock = raw < 0 || fabs(error) > kClockSnapMs ? reported : predicted + error * kClockPull;+ _reported = raw;+ _clockTime = shown;+ return _clock;+}++- (void)tick {+ NSString *track = SGKaraokePlayingTrack();+ if (!(track == _track || [track isEqualToString:_track])) {+ SGLog(@"karaoke: page shows track %@, lyrics %@", track, SGKaraokeLinesForTrack(track) ? @"captured" : @"not captured yet");+ _track = track;+ _lines = nil;+ _builtWidth = 0;+ [self creditTo:nil];+ [self dropLineViews];+ }+ if (!_lines && track && (_lines = SGKaraokeLinesForTrack(track))) {+ SGLog(@"karaoke: showing %lu lines of %@", (unsigned long)_lines.count, track);+ [self setNeedsLayout];+ }+ [self setShowing:_tops != nil];+ // The source is settled a moment after the lines are, so it is asked for until it answers.+ if (_crediting && _lines && !_credit.text.length) [self creditTo:SGLyricsCreditFor(track)];+ if (!_tops) return;+ [self alignFade];++ double now = [self clockMs];+ NSInteger active = -1;+ for (NSUInteger i = 0; i < _lines.count && _lines[i].start <= now; i++) active = i;+ if (active != _active) {+ if (_active >= 0) _shown[@(_active)].active = NO;+ if (active >= 0) [self viewForLine:active].active = YES;+ BOOL jump = labs(active - _active) > 2; // a seek, not the song moving on+ _active = active;+ [self placeLinesAnimated:!jump];+ } else {+ [self showLinesInSight]; // the page may be scrolling by hand, or springing back+ }+ if (active >= 0) [_shown[@(active)] showTime:now];+}++@enddiff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hnew file mode 100644index 00000000..4e3f60d2--- /dev/null+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -0,0 +1,27 @@+// The redesign's navbar: the glass tab bar (TabBar.x) over Spotify's own, composed from its own list+// (Navbar.x, NavbarLayout.m), which the redesign keeps apart from the native look's: 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 SGRKeyNavbar @"spotifyglass.redesign.navbar"++extern NSString *const SGRNavbarID; // NSString, the entry's identity+extern NSString *const SGRNavbarTitle; // NSString, the name in the settings list and under the icon+extern NSString *const SGRNavbarURI; // NSString, the mod's own tabs only: what a tap opens+extern NSString *const SGRNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts"+extern NSString *const SGRNavbarHidden; // NSNumber+NSArray<NSDictionary *> *SGRNavbarLayout(void);+void SGRSetNavbarLayout(NSArray<NSDictionary *> *layout);+// Spotify's own tabs in Spotify's order, as Navbar.x last saw them on the bar.+NSArray<NSString *> *SGRNavbarStock(void);+void SGRSetNavbarStock(NSArray<NSString *> *stock);++// Navbar.x, called from the tab bar's layout passes in TabBar.x.+void SGRComposeTabBar(UIView *tabBar);+void SGRLogTabBarRow(UIView *tabBar);+// Lays the bar out again after the Navbar page changes something, so it does not wait for a touch.+void SGRRefreshTabBar(void);++UIViewController *SGRNavbarSettingsPage(void); // the tab editor, in Mod Settings+UIViewController *SGRNavbarEditorPage(void); // the tab editor alone, for the welcome tourdiff --git a/tweak/Sources/Redesigned/Navbar/Navbar.x b/tweak/Sources/Redesigned/Navbar/Navbar.xnew file mode 100644index 00000000..a781eeef--- /dev/null+++ b/tweak/Sources/Redesigned/Navbar/Navbar.x@@ -0,0 +1,375 @@+// The redesign's copy of Native/Navbar/Navbar.x, composing the row the glass tab bar mirrors.+// Navbar: which tabs the bar shows, in what order, and tabs of the mod's own that open any+// spotify: URI. Spotify keeps its four items (Home, Search, Library, Create) as the arranged+// subviews of one stack view, but a tap on one of them is answered by counting the row off from+// the left, not by asking the item what it is: moved in the stack, an item takes the tap of+// whatever used to stand there. So the stack's own order is left exactly as Spotify built it.+//+// The row is split into equal slots instead, and each item is given the frame of its slot after+// the stack's own pass: hit testing goes by frame, so the touch follows the icon, while Spotify+// still counts its items off in the order it put them in. Items of the mod's own go on the end of+// the stack, past that count, and take a slot with the rest. A tap on one goes through Spotify's+// link dispatcher, the same route the app takes for a link it opens itself, so any URI works.+//+// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView+// 402x49 of four ElementContentView<TabBarItemElement> 100x49, each an SPTEncoreIconView 24x24+// at y 12.5 over an SPTEncoreLabel at y 35.+#import "Core/SGCore.h"+#import "Navbar.h"+#import "Headers/SPTEncoreIconView.h"+#import "Shared/Navigation/Links.h"+#import <objc/message.h>++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, so an item of+// the mod's own sits on the same line as its neighbours.+static CGRect sg_iconBox = {{0, kIconTop}, {kIconSize, kIconSize}};+static CGRect sg_labelBox = {{0, kLabelTop}, {0, kLabelHeight}};++static __weak UIView *sg_navbarRoot;+// The bar's row of items, given its frames by placeRow after each of its own passes.+static __weak UIStackView *sg_row;+static UIFont *sg_tabFont;+// Spotify's own tabs in Spotify's order, from the first layout pass of this launch, before+// anything below has moved them.+static NSMutableArray<NSString *> *sg_stockOrder;++static UIColor *itemColor(void) { return [UIColor colorWithWhite:0xB3 / 255.0 alpha:1]; }++#pragma mark - the mod's own items++// One of the 538 glyphs SPTEncoreIcon exposes, one class method each ("podcasts", "heart"), so an+// item of the mod's own is drawn the same way as Spotify's. An SF Symbol stands in if the name is+// not one of them.+static UIView *iconView(NSString *name) {+ Class icon = NSClassFromString(@"SPTEncoreIcon");+ Class view = NSClassFromString(@"SPTEncoreIconView");+ SEL glyphSel = NSSelectorFromString(name.length ? name : @"star");+ if (icon && view && [icon respondsToSelector:glyphSel]) {+ id (*glyphFor)(id, SEL) = (id (*)(id, SEL))objc_msgSend;+ id glyph = glyphFor(icon, glyphSel);+ SPTEncoreIconView *encore = glyph ? [[view alloc] initWithIcon:glyph] : nil;+ if (encore) {+ [encore setForegroundColor:itemColor()];+ return encore;+ }+ }+ UIImage *image = [UIImage systemImageNamed:@"star.fill" withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:19 weight:UIImageSymbolWeightSemibold]];+ UIImageView *fallback = [[UIImageView alloc] initWithImage:image];+ fallback.tintColor = itemColor();+ fallback.contentMode = UIViewContentModeCenter;+ return fallback;+}++@interface SGRTabItemView : UIControl+@property (nonatomic, copy) NSString *uri;+- (instancetype)initWithEntry:(NSDictionary *)entry;+- (void)applyEntry:(NSDictionary *)entry;+@end++@implementation SGRTabItemView {+ NSString *_iconName;+ UIView *_icon;+ UILabel *_title;+}++- (instancetype)initWithEntry:(NSDictionary *)entry {+ if (!(self = [super initWithFrame:CGRectZero])) return nil;+ _title = [UILabel new];+ _title.textAlignment = NSTextAlignmentCenter;+ _title.textColor = itemColor();+ [self addSubview:_title];+ [self applyEntry:entry];+ [self addTarget:self action:@selector(open) forControlEvents:UIControlEventTouchUpInside];+ return self;+}++- (void)applyEntry:(NSDictionary *)entry {+ self.uri = entry[SGRNavbarURI];+ _title.text = entry[SGRNavbarTitle];+ NSString *name = entry[SGRNavbarIcon] ?: @"star";+ if ([name isEqualToString:_iconName]) return;+ [_icon removeFromSuperview];+ _iconName = [name copy];+ _icon = iconView(name);+ // Encore's views lay themselves out from constraints; this one is placed by frame.+ _icon.translatesAutoresizingMaskIntoConstraints = YES;+ [self addSubview:_icon];+}++// Both boxes come off a neighbour, so whatever Spotify 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];+ CGFloat width = self.bounds.size.width;+ // The glass bar of TabBar.x draws the names; the hidden row keeps its icons for the glyphs.+ _title.hidden = YES;+ _title.font = sg_tabFont ?: [UIFont systemFontOfSize:10];+ _title.frame = CGRectMake(0, CGRectGetMinY(sg_labelBox), width, CGRectGetHeight(sg_labelBox));+ _icon.frame = CGRectMake((width - CGRectGetWidth(sg_iconBox)) / 2, CGRectGetMinY(sg_iconBox),+ CGRectGetWidth(sg_iconBox), CGRectGetHeight(sg_iconBox));+}++// A row that splits its width evenly ignores this, but one that sizes itself to its content would+// otherwise have nothing to go on for an item of ours.+- (CGSize)intrinsicContentSize {+ return CGSizeMake(kIconSize * 2, kLabelTop + kLabelHeight);+}++- (void)setHighlighted:(BOOL)highlighted {+ [super setHighlighted:highlighted];+ self.alpha = highlighted ? 0.5 : 1;+}++// Through the app's own link dispatcher (Shared/Navigation/Links.h).+- (void)open {+ NSURL *url = self.uri.length ? [NSURL URLWithString:self.uri] : nil;+ if (!SGOpenSpotifyURI(url)) SGLog(@"navbar: cannot open %@, dispatcher %@", self.uri, SGLinkDispatcher());+}++@end++#pragma mark - composition++// Spotify's items are told apart by the label under the icon: it survives the element views being+// rebuilt, and it is the name the Navbar page lists them under.+static NSString *stockID(UIView *item) {+ __block NSString *text = nil;+ SGForEachView(item, ^(UIView *v) {+ if (!text && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) text = ((UILabel *)v).text;+ });+ return text ?: NSStringFromClass(item.class);+}++static void measureItem(UIView *item) {+ __block UIView *icon = nil, *label = nil;+ SGForEachView(item, ^(UIView *v) {+ if (!icon && [NSStringFromClass(v.class) containsString:@"IconView"] && v.bounds.size.width > 1) icon = v;+ if (!label && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) label = v;+ });+ if (icon) sg_iconBox = SGFrameIn(icon, item);+ if (!label) return;+ sg_labelBox = SGFrameIn(label, item);+ if (!sg_tabFont) sg_tabFont = ((UILabel *)label).font;+}++static NSMutableDictionary<NSString *, SGRTabItemView *> *customItems(UIStackView *stack) {+ NSMutableDictionary *items = objc_getAssociatedObject(stack, &kCustomKey);+ if (!items) {+ items = [NSMutableDictionary dictionary];+ objc_setAssociatedObject(stack, &kCustomKey, items, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ return items;+}++void SGRComposeTabBar(UIView *tabBar) {+ UIStackView *stack = SGRowIn(tabBar);+ if (!stack) return;+ sg_navbarRoot = tabBar;++ NSMutableDictionary<NSString *, UIView *> *stockViews = [NSMutableDictionary dictionary];+ for (UIView *item in stack.arrangedSubviews) {+ if ([item isKindOfClass:SGRTabItemView.class]) continue;+ NSString *ident = stockID(item);+ if (stockViews[ident]) continue;+ stockViews[ident] = item;+ measureItem(item);+ if (!sg_stockOrder) sg_stockOrder = [NSMutableArray array];+ if (![sg_stockOrder containsObject:ident]) [sg_stockOrder addObject:ident];+ }+ if (sg_stockOrder && ![sg_stockOrder isEqualToArray:SGRNavbarStock()]) SGRSetNavbarStock(sg_stockOrder);++ NSMutableDictionary<NSString *, SGRTabItemView *> *custom = customItems(stack);+ NSMutableArray<UIView *> *wanted = [NSMutableArray array];+ NSMutableSet<NSString *> *placed = [NSMutableSet set];+ NSMutableSet<NSString *> *keep = [NSMutableSet set];++ if (SGEnabled(SGRKeyNavbar)) {+ for (NSDictionary *entry in SGRNavbarLayout()) {+ NSString *ident = entry[SGRNavbarID];+ if (![ident isKindOfClass:NSString.class] || [placed containsObject:ident]) continue;+ [placed addObject:ident];+ BOOL hidden = [entry[SGRNavbarHidden] boolValue];+ if (entry[SGRNavbarURI]) {+ if (hidden) continue;+ SGRTabItemView *item = custom[ident];+ if (item) [item applyEntry:entry];+ else custom[ident] = item = [[SGRTabItemView alloc] initWithEntry:entry];+ [keep addObject:ident];+ [wanted addObject:item];+ } else if (stockViews[ident]) {+ stockViews[ident].hidden = hidden;+ [wanted addObject:stockViews[ident]];+ }+ }+ }+ // Tabs of Spotify's the list does not name — or named before Spotify had built them — keep+ // Spotify's own place, at the end, shown.+ for (NSString *ident in sg_stockOrder) {+ UIView *item = stockViews[ident];+ if (!item || [wanted containsObject:item]) continue;+ item.hidden = NO;+ [wanted addObject:item];+ }+ for (NSString *ident in custom.allKeys) {+ if ([keep containsObject:ident]) continue;+ [custom[ident] removeFromSuperview];+ [custom removeObjectForKey:ident];+ }++ // A bar with nothing on it would strand whoever emptied it, so the last word is Spotify's.+ BOOL empty = YES;+ for (UIView *item in wanted) if (!item.hidden) empty = NO;+ if (empty) for (UIView *item in wanted) item.hidden = NO;++ // Items of the mod's own join the stack at the end, where they are past whatever Spotify+ // counts, and Spotify's own keep the places it gave them.+ for (UIView *item in wanted) {+ if ([item isKindOfClass:SGRTabItemView.class] && item.superview != stack) [stack addArrangedSubview:item];+ }+ NSMutableArray<UIView *> *order = [NSMutableArray array];+ for (UIView *item in wanted) if (!item.hidden && item.superview == stack) [order addObject:item];+ sg_row = stack;+ if (![order isEqualToArray:objc_getAssociatedObject(stack, &kOrderKey)]) {+ objc_setAssociatedObject(stack, &kOrderKey, order, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ [stack setNeedsLayout];+ }+}++// Spotify placed the icon and the label for the width it measured (trees/test5.txt: x 28 in a+// 134pt slot, the centre of the 80pt it had with five tabs) and lays the item out no further+// once the slot changes. Assigning the centres back sends them through the hooks below.+static void centreContents(UIView *item) {+ SGForEachView(item, ^(UIView *v) {+ if ([v isKindOfClass:%c(SPTEncoreIconView)] || [v isKindOfClass:%c(SPTEncoreLabel)]) v.center = v.center;+ });+}++// Equal slots across the bar, in the order composed above. The frames go on after the stack's+// own pass, so Spotify's own widths never decide whether a fifth item fits.+static void placeRow(UIStackView *stack) {+ NSArray<UIView *> *order = objc_getAssociatedObject(stack, &kOrderKey);+ UIView *bar = sg_navbarRoot;+ if (!order.count || !bar) return;+ CGFloat width = bar.bounds.size.width / order.count;+ CGFloat height = stack.bounds.size.height;+ [order enumerateObjectsUsingBlock:^(UIView *item, NSUInteger i, BOOL *stop) {+ CGFloat x = [bar convertPoint:CGPointMake(i * width, 0) toView:stack].x;+ CGRect frame = CGRectMake(x, 0, width, height);+ if (!CGAffineTransformIsIdentity(item.transform)) item.transform = CGAffineTransformIdentity;+ if (!CGRectEqualToRect(item.frame, frame)) item.frame = frame;+ centreContents(item);+ }];+}++%hook UIStackView+- (void)layoutSubviews {+ %orig;+ if ((UIStackView *)self == sg_row) placeRow((UIStackView *)self);+}+%end++// Spotify's element layout places the icon and the label from the width it measured, not from+// the slot above (trees/test5.txt: x 38 in a 134pt element in a 126pt slot), and a view placed by+// its parent gets no layout pass of its own. So the placement itself is bent: on the bar, whatever+// x Spotify sets, the view lands centred on its slot.+static CGFloat slotCentreX(UIView *view) {+ UIStackView *row = sg_row;+ if (!row) return NAN;+ UIView *slot = nil;+ for (UIView *v = view; v.superview; v = v.superview) if (v.superview == row) { slot = v; break; }+ if (!slot) return NAN;+ return [slot convertPoint:CGPointMake(CGRectGetMidX(slot.bounds), 0) toView:view.superview].x;+}++%hook SPTEncoreIconView+- (void)setFrame:(CGRect)frame {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) frame.origin.x = centre - frame.size.width / 2;+ %orig(frame);+}+- (void)setCenter:(CGPoint)center {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) center.x = centre;+ %orig(center);+}+%end++%hook SPTEncoreLabel+- (void)setFrame:(CGRect)frame {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) frame.origin.x = centre - frame.size.width / 2;+ %orig(frame);+}+- (void)setCenter:(CGPoint)center {+ CGFloat centre = slotCentreX((UIView *)self);+ if (!isnan(centre)) center.x = centre;+ %orig(center);+}+%end++void SGRRefreshTabBar(void) {+ [sg_navbarRoot setNeedsLayout];+}++// What the row settled on, logged whenever it changes: `make log` then says whether the items fit,+// what is holding their width, and in what order the bar ended up.+void SGRLogTabBarRow(UIView *tabBar) {+ UIStackView *stack = SGRowIn(tabBar);+ if (!stack) return;+ NSMutableString *out = [NSMutableString stringWithFormat:@"row in %@ %@, icon %@ label %@, stack %@ axis %ld dist %ld align %ld spacing %.1f autolayout %d",+ NSStringFromClass(tabBar.class), NSStringFromCGRect(tabBar.frame),+ NSStringFromCGRect(sg_iconBox), NSStringFromCGRect(sg_labelBox), NSStringFromCGRect(stack.frame),+ (long)stack.axis, (long)stack.distribution, (long)stack.alignment, stack.spacing,+ !stack.translatesAutoresizingMaskIntoConstraints];+ NSUInteger index = 0;+ for (UIView *item in stack.arrangedSubviews) {+ [out appendFormat:@"\n %lu %@ %@%@ autolayout %d", (unsigned long)index++, NSStringFromClass(item.class),+ NSStringFromCGRect(item.frame), item.hidden ? @" hidden" : @"",+ !item.translatesAutoresizingMaskIntoConstraints];+ for (NSLayoutConstraint *c in item.constraints) {+ if (c.firstAttribute == NSLayoutAttributeWidth || c.secondAttribute == NSLayoutAttributeWidth) [out appendFormat:@"\n %@", c];+ }+ }+ for (NSLayoutConstraint *c in stack.constraints) [out appendFormat:@"\n own %@", c];+ for (NSLayoutConstraint *c in stack.superview.constraints) {+ if (c.firstItem == stack || c.secondItem == stack) [out appendFormat:@"\n held %@", c];+ }+ static NSString *last;+ if ([out isEqualToString:last]) return;+ last = [out copy];+ SGLogLong(@"navbar", out);+}++// Whether Spotify reads its own item list through this ObjC bridge decides whether the bar can be+// composed at the model level, where the order, the taps and the widths would all follow by+// themselves, instead of by moving views about. Silence in the log says it cannot.+%hook _TtC28NavigationUI_TabBarItemsImpl29TabBarItemsNavigationListImpl+- (NSArray *)items {+ NSArray *items = %orig;+ NSMutableString *out = [NSMutableString stringWithFormat:@"list read, %lu items", (unsigned long)items.count];+ for (id item in items) [out appendFormat:@"\n %@ · %@", [item valueForKey:@"title"], [item valueForKey:@"viewURI"]];+ static NSString *last;+ if (![out isEqualToString:last]) {+ last = [out copy];+ SGLogLong(@"navbar", out);+ }+ return items;+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[+ @"SPTEncoreIcon",+ @"SPTEncoreIconView",+ @"SPTEncoreLabel",+ @"_TtC28NavigationUI_TabBarItemsImpl29TabBarItemsNavigationListImpl",+ ]);+}diff --git a/tweak/Sources/Redesigned/Navbar/NavbarLayout.m b/tweak/Sources/Redesigned/Navbar/NavbarLayout.mnew file mode 100644index 00000000..a31aa611--- /dev/null+++ b/tweak/Sources/Redesigned/Navbar/NavbarLayout.m@@ -0,0 +1,34 @@+// The saved composition of the redesign's bar, as NSUserDefaults property lists, apart from the native look's.+#import "Navbar.h"++NSString *const SGRNavbarID = @"id";+NSString *const SGRNavbarTitle = @"title";+NSString *const SGRNavbarURI = @"uri";+NSString *const SGRNavbarIcon = @"icon";+NSString *const SGRNavbarHidden = @"hidden";++static NSString *const kNavbarLayout = @"spotifyglass.redesign.navbar.layout";+static NSString *const kNavbarStock = @"spotifyglass.redesign.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 *> *SGRNavbarLayout(void) {+ return listOfKind(kNavbarLayout, NSDictionary.class);+}++void SGRSetNavbarLayout(NSArray<NSDictionary *> *layout) {+ [NSUserDefaults.standardUserDefaults setObject:layout ?: @[] forKey:kNavbarLayout];+}++NSArray<NSString *> *SGRNavbarStock(void) {+ return listOfKind(kNavbarStock, NSString.class);+}++void SGRSetNavbarStock(NSArray<NSString *> *stock) {+ [NSUserDefaults.standardUserDefaults setObject:stock ?: @[] forKey:kNavbarStock];+}diff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.mnew file mode 100644index 00000000..ff75ef98--- /dev/null+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m@@ -0,0 +1,342 @@+#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 @[+ @{SGRNavbarTitle: @"Home", SGRNavbarURI: @"spotify:home", SGRNavbarIcon: @"home"},+ @{SGRNavbarTitle: @"Search", SGRNavbarURI: @"spotify:search", SGRNavbarIcon: @"search"},+ @{SGRNavbarTitle: @"Your Library", SGRNavbarURI: @"spotify:collection", SGRNavbarIcon: @"collection"},+ @{SGRNavbarTitle: @"Liked Songs", SGRNavbarURI: @"spotify:collection:tracks", SGRNavbarIcon: @"heart"},+ @{SGRNavbarTitle: @"Playlists", SGRNavbarURI: @"spotify:collection:playlists", SGRNavbarIcon: @"playlist"},+ @{SGRNavbarTitle: @"Albums", SGRNavbarURI: @"spotify:collection:albums", SGRNavbarIcon: @"album"},+ @{SGRNavbarTitle: @"Artists", SGRNavbarURI: @"spotify:collection:artists", SGRNavbarIcon: @"artist"},+ @{SGRNavbarTitle: @"Podcasts", SGRNavbarURI: @"spotify:collection:podcasts", SGRNavbarIcon: @"podcasts"},+ @{SGRNavbarTitle: @"Audiobooks", SGRNavbarURI: @"spotify:collection:audiobooks", SGRNavbarIcon: @"audiobook"},+ @{SGRNavbarTitle: @"Downloads", SGRNavbarURI: @"spotify:collection:downloads", SGRNavbarIcon: @"downloaded"},+ @{SGRNavbarTitle: @"Your Episodes", SGRNavbarURI: @"spotify:collection:your-episodes", SGRNavbarIcon: @"bookmark"},+ @{SGRNavbarTitle: @"Browse", SGRNavbarURI: @"spotify:browse", SGRNavbarIcon: @"browse"},+ @{SGRNavbarTitle: @"New Releases", SGRNavbarURI: @"spotify:new-releases", SGRNavbarIcon: @"star"},+ @{SGRNavbarTitle: @"Made For You", SGRNavbarURI: @"spotify:made-for-you", SGRNavbarIcon: @"user"},+ @{SGRNavbarTitle: @"Concerts", SGRNavbarURI: @"spotify:concerts", SGRNavbarIcon: @"events"},+ @{SGRNavbarTitle: @"Queue", SGRNavbarURI: @"spotify:now-playing:queue", SGRNavbarIcon: @"queue"},+ @{SGRNavbarTitle: @"Create", SGRNavbarURI: @"spotify:create-menu", SGRNavbarIcon: @"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 = SGRNavbarStock();+ NSMutableArray<NSMutableDictionary *> *entries = [NSMutableArray array];+ NSMutableSet<NSString *> *seen = [NSMutableSet set];+ for (NSDictionary *entry in SGRNavbarLayout()) {+ NSString *ident = entry[SGRNavbarID];+ if (![ident isKindOfClass:NSString.class] || [seen containsObject:ident]) continue;+ if (!entry[SGRNavbarURI] && ![stock containsObject:ident]) continue;+ [seen addObject:ident];+ [entries addObject:[entry mutableCopy]];+ }+ for (NSString *ident in stock) {+ if ([seen containsObject:ident]) continue;+ [entries addObject:[@{SGRNavbarID: ident, SGRNavbarTitle: 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[SGRNavbarID] = NSUUID.UUID.UUIDString;+ SGRSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);+ SGRRefreshTabBar();+}++@interface SGRTabPickerPage : SGPage+@end++@implementation SGRTabPickerPage {+ UIView *_footer;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Add a Tab";+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ _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[SGRNavbarTitle], tab[SGRNavbarURI], 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(@{SGRNavbarTitle: title.length ? title : uri, SGRNavbarURI: uri, SGRNavbarIcon: icon.length ? icon : @"star"});+ [self.navigationController popViewControllerAnimated:YES];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++@end++typedef NS_ENUM(NSInteger, SGRNavbarSection) {+ SGRNavbarSectionSwitch,+ SGRNavbarSectionTabs,+ SGRNavbarSectionAdd,+ SGRNavbarSectionReset,+ SGRNavbarSectionCount,+};++// 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. Mod Settings and the welcome+// tour show the same editor.+@interface SGRNavbarPage : SGPage+@end++@implementation SGRNavbarPage {+ NSMutableArray<NSMutableDictionary *> *_entries;+ UIView *_intro;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Navbar";+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ 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 {+ SGRSetNavbarLayout(_entries);+ SGRRefreshTabBar();+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return SGRNavbarSectionCount;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return section == SGRNavbarSectionTabs ? (NSInteger)_entries.count : 1;+}++- (NSString *)headerFor:(NSInteger)section {+ return section == SGRNavbarSectionTabs ? @"Tabs" : nil;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ NSString *title = [self headerFor:section];+ return title ? SGSectionHeader(table, title) : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ if ([self headerFor:section]) return SGSectionHeaderHeight;+ return [self tableView:table numberOfRowsInSection:section] ? SGSectionGap : 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 SGRNavbarSectionSwitch: {+ SGFillCell(cell, @"Custom navbar", nil, nil, nil);+ UISwitch *toggle = [UISwitch new];+ toggle.onTintColor = SGGreen();+ toggle.on = SGEnabled(SGRKeyNavbar);+ [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];+ cell.accessoryView = toggle;+ break;+ }+ case SGRNavbarSectionTabs: {+ NSDictionary *entry = _entries[(NSUInteger)path.row];+ BOOL hidden = [entry[SGRNavbarHidden] boolValue];+ NSString *uri = entry[SGRNavbarURI];+ SGFillCell(cell, entry[SGRNavbarTitle], hidden ? @"Hidden" : (uri ?: @"Spotify's own tab"),+ hidden ? SGGrey() : nil, hidden ? @"eye.slash" : @"eye");+ break;+ }+ case SGRNavbarSectionAdd:+ 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 == SGRNavbarSectionTabs;+}++- (BOOL)tableView:(UITableView *)table canEditRowAtIndexPath:(NSIndexPath *)path {+ return path.section == SGRNavbarSectionTabs;+}++// 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 != SGRNavbarSectionTabs) return UITableViewCellEditingStyleNone;+ return _entries[(NSUInteger)path.row][SGRNavbarURI] ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;+}++- (NSIndexPath *)tableView:(UITableView *)table targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)from toProposedIndexPath:(NSIndexPath *)to {+ return to.section == SGRNavbarSectionTabs ? 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 == SGRNavbarSectionTabs) {+ NSMutableDictionary *entry = _entries[(NSUInteger)path.row];+ entry[SGRNavbarHidden] = [entry[SGRNavbarHidden] boolValue] ? nil : @YES;+ [self save];+ [table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];+ } else if (path.section == SGRNavbarSectionAdd) {+ [self.navigationController pushViewController:[SGRTabPickerPage new] animated:YES];+ } else if (path.section == SGRNavbarSectionReset) {+ [self reset];+ }+}++- (void)toggled:(UISwitch *)toggle {+ SGSetEnabled(SGRKeyNavbar, toggle.on);+ SGRRefreshTabBar();+}++- (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) {+ SGRSetNavbarLayout(@[]);+ SGRRefreshTabBar();+ self->_entries = navbarEntries();+ [self.tableView reloadData];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++@end++UIViewController *SGRNavbarSettingsPage(void) {+ return [SGRNavbarPage new];+}++UIViewController *SGRNavbarEditorPage(void) {+ return [SGRNavbarPage new];+}diff --git a/tweak/Sources/Redesigned/Navbar/SearchField.x b/tweak/Sources/Redesigned/Navbar/SearchField.xindex 642df45d..cb2e0a8f 100644--- a/tweak/Sources/Redesigned/Navbar/SearchField.x+++ b/tweak/Sources/Redesigned/Navbar/SearchField.x@@ -1,4 +1,4 @@-// Search page: the white search field becomes a glass capsule with white text.+// The redesign's search page: the white search field becomes a glass capsule with white text.//// Tree (trees/search.txt): SearchHeaderFind.SearchBar, a 370x48 Encore tertiary button painted// white, r=6, holding SearchHeaderFind.SearchBarIcon and the placeholder label. The button class is@@ -12,7 +12,6 @@// 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 "Core/SGCore.h"-#import "Native/Appearance/Appearance.h"#import "Diagnostics/Diagnostics.h"// Spotify's glyph view, resolved at runtime; declared on UIView so the call and the hook below@@ -95,7 +94,6 @@ static void traceFieldArriving(UIView *button) {}static void styleSearchField(UIView *button) {- if (!SGFlag(SGKeySearchField, NO)) return;CGSize size = button.bounds.size;if (size.width < 200 || size.height < 40 || size.height > 60) return;BOOL styled = [objc_getAssociatedObject(button, &kStyledKey) boolValue];@@ -150,6 +148,7 @@ static void styleSearchField(UIView *button) {%end%ctor {+ if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[@"_TtCCE16Encore_ButtonKitO16EncoreFoundation6Encore6Button8Tertiary", @"SPTEncoreIconView"]);}diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex 92b8ef20..bc08eb83 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -4,14 +4,14 @@// its frame, so the page insets and the now playing bar stay where Spotify puts them.//// A tab picked on the system bar is passed on as a tap on the hidden Spotify item it mirrors, and the-// system bar's selection follows whichever Spotify label is painted white. Navbar/Navbar.x still-// composes the hidden row, so its order, hidden tabs and tabs of the mod's own carry over.+// system bar's selection follows whichever Spotify label is painted white. Navbar.x composes the+// hidden row, so its order, hidden tabs and tabs of the mod's own carry over. Always on in the redesign.//// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView of// ElementContentView<TabBarItemElement>, each with an SPTEncoreIconView and an SPTEncoreLabel.#import "Core/SGCore.h"-#import "Native/Navbar/Navbar.h"-#import "Native/Appearance/Appearance.h"+#import "Navbar.h"+#import "Redesigned/Kit/SGRTokens.h"#import "Settings/SGPage.h"#import "Headers/SPTEncoreIconView.h"#import <objc/message.h>@@ -19,7 +19,7 @@static char kBarKey;static __weak UIView *sg_stockBar;-@interface SGSystemTabBar : UITabBar <UITabBarDelegate, UIGestureRecognizerDelegate>+@interface SGRSystemTabBar : UITabBar <UITabBarDelegate, UIGestureRecognizerDelegate>@property (nonatomic, weak) UIView *stockBar;@property (nonatomic, copy) NSArray<UIView *> *sources;@property (nonatomic, weak) UILongPressGestureRecognizer *hold;@@ -177,7 +177,7 @@ static void forwardTap(UIView *item) {#pragma mark - the system bar-@implementation SGSystemTabBar+@implementation SGRSystemTabBar- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {NSUInteger index = [self.items indexOfObject:item];@@ -235,11 +235,11 @@ static void forwardTap(UIView *item) {@end-@interface SGHomeHold : UILongPressGestureRecognizer+@interface SGRHomeHold : UILongPressGestureRecognizer@end-@implementation SGHomeHold-+ (void)held:(SGHomeHold *)hold {+@implementation SGRHomeHold++ (void)held:(SGRHomeHold *)hold {if (hold.state == UIGestureRecognizerStateBegan) SGOpenModSettings(hold.view);}@end@@ -249,20 +249,9 @@ static void holdHome(UIView *stockBar) {UIView *home = SGRowIn(stockBar).arrangedSubviews.firstObject;if (!home) return;for (UIGestureRecognizer *recognizer in home.gestureRecognizers) {- if ([recognizer isKindOfClass:SGHomeHold.class]) return;- }- [home addGestureRecognizer:[[SGHomeHold alloc] initWithTarget:SGHomeHold.class action:@selector(held:)]];-}--static void removeBar(UIView *stockBar) {- UIView *bar = objc_getAssociatedObject(stockBar, &kBarKey);- if (!bar) return;- [bar removeFromSuperview];- objc_setAssociatedObject(stockBar, &kBarKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);- for (UIView *sub in stockBar.subviews) {- sub.alpha = 1;- sub.userInteractionEnabled = YES;+ if ([recognizer isKindOfClass:SGRHomeHold.class]) return;}+ [home addGestureRecognizer:[[SGRHomeHold alloc] initWithTarget:SGRHomeHold.class action:@selector(held:)]];}static void logBarOnce(UITabBar *bar) {@@ -275,15 +264,11 @@ static void logBarOnce(UITabBar *bar) {}static void syncBar(UIView *stockBar) {- if (!SGFlag(SGKeyTabBar, NO)) {- removeBar(stockBar);- return;- }sg_stockBar = stockBar;- SGSystemTabBar *bar = objc_getAssociatedObject(stockBar, &kBarKey);+ SGRSystemTabBar *bar = objc_getAssociatedObject(stockBar, &kBarKey);if (!bar) {- bar = [[SGSystemTabBar alloc] initWithFrame:stockBar.bounds];+ bar = [[SGRSystemTabBar alloc] initWithFrame:stockBar.bounds];bar.delegate = bar;bar.stockBar = stockBar;UILongPressGestureRecognizer *hold = [[UILongPressGestureRecognizer alloc] initWithTarget:bar action:@selector(held:)];@@ -292,7 +277,7 @@ static void syncBar(UIView *stockBar) {bar.hold = hold;objc_setAssociatedObject(stockBar, &kBarKey, bar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- bar.tintColor = SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];+ bar.tintColor = SGRAccent();for (UIView *sub in stockBar.subviews) {if (sub == bar) continue;@@ -362,13 +347,13 @@ static UIView *tabBarOf(UIView *item) {%hook _TtC23NavigationUI_TabBarImpl10TabBarView- (void)layoutSubviews {%orig;- SGComposeTabBar((UIView *)self);+ SGRComposeTabBar((UIView *)self);for (UIView *sub in ((UIView *)self).subviews) {- if (![sub isKindOfClass:SGSystemTabBar.class]) [sub layoutIfNeeded];+ if (![sub isKindOfClass:SGRSystemTabBar.class]) [sub layoutIfNeeded];}holdHome((UIView *)self);syncBar((UIView *)self);- SGLogTabBarRow((UIView *)self);+ SGRLogTabBarRow((UIView *)self);}%end@@ -376,10 +361,10 @@ static UIView *tabBarOf(UIView *item) {static void itemDidLayOut(UIView *item) {UIView *bar = tabBarOf(item);if (!bar) return;- SGComposeTabBar(bar);+ SGRComposeTabBar(bar);holdHome(bar);syncBar(bar);- SGLogTabBarRow(bar);+ SGRLogTabBarRow(bar);}%hook _TtC23NavigationUI_TabBarImpl21TabBarItemElementView@@ -408,6 +393,7 @@ static void itemDidLayOut(UIView *item) {%end%ctor {+ if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[@"_TtC23NavigationUI_TabBarImpl10TabBarView",diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.xindex 28a8ea22..3e285751 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x@@ -1,57 +1,20 @@-// Now playing bar: the album-coloured card becomes a glass card with round artwork and the+// The redesign's now playing bar: the album-coloured card becomes a glass card with round artwork and the// progress line under the text. Spotify's own labels, buttons and gestures stay in place.//-// 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 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.+// The full screen player morphs the bar's own card and artwork into the cover art. The bar was+// written to hand itself back to Spotify for that animation, from NowPlaying_ViewPageImpl's+// Show/CloseFullscreenAnimatedTransitioning, but Spotify 9.1.78 never runs the player through those,+// so the handback never happened and is gone; if the morph ever reads as a cut, the place to start is+// Shared/Player/PlayerEvents.h, which does fire.//// 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 "Core/SGCore.h"-#import "Native/Player/NowPlaying.h"+#import "Redesigned/Kit/SGRRepaint.h"static const CGFloat kCardRadius = 24;-static const NSTimeInterval kFadeOut = 0.12, kFadeIn = 0.2;-static char kGlassKey, kRadiusKey;--// The view carrying the glass pane, so the transition hooks reach it without the controllers.-static __weak UIView *sg_barGlassHost = nil;-// Open and close tapped in quick succession overlap; only the newest animation takes the bar back.-static NSUInteger sg_barTransition = 0;--// The karaoke card under the player puts its display link down while the player animates.-NSString *const SGPlayerTransitionNotification = @"spotifyglass.playerTransition";-NSString *const SGPlayerTransitionEndedNotification = @"spotifyglass.playerTransitionEnded";-static CFTimeInterval sg_transitionEnds;-static NSUInteger sg_transitionGeneration;--CFTimeInterval SGPlayerTransitionEnds(void) {- return sg_transitionEnds > CACurrentMediaTime() ? sg_transitionEnds : 0;-}--// The two animators hooked below are what the bar was written against, but the player of this-// Spotify never runs through them (no log of theirs has ever shown up), so the announcement comes-// from the appearance callbacks of a controller inside the player, which UIKit sends as the-// presentation or the dismissal begins, whatever animates it; the transition coordinator says when-// it is over, a cancelled swipe included.-static void announceTransition(UIViewController *unit, BOOL animated, NSString *what) {- id<UIViewControllerTransitionCoordinator> coordinator = unit.transitionCoordinator;- if (!animated || !coordinator) return;- NSTimeInterval duration = MAX(0.1, coordinator.transitionDuration);- NSUInteger generation = ++sg_transitionGeneration;- sg_transitionEnds = CACurrentMediaTime() + duration;- [NSNotificationCenter.defaultCenter postNotificationName:SGPlayerTransitionNotification object:nil];- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {- if (generation != sg_transitionGeneration) return;- sg_transitionEnds = 0;- [NSNotificationCenter.defaultCenter postNotificationName:SGPlayerTransitionEndedNotification object:nil];- }];- static dispatch_once_t once;- dispatch_once(&once, ^{ SGLog(@"player %@ over %.2fs, by its appearance callbacks", what, duration); });-}+static char kGlassKey;static UIView *detectColoredCard(UIView *bar) {__block UIView *best = nil;@@ -78,23 +41,11 @@ static CGRect contentBounds(UIView *bar, UIView *target) {return CGRectIsNull(box) ? box : CGRectInset(box, -10, -8);}-// Spotify's own radius is kept the first time each view is rounded, so the bar can be put back-// the way it was laid out for the player's expand animation.static void roundView(UIView *view, CGFloat radius) {- if (!objc_getAssociatedObject(view, &kRadiusKey)) {- objc_setAssociatedObject(view, &kRadiusKey, @(view.layer.cornerRadius), OBJC_ASSOCIATION_RETAIN_NONATOMIC);- }view.layer.cornerRadius = radius;view.layer.cornerCurve = kCACornerCurveContinuous;}-static void restoreRounding(UIView *root) {- SGForEachView(root, ^(UIView *v) {- NSNumber *saved = objc_getAssociatedObject(v, &kRadiusKey);- if (saved) v.layer.cornerRadius = saved.doubleValue;- });-}-static void restyleCardContent(UIView *card) {SGForEachView(card, ^(UIView *v) {CGSize size = v.bounds.size;@@ -116,38 +67,13 @@ static void restyleCardContent(UIView *card) {});}-static BOOL insideClass(UIView *view, NSString *marker) {- for (UIView *v = view; v; v = v.superview) if ([NSStringFromClass(v.class) containsString:marker]) return YES;- return NO;-}--// trees/test6.txt: the button row is a UIStackView holding Connect_EntryPointsImpl.ConnectStateView-// (the connected device) and .ConnectButtonView, each wrapped; hiding the wrapper closes the gap.-// The ConnectStateView under the title ("playing on ...") sits in InformationContainer and stays.-static void hideConnectButton(UIView *bar) {- if (!SGHidden(SGHideBarConnect)) return;- SGForEachView(bar, ^(UIView *v) {- NSString *name = NSStringFromClass(v.class);- if (![name containsString:@"ConnectButtonView"] && ![name containsString:@"ConnectStateView"]) return;- if (insideClass(v, @"InformationContainer")) return;- UIView *item = v;- while (item.superview && ![item.superview isKindOfClass:UIStackView.class]) item = item.superview;- if (item.superview && !item.hidden) item.hidden = YES;- });-}-static void styleNowPlayingBar(UIViewController *container) {- if (!SGFlag(SGKeyNowPlayingBar, NO)) return;UIViewController *barVC = container.childViewControllers.firstObject;UIView *bar = barVC.viewIfLoaded ?: container.view;- sg_nowPlayingRoot = bar;- sg_barGlassHost = container.view;- // Mid-transition the bar is Spotify's; its layout runs untouched so the progress line, the- // corners and the paint are whatever the animation needs.- if (sg_nowPlayingStock) return;+ sgr_nowPlayingRoot = bar;- UIView *card = sg_nowPlayingCard;- if (!card || !SGIsInside(card, bar)) card = sg_nowPlayingCard = detectColoredCard(bar);+ UIView *card = sgr_nowPlayingCard;+ if (!card || !SGIsInside(card, bar)) card = sgr_nowPlayingCard = detectColoredCard(bar);container.view.layer.backgroundColor = NULL;SGStripBackgrounds(bar);@@ -174,43 +100,6 @@ static void styleNowPlayingBar(UIViewController *container) {});}-#pragma mark - the player's expand and close animations--// `stock` gives the bar back to Spotify for the length of an animation, and takes it again after.-static void barStock(BOOL stock, NSTimeInterval fade) {- UIView *host = sg_barGlassHost;- if (!host || !SGFlag(SGKeyNowPlayingBar, NO) || sg_nowPlayingStock == stock) return;- sg_nowPlayingStock = stock;-- if (stock) {- restoreRounding(host);- if (sg_nowPlayingCardColor) sg_nowPlayingCard.layer.backgroundColor = sg_nowPlayingCardColor;- }- // A layout pass with the flag already set puts the bar in the state the flag asks for: the- // hook above either stands aside or restyles from scratch.- [host setNeedsLayout];- [host layoutIfNeeded];-- UIVisualEffectView *glass = objc_getAssociatedObject(host, &kGlassKey);- [UIView animateWithDuration:fade animations:^{ glass.alpha = stock ? 0 : 1; }];-}--// Both animators are UIViewControllerAnimatedTransitioning. The bar is Spotify's own from the-// first frame and glass again once the animation has had its duration; on the way up it is behind-// the player by then, on the way down the dissolve lands with the artwork.-static void playerTransition(id<UIViewControllerAnimatedTransitioning> animator, id<UIViewControllerContextTransitioning> context) {- NSTimeInterval duration = MAX(0.1, [animator transitionDuration:context]);- NSUInteger generation = ++sg_barTransition;- sg_transitionEnds = CACurrentMediaTime() + duration;- [NSNotificationCenter.defaultCenter postNotificationName:SGPlayerTransitionNotification object:nil];- barStock(YES, MIN(kFadeOut, duration / 3));- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{- if (generation == sg_barTransition) barStock(NO, kFadeIn);- });- static dispatch_once_t once;- dispatch_once(&once, ^{ SGLog(@"player transition %@ over %.2fs", [animator class], duration); });-}-%hook _TtC18NowPlaying_BarImpl36NowPlayingBarContainerViewController- (void)viewDidLayoutSubviews {%orig;@@ -221,44 +110,16 @@ static void playerTransition(id<UIViewControllerAnimatedTransitioning> animator,%hook _TtC18NowPlaying_BarImpl27NowPlayingBarViewController- (void)viewDidLayoutSubviews {%orig;- hideConnectButton(((UIViewController *)self).view);UIViewController *parent = ((UIViewController *)self).parentViewController;if ([NSStringFromClass(parent.class) containsString:@"NowPlayingBarContainer"]) styleNowPlayingBar(parent);}%end-%hook _TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController-- (void)viewWillAppear:(BOOL)animated {- %orig;- announceTransition((UIViewController *)self, animated, @"opens");-}-- (void)viewWillDisappear:(BOOL)animated {- %orig;- announceTransition((UIViewController *)self, animated, @"closes");-}-%end--%hook _TtC23NowPlaying_ViewPageImpl35ShowFullscreenAnimatedTransitioning-- (void)animateTransition:(id<UIViewControllerContextTransitioning>)context {- playerTransition((id)self, context);- %orig;-}-%end--%hook _TtC23NowPlaying_ViewPageImpl36CloseFullScreenAnimatedTransitioning-- (void)animateTransition:(id<UIViewControllerContextTransitioning>)context {- playerTransition((id)self, context);- %orig;-}-%end-%ctor {+ if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[@"_TtC18NowPlaying_BarImpl36NowPlayingBarContainerViewController",@"_TtC18NowPlaying_BarImpl27NowPlayingBarViewController",- @"_TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController",- @"_TtC23NowPlaying_ViewPageImpl35ShowFullscreenAnimatedTransitioning",- @"_TtC23NowPlaying_ViewPageImpl36CloseFullScreenAnimatedTransitioning",]);}diff --git a/tweak/Sources/Redesigned/Player/KaraokeCard.x b/tweak/Sources/Redesigned/Player/KaraokeCard.xnew file mode 100644index 00000000..6900d7d7--- /dev/null+++ b/tweak/Sources/Redesigned/Player/KaraokeCard.x@@ -0,0 +1,43 @@+// The same Apple Music style lyrics on the card under the player, so the card sweeps word by word+// rather than scrolling whole lines while the page it expands into sweeps. It is the page's view in+// compact: the card is a seventh of the height, so it takes Spotify's own type size and spacing.+//+// The host is Lyrics_CardElementImpl.CardContentView, the card's own content view. The table inside+// it, Lyrics_TextElementImpl.LyricsTextView, is the wrong thing to hook: the full screen page is+// built from that same class, and KaraokePage.x is already over it there. CardContentView belongs+// to the card alone, and is still in the tree while the page is open, behind it.+//+// The view is laid over rather than swapped in, as on the page: Spotify's table keeps running+// underneath and comes back the moment a track has no synced lyrics. It takes no touches, so the+// tap that opens the full screen page is still Spotify's to answer.+#import "Core/SGCore.h"+#import "Redesigned/Lyrics/SGRKaraokeView.h"++// Below this the card is collapsed, by PlayerCards.x or while it is still being laid out.+static const CGFloat kLivingHeight = 40;++static char kKaraokeKey;++%hook _TtC22Lyrics_CardElementImpl15CardContentView+- (void)layoutSubviews {+ %orig;+ UIView *host = (UIView *)self;+ if (host.bounds.size.height < kLivingHeight) return;+ SGRKaraokeView *view = objc_getAssociatedObject(host, &kKaraokeKey);+ if (!view) {+ SGLog(@"karaoke: card laid out, playing %@", SGKaraokePlayingTrack());+ view = [[SGRKaraokeView alloc] initWithFrame:host.bounds compact:YES];+ objc_setAssociatedObject(host, &kKaraokeKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ if (view.superview == host) [host bringSubviewToFront:view];+ else [host addSubview:view];+ view.frame = host.bounds;+ [view syncSiblings];+}+%end++%ctor {+ if (!SGRedesignedUI() || !SGFlag(SGKeyKaraokeLyrics, NO)) return;+ %init;+ SGRequireClasses(@[@"_TtC22Lyrics_CardElementImpl15CardContentView"]);+}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex e2ffce1c..44d61e34 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -9,9 +9,11 @@// PlayerHeader.x glass behind the close and more buttons// PlayerControls.x previous, play and next as bare glyphs, monospaced times// PlayerFooter.x share gone, lyrics, Connect and queue as one row of three glyphs-// PlayerCards.x the lyrics card kept on a content surface, every other card collapsed+// PlayerCards.x the lyrics card kept, clear on the field, every other card collapsed+// KaraokeCard.x Apple Music style lyrics on that card+// PlayerGestures.x the gestures' hookup//-// Every hook installs only while SGRedesignOn(@"player"); the legacy player hooks stand aside then.+// Every hook installs only while Redesigned UI is on (SGRedesignedUI); the native look's do not then.// Threading: main thread only.#import <UIKit/UIKit.h>diff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.xindex 0eb303b9..bbc26436 100644--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x@@ -100,7 +100,7 @@ static void scaleEveryCover(BOOL animated) {%end// Spotify shows and hides the preview as lyrics come and go; it stays hidden, the way-// Declutter/Declutter.x has shipped it (its parent is a plain view, 01.txt:35, not a stack).+// Native/Player/PlayerDeclutter.x has shipped it (its parent is a plain view, 01.txt:35, not a stack).%hook _TtC22Lyrics_NPVContainerKit19LyricsContainerView- (void)setHidden:(BOOL)hidden {%orig(YES);@@ -138,7 +138,7 @@ static void scaleEveryCover(BOOL animated) {static SGRPlayerArtworkWatcher *sg_artworkWatcher;%ctor {- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;sg_tilts = [NSHashTable weakObjectsHashTable];sg_covers = [NSMapTable weakToWeakObjectsMapTable];diff --git a/tweak/Sources/Redesigned/Player/PlayerCards.x b/tweak/Sources/Redesigned/Player/PlayerCards.xindex 0205a155..a33ddc6a 100644--- a/tweak/Sources/Redesigned/Player/PlayerCards.x+++ b/tweak/Sources/Redesigned/Player/PlayerCards.x@@ -4,7 +4,7 @@// adds later) reports no height, so the list closes up around it.//// An allow list rather than Declutter's block list: the server decides which cards a track gets, and a-// new kind should not turn up under a redesigned player. The collapse is the one Declutter/Declutter.x+// new kind should not turn up under a redesigned player. The collapse is the one Native/Player/PlayerDeclutter.x// has shipped (the 24pt gaps between cards stay until the card list is filtered at the network, phase 2).//// Tree (trees/clean/player/01.txt:385, lyrics/01.txt:996-999): every card is an Element_List.CollectionViewCell@@ -15,6 +15,7 @@// their card. The card's share button is id=lyrics-share-button (lyrics/01.txt:1009).#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"+#import "Redesigned/Kit/SGRRepaint.h"#import "Shared/Lyrics/Lyrics.h"#import "Player.h"@@ -119,9 +120,9 @@ static UIView *cellAround(UIView *view) {if (cell.bounds.size.height >= kLivingHeight) {objc_setAssociatedObject(cell, &kRevalidatedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);// Spotify paints the cell the album colour again at every track change, which is no layout pass- // of the card's; as the root of the lyrics card, Appearance/Repaint.x keeps it clear in between.+ // of the card's; as the root of the lyrics card, Redesigned/Kit/SGRRepaint.x keeps it clear in between.if (clearWanted()) {- sg_lyricsCardRoot = cell;+ sgr_lyricsCardRoot = cell;SGStripBackgrounds(cell);static dispatch_once_t once;dispatch_once(&once, ^{ SGLog(@"redesign player: lyrics card cleared onto the field"); });@@ -171,7 +172,7 @@ static UIView *cellAround(UIView *view) {static SGRPlayerCardsWatcher *sg_cardsWatcher;%ctor {- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;sg_cardsWatcher = [SGRPlayerCardsWatcher new];SGRAddPlayerStateObserver(sg_cardsWatcher);diff --git a/tweak/Sources/Redesigned/Player/PlayerControls.x b/tweak/Sources/Redesigned/Player/PlayerControls.xindex 5a4ce24b..5d5552c7 100644--- a/tweak/Sources/Redesigned/Player/PlayerControls.x+++ b/tweak/Sources/Redesigned/Player/PlayerControls.x@@ -243,7 +243,7 @@ static UILabel *monospaced(UIView *host, NSString *identifier, const void *findK%end%ctor {- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;sg_controlsWatcher = [SGRPlayerControlsWatcher new];SGRAddPlayerStateObserver(sg_controlsWatcher);diff --git a/tweak/Sources/Redesigned/Player/PlayerField.x b/tweak/Sources/Redesigned/Player/PlayerField.xindex 9caf836e..68f35827 100644--- a/tweak/Sources/Redesigned/Player/PlayerField.x+++ b/tweak/Sources/Redesigned/Player/PlayerField.x@@ -6,7 +6,7 @@// scrolls (874 at rest, 1495 and 2144 further down, 02.txt:757, 03.txt:861), so a field inside it// scrolls with the cards and is laid out again on every scroll frame: the hook only compares a frame.// The field goes on top of the plane's own subviews, so Spotify's gradients are covered rather than-// fought over, and nothing depends on Appearance/Repaint.x.+// fought over, and nothing depends on a repaint hook.//// The picture comes from the Kit's now playing artwork: the now playing bar's 40pt cover, published by// the Kit, and the player's own 354pt cover, published here from the cell in the middle of the@@ -170,7 +170,7 @@ static SGRPlayerCoverWatcher *sg_coverWatcher;flags[[@"ios-feature-nowplaying." stringByAppendingString:egg]] = @NO;}SGRedesignForceFlags(@"player", flags);- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;sg_coverWatcher = [SGRPlayerCoverWatcher new];SGRAddPlayerStateObserver(sg_coverWatcher);diff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.xindex 02b0a1ef..799b5cf5 100644--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x@@ -17,6 +17,7 @@// is a UIButton (trees/clean/lyrics/01.txt:1013, objc-meta-Spotify.txt:216095).#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"+#import "Shared/Navigation/Links.h"#import "Player.h"static const CGFloat kLyricsGlyphSize = 20;@@ -57,7 +58,7 @@ static void openLyrics(void) {UIControl *expand = (UIControl *)SGRFindByIdentifier(card, @"lyrics-expand-button", &kExpandKey);NSString *how = @"nothing";if ([expand isKindOfClass:UIControl.class] && SGRFire(expand)) how = @"the card's expand button";- else if (SGROpenURI([NSURL URLWithString:@"spotify:lyrics:fullscreen"])) how = @"spotify:lyrics:fullscreen";+ else if (SGOpenSpotifyURI([NSURL URLWithString:@"spotify:lyrics:fullscreen"])) how = @"spotify:lyrics:fullscreen";SGLog(@"redesign player: lyrics glyph opened the page by %@", how);}@@ -140,7 +141,7 @@ static UIView *connectGlyphIn(UIView *holder) {%end%ctor {- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18FooterElementsUnit"]);}diff --git a/tweak/Sources/Redesigned/Player/PlayerGestures.x b/tweak/Sources/Redesigned/Player/PlayerGestures.xnew file mode 100644index 00000000..445acb5f--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerGestures.x@@ -0,0 +1,33 @@+// The redesigned player's hookup of the gestures (Shared/Gestures): the double tap goes on the player's artwork list.+//+// Tree (trees/now-playing.txt): the artwork sits in AccessibleCollectionView, a full screen list of+// the queue scrolled sideways, so the recognizer goes on that and the grid is the screen. Spotify's+// controls are sibling units rather than children of it, so a tap on a button never reaches it.+#import "Core/SGCore.h"+#import "Shared/Gestures/Gestures.h"++// A single tap on the cover is Spotify's way into the tilt mode, the artwork alone in 3D. That is+// the half of a double tap that misses, so while the zones are on it would open on the way to every+// gesture; the tap goes back to Spotify with the switch.+%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView+- (void)handleTap {+ if (SGFlag(SGKeyGestures, NO)) return;+ %orig;+}+%end++%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView+- (void)layoutSubviews {+ %orig;+ SGGestureAttach((UIView *)self);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[+ @"_TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView",+ @"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView",+ ]);+}diff --git a/tweak/Sources/Redesigned/Player/PlayerHeader.x b/tweak/Sources/Redesigned/Player/PlayerHeader.xindex 7afe69fa..7a3ebab9 100644--- a/tweak/Sources/Redesigned/Player/PlayerHeader.x+++ b/tweak/Sources/Redesigned/Player/PlayerHeader.x@@ -59,7 +59,7 @@ static void glassInside(UIViewController *unit, NSArray<NSString *> *identifiers%end%ctor {- if (!SGRedesignOn(@"player")) return;+ if (!SGRedesignedUI()) return;%init;SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit"]);}diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.mindex 389bd9fa..db99bec4 100644--- a/tweak/Sources/Settings/SGModPage.m+++ b/tweak/Sources/Settings/SGModPage.m@@ -2,10 +2,6 @@#import "SGPageStyle.h"#import "SGGlowSwitch.h"#import "Core/SGCore.h"-#import "Shared/Flags/Flags.h"-#import "Shared/About/About.h"-#import "Shared/AdBlock/AdBlock.h"-#import "Redesigned/Kit/SGRedesign.h"NSString *const SGRestartNote = @"Changes apply after you restart Spotify.";@@ -225,20 +221,17 @@ static BOOL flagRowOn(SGModRow *row) {return value && [value boolValue] != row.forceOff;}-// A flag Redesigned UI owns, for Spotify's newer design or for a redesigned screen: its row shows what-// the switch forces and takes no touch, so the flag has one place to change.+// A flag something of the mod's forces (Core/SGFlagForce.h: the redesign, the ad blocking): its row+// shows what is forced and takes no touch, so the flag has one place to change.static BOOL flagRowLocked(SGModRow *row) {- if (!row.flag) return NO;- return (SGGlassOwnsFlag(row.key) && SGFlag(SGKeySpotifyGlass, NO)) || (row.forceOff && SGAdBlockForcesFlagOff(row.key))- || SGRedesignOwnedFlag(row.key);+ return row.flag && SGLockedFlagValue(row.key, NULL) != nil;}-// What a locked row shows: the value its owner forces, read the row's way, so a Disable Canvas row-// reads on while the redesign forces Canvas off. The glass flags and the ad blocking only ever force a-// flag the way its row would.+// What a locked row shows: the forced value, read the row's way, so a Disable Canvas row reads on+// while Canvas is forced off.static BOOL lockedRowOn(SGModRow *row) {- id owned = SGRedesignOwnedFlag(row.key);- return owned ? [owned boolValue] != row.forceOff : YES;+ id value = SGLockedFlagValue(row.key, NULL);+ return value ? [value boolValue] != row.forceOff : YES;}@implementation SGModPage {@@ -352,8 +345,10 @@ static BOOL lockedRowOn(SGModRow *row) {if (row.key) {BOOL locked = flagRowLocked(row);- // The redesign's own flags win over an override; the others' lock gives way to one.- BOOL showsLock = locked && (SGRedesignOwnedFlag(row.key) || !SGFlagOverride(row.key));+ // A lock that beats an override shows over one; the others give way to it.+ BOOL beats = NO;+ if (locked) SGLockedFlagValue(row.key, &beats);+ BOOL showsLock = locked && (beats || !SGFlagOverride(row.key));BOOL on = row.flag ? (showsLock ? lockedRowOn(row) : flagRowOn(row)) : SGFlag(row.key, row.defaultOn);UIControl *toggle;if (row.glows) {diff --git a/tweak/Sources/Settings/SGPageStyle.h b/tweak/Sources/Settings/SGPageStyle.hindex 32efc9a0..cd116573 100644--- a/tweak/Sources/Settings/SGPageStyle.h+++ b/tweak/Sources/Settings/SGPageStyle.h@@ -30,5 +30,7 @@ CGFloat SGSectionFooterHeight(UITableView *table, NSString *text);UITableViewCell *SGDequeueCell(UITableView *table, NSString *identifier);void SGOpenURL(NSString *url);+extern NSString *const SGSiteURL;+extern NSString *const SGRepoURL;// The controller on top of the key window, through whatever is presented over it.UIViewController *SGTopController(void);diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.mindex 00399d6c..7a7f457a 100644--- a/tweak/Sources/Settings/SGPageStyle.m+++ b/tweak/Sources/Settings/SGPageStyle.m@@ -1,6 +1,5 @@#import "SGPageStyle.h"#import "Core/SGCore.h"-#import "Native/Appearance/Appearance.h"static UIFont *sg_titleFont, *sg_subtitleFont;@@ -68,11 +67,27 @@ void SGInsetForBars(UITableView *table) {table.verticalScrollIndicatorInsets = inset;}-UIColor *SGGreen(void) { return SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }+// The pages follow the native look's AMOLED and accent switches (Native/Appearance), read here by their+// keys so the page framework depends on no layer. Under Redesigned UI those switches are put away, and+// the pages keep Spotify's own colours.+static NSString *const kAmoledKey = @"spotifyglass.amoled";+static NSString *const kAccentKey = @"spotifyglass.accent";++static UIColor *nativeAccent(void) {+ NSInteger rgb = SGNativeUI() ? SGInt(kAccentKey, -1) : -1;+ if (rgb < 0 || rgb > 0xFFFFFF) return nil;+ return [UIColor colorWithRed:((rgb >> 16) & 0xFF) / 255.0 green:((rgb >> 8) & 0xFF) / 255.0 blue:(rgb & 0xFF) / 255.0 alpha:1];+}++static BOOL nativeAmoled(void) {+ return SGNativeUI() && SGFlag(kAmoledKey, NO);+}++UIColor *SGGreen(void) { return nativeAccent() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }UIColor *SGRed(void) { return [UIColor colorWithRed:0xF1 / 255.0 green:0x5E / 255.0 blue:0x6B / 255.0 alpha:1]; }-UIColor *SGPageBackground(void) { return SGFlag(SGKeyAmoled, NO) ? UIColor.blackColor : [UIColor colorWithWhite:0x12 / 255.0 alpha:1]; }+UIColor *SGPageBackground(void) { return nativeAmoled() ? UIColor.blackColor : [UIColor colorWithWhite:0x12 / 255.0 alpha:1]; }// Spotify's own elevated grey on its dark grey; iOS's own card grey on the AMOLED black.-UIColor *SGCardBackground(void) { return [UIColor colorWithWhite:(SGFlag(SGKeyAmoled, NO) ? 0x1C : 0x2A) / 255.0 alpha:1]; }+UIColor *SGCardBackground(void) { return [UIColor colorWithWhite:(nativeAmoled() ? 0x1C : 0x2A) / 255.0 alpha:1]; }UIImage *SGTileImage(NSString *symbol) {UIImageSymbolConfiguration *config = [UIImageSymbolConfiguration configurationWithPointSize:14 weight:UIImageSymbolWeightMedium];@@ -189,6 +204,9 @@ UIViewController *SGTopController(void) {return top;}+NSString *const SGSiteURL = @"https://spoti.pw";+NSString *const SGRepoURL = @"https://github.com/skopevoj/spoti.pw";+void SGOpenURL(NSString *url) {NSURL *target = url ? [NSURL URLWithString:url] : nil;if (!target) return;diff --git a/tweak/Sources/Shared/AdBlock/AdBlock.m b/tweak/Sources/Shared/AdBlock/AdBlock.mindex c393bee3..9dc1fb87 100644--- a/tweak/Sources/Shared/AdBlock/AdBlock.m+++ b/tweak/Sources/Shared/AdBlock/AdBlock.m@@ -58,6 +58,12 @@ BOOL SGAdBlockForcesFlagOff(NSString *key) {return SGHidden(SGKeyHideUpsells) && listed(key, upsellFlags, sizeof(upsellFlags) / sizeof(upsellFlags[0]));}+// After an override from the All flags page, and locking the rows that would turn the same flag off.+__attribute__((constructor)) static void registerForcer(void) {+ SGFlagForcer off = ^id(NSString *key) { return SGAdBlockForcesFlagOff(key) ? @NO : nil; };+ SGRegisterFlagForcer(NO, off, off);+}+#pragma mark - countersstatic NSString *const kCounts = @"spotifyglass.adblock.counts";diff --git a/tweak/Sources/Shared/Flags/Flags.h b/tweak/Sources/Shared/Flags/Flags.hindex 2ebf5dad..0f857f0c 100644--- a/tweak/Sources/Shared/Flags/Flags.h+++ b/tweak/Sources/Shared/Flags/Flags.h@@ -4,12 +4,6 @@// page. Flags that change a part of the app sit on that part's own page.#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[];diff --git a/tweak/Sources/Shared/Flags/Flags.x b/tweak/Sources/Shared/Flags/Flags.xindex 197c0c5c..dd0ae9c9 100644--- a/tweak/Sources/Shared/Flags/Flags.x+++ b/tweak/Sources/Shared/Flags/Flags.x@@ -1,39 +1,13 @@// Spotify reads every remote-config flag once at startup through the configuration provider,-// keyed "component.property". While Redesigned UI is on, the flags its screens are built on come first-// (Redesign/Kit/SGRedesign.h), so an override left from Spotify's own screens cannot pull a redesigned-// one apart; then an override from the Flags page, then the flags of Spotify's own newer design, which-// it ships switched off and Redesigned UI turns on.+// keyed "component.property". The value handed back is Core/SGFlagForce.h's: what the redesign forces+// (Redesigned/Kit/SGRedesign.h), which comes before an override so one left from Spotify's own screens+// cannot pull a redesigned one apart, then an override from the Flags page, then what the ad blocking+// and the lyrics sources force.#import "Core/SGCore.h"#import "Flags.h"-#import "Shared/AdBlock/AdBlock.h"-#import "Shared/LyricsSources/LyricsSources.h"-#import "Redesigned/Kit/SGRedesign.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 = SGRedesignForcedFlag(key);- if (!value) value = SGFlagOverride(key);- if (!value && SGFlag(SGKeySpotifyGlass, NO) && SGGlassOwnsFlag(key)) value = @YES;- if (!value && SGAdBlockForcesFlagOff(key)) value = @NO;- if (!value) value = SGLyricsForcedFlag(key);- return value;+ return SGForcedFlagValue(key);}static BOOL boolFor(NSString *key, BOOL orig) {@@ -82,17 +56,10 @@ static id enumFor(NSString *key, id orig) {}%end-%hook SPTHubViewController-- (BOOL)prefersLiquidGlassNavigationBar {- return SGFlag(SGKeySpotifyGlass, NO) ? YES : %orig;-}-%end-%ctor {%init;SGRequireClasses(@[@"_TtC22RemoteConfigurationSDK25ConfigurationProviderImpl",@"_TtC22RemoteConfigurationSDK35ObservableConfigurationProviderImpl",- @"SPTHubViewController",]);}diff --git a/tweak/Sources/Shared/Gestures/Gestures.h b/tweak/Sources/Shared/Gestures/Gestures.hindex 5ba83dd9..e51d0ef0 100644--- a/tweak/Sources/Shared/Gestures/Gestures.h+++ b/tweak/Sources/Shared/Gestures/Gestures.h@@ -37,3 +37,7 @@ void SGResetGestureZones(void);NSInteger SGGestureCellAt(CGPoint point, CGSize size);UIViewController *SGGesturesSettingsPage(void);++// Puts the double tap on `host`, the view the player's grid covers, while the switch is on; again on+// every layout pass of the host, so taps Spotify adds later still wait for it. Main thread.+void SGGestureAttach(UIView *host);diff --git a/tweak/Sources/Shared/Gestures/Gestures.x b/tweak/Sources/Shared/Gestures/Gestures.xindex f0eb1679..5ecb5757 100644--- a/tweak/Sources/Shared/Gestures/Gestures.x+++ b/tweak/Sources/Shared/Gestures/Gestures.x@@ -1,8 +1,6 @@-// A double tap on the player, read against the grid Settings draws.-//-// Tree (trees/now-playing.txt): the artwork sits in AccessibleCollectionView, a full screen list of-// the queue scrolled sideways, so the recognizer goes on that and the grid is the screen. Spotify's-// controls are sibling units rather than children of it, so a tap on a button never reaches here.+// A double tap on the player, read against the grid Settings draws: the recognizer, what each cell does+// and the playback controller it does it with. Which view of the player it goes on is each look's own+// hookup (Native/Player/PlayerGestures.x, Redesigned/Player/PlayerGestures.x), which call SGGestureAttach.//// The player already answers a sideways swipe with the next track and a vertical drag with the// cards below, which leaves the double tap as the one gesture free to take.@@ -101,7 +99,8 @@ static NSUInteger tapsAbove(UIView *host) {return count;}-static void attachTap(UIView *host) {+void SGGestureAttach(UIView *host) {+ if (!host || !SGFlag(SGKeyGestures, NO)) return;UITapGestureRecognizer *tap = objc_getAssociatedObject(host, &kTapKey);if (!tap) {tap = [[UITapGestureRecognizer alloc] initWithTarget:target() action:@selector(doubleTapped:)];@@ -129,25 +128,7 @@ static void attachTap(UIView *host) {// A single tap on the cover is Spotify's way into the tilt mode, the artwork alone in 3D. That is// the half of a double tap that misses, so while the zones are on it would open on the way to every// gesture; the tap goes back to Spotify with the switch.-%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView-- (void)handleTap {- if (SGFlag(SGKeyGestures, NO)) return;- %orig;-}-%end--%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView-- (void)layoutSubviews {- %orig;- if (SGFlag(SGKeyGestures, NO)) attachTap((UIView *)self);-}-%end-%ctor {%init;- SGRequireClasses(@[- @"SPTNowPlayingPlaybackControllerImplementation",- @"_TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView",- @"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView",- ]);+ SGRequireClasses(@[@"SPTNowPlayingPlaybackControllerImplementation"]);}diff --git a/tweak/Sources/Shared/Lyrics/KaraokeSource.x b/tweak/Sources/Shared/Lyrics/KaraokeSource.xindex 8b240800..d3488bd7 100644--- a/tweak/Sources/Shared/Lyrics/KaraokeSource.x+++ b/tweak/Sources/Shared/Lyrics/KaraokeSource.x@@ -2,7 +2,7 @@// the same URLSession delegates AdBlock/AdNetwork.x reads, untouched, and kept per track, since the// page may open long after the request finished. The clock is SPTEsperantoPlayer's state, asked for on// every frame: the player is caught the first time the app asks it, and its position runs on by itself.-// With a source of the mod's on, the color-lyrics body is Features/LyricsSources' to answer and it+// With a source of the mod's on, the color-lyrics body is Shared/LyricsSources' to answer and it// hands the lines over.#import "Core/SGCore.h"#import "Lyrics.h"diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.hindex 290a2d37..2b8a1e5f 100644--- a/tweak/Sources/Shared/Lyrics/Lyrics.h+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h@@ -1,13 +1,18 @@-// Apple Music style lyrics on the full screen lyrics page: the line being sung lights up word by-// word, the rest dim and blur with distance. Spotify only times whole lines, so the words inside a-// line are timed by an estimate (KaraokeTiming.m), unless a source of the mod's times them. The-// lines are read from the color-lyrics response as it arrives, or handed over by-// Features/LyricsSources, and the position from the player's state (KaraokeSource.x); a track-// without synced lyrics keeps Spotify's own page.+// Apple Music style lyrics, the engine both looks draw from: the line being sung lights up word by+// word. Spotify only times whole lines, so the words inside a line are timed by an estimate+// (KaraokeTiming.m), unless a source of the mod's times them. The lines are read from the color-lyrics+// response as it arrives, or handed over by Shared/LyricsSources, and the position from the player's+// state (KaraokeSource.x); a track without synced lyrics keeps Spotify's own page. What draws them is+// each look's own: Native/Lyrics/KaraokeView.h and Redesigned/Lyrics/SGRKaraokeView.h.#import <UIKit/UIKit.h>#define SGKeyKaraokeLyrics @"spotifyglass.karaokeLyrics"+@class SGModRow, SGModSection;+// LyricsSettings.m: the Lyrics page's rows for either look.+NSArray<SGModRow *> *SGLyricsLookRows(void);+NSArray<SGModSection *> *SGLyricsSourceSections(void);+// Which edge a line is laid against. Apple Music puts a duet's second voice against the far one, so// the two sides of the song read apart; a track sung by one voice stays leading throughout.typedef NS_ENUM(NSUInteger, SGKaraokeAlign) {@@ -64,11 +69,3 @@ id SGKaraokePlayer(void); // SPTEsperantoPlayer, nil before the aSPTPlayerTrack *SGKaraokeTrackFor(NSString *trackID);// Keeps a track seen elsewhere, so a source can name it before the player has reported it.void SGKaraokeRememberTrack(SPTPlayerTrack *track);--@interface SGKaraokeView : UIView-// Compact is the card under the player: Spotify's own type size, no seeking by tap and no margin of-// its own, since the card already insets what it holds. initWithFrame: is the full screen page.-- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact;-// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.-- (void)syncSiblings;-@enddiff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.mnew file mode 100644index 00000000..13d2075c--- /dev/null+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m@@ -0,0 +1,41 @@+// What the Lyrics page holds for either look: Apple Music style, the lock screen, where lyrics come from+// and Spotify's lyrics flags. The page itself is App/Pages.m's, which adds the native look's glass row.+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Lyrics.h"+#import "Shared/LockScreenLyrics/LockScreenLyrics.h"+#import "Shared/LyricsSources/LyricsSources.h"++NSArray<SGModRow *> *SGLyricsLookRows(void) {+ return @[+ SGOptionRow(@"Apple Music style", @"Word by word on the full screen page; timing inside a line is estimated unless Musixmatch has it", SGKeyKaraokeLyrics),+ SGOptionRow(@"Lyrics on the lock screen", @"The line being sung in place of the artist, also in the Dynamic Island, Control Center and CarPlay", SGKeyLockScreenLyrics),+ ];+}++NSArray<SGModSection *> *SGLyricsSourceSections(void) {+ // The row reads the order out, so which sources are on is visible without opening it.+ SGModRow *sources = SGPageRow(@"Lyrics sources", ^UIViewController *{ return SGLyricsSourcesPage(); });+ sources.subtitle = @"BiniLyrics, Musixmatch, Unison, NetEase and LRCLIB, in the order you put them";+ sources.value = ^NSString *{+ NSMutableArray<NSString *> *names = [NSMutableArray array];+ for (NSString *key in SGLyricsOrder()) [names addObject:SGLyricsProviderFor(key).name];+ return names.count ? [names componentsJoinedByString:@", "] : @"Off";+ };+ return @[+ SGNotedSection(@"Where lyrics come from", @[+ sources,+ SGOptionRow(@"Lyrics for every track", @"Offers the lyrics card on tracks Spotify has no lyrics for; needs a source above", SGKeyLyricsAllTracks),+ SGOptionRow(@"Name the source", @"Reads out which source the lines on the full screen page came from", SGKeyLyricsCredit),+ ], @"With no source on, Spotify's own lyrics are left alone."),+ 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(@"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(@"Lyrics toggle in the context menu", @"ios-feature-lyrics.lyrics_context_menu_toggle_enabled"),+ ]),+ ];+}diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.mindex abd20ffc..8a58b313 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m@@ -419,6 +419,11 @@ id SGLyricsForcedFlag(NSString *key) {return nil;}+// After an override; no row shows the timeout, so nothing is locked.+__attribute__((constructor)) static void registerForcer(void) {+ SGRegisterFlagForcer(NO, ^id(NSString *key) { return SGLyricsForcedFlag(key); }, nil);+}+NSString *SGLyricsCreditFor(NSString *trackID) {setUp();@synchronized (sg_credits) { return trackID ? sg_credits[trackID] : nil; }diff --git a/tweak/Sources/Shared/Navigation/Links.h b/tweak/Sources/Shared/Navigation/Links.hnew file mode 100644index 00000000..0e9d2c0f--- /dev/null+++ b/tweak/Sources/Shared/Navigation/Links.h@@ -0,0 +1,7 @@+// Opening a spotify: URI the way the app opens a link of its own, through its link dispatcher: the+// tabs of the mod's own on either look's bar, the redesigned player's lyrics glyph.+#import <Foundation/Foundation.h>++// NO before the dispatcher is set up, or for a nil URI.+BOOL SGOpenSpotifyURI(NSURL *uri);+id SGLinkDispatcher(void); // SPTLinkDispatcherImplementation, nil until it is set updiff --git a/tweak/Sources/Shared/Navigation/Links.x b/tweak/Sources/Shared/Navigation/Links.xnew file mode 100644index 00000000..cd50014f--- /dev/null+++ b/tweak/Sources/Shared/Navigation/Links.x@@ -0,0 +1,30 @@+// The dispatcher is a singleton the app builds at startup; -setMainUILoaded: is the last call of its+// setup (objc-methods.txt:38809).+#import "Core/SGCore.h"+#import "Headers/SPTLinkDispatcherImplementation.h"+#import "Links.h"++static __weak SPTLinkDispatcherImplementation *sg_linkDispatcher;++id SGLinkDispatcher(void) {+ return sg_linkDispatcher;+}++BOOL SGOpenSpotifyURI(NSURL *uri) {+ SPTLinkDispatcherImplementation *dispatcher = sg_linkDispatcher;+ if (!uri || ![dispatcher respondsToSelector:@selector(navigateToURI:options:interactionID:)]) return NO;+ [dispatcher navigateToURI:uri options:0 interactionID:nil];+ return YES;+}++%hook SPTLinkDispatcherImplementation+- (void)setMainUILoaded:(BOOL)loaded {+ %orig;+ sg_linkDispatcher = (SPTLinkDispatcherImplementation *)self;+}+%end++%ctor {+ %init;+ SGRequireClasses(@[@"SPTLinkDispatcherImplementation"]);+}diff --git a/tweak/Sources/Shared/Player/PlayerEvents.h b/tweak/Sources/Shared/Player/PlayerEvents.hnew file mode 100644index 00000000..9190da90--- /dev/null+++ b/tweak/Sources/Shared/Player/PlayerEvents.h@@ -0,0 +1,10 @@+// The full screen player's open and close, for whatever must stand still while it animates (the+// karaoke card puts its display link down, the redesign holds heavy work back). Both looks' players are+// presented by Spotify's own presentation controller, so one announcement serves both.+#import <UIKit/UIKit.h>++// Posted as the player starts to open or close, before the animation runs, and again once it is+// over; SGPlayerTransitionEnds says when it is expected to be over (as CACurrentMediaTime), 0 when none runs.+extern NSString *const SGPlayerTransitionNotification;+extern NSString *const SGPlayerTransitionEndedNotification;+CFTimeInterval SGPlayerTransitionEnds(void);diff --git a/tweak/Sources/Shared/Player/PlayerEvents.x b/tweak/Sources/Shared/Player/PlayerEvents.xnew file mode 100644index 00000000..6d2d9862--- /dev/null+++ b/tweak/Sources/Shared/Player/PlayerEvents.x@@ -0,0 +1,48 @@+// The player's open and close, told from the appearance callbacks of a controller inside the player,+// which UIKit sends as the presentation or the dismissal begins, whatever animates it; the transition+// coordinator says when it is over, a cancelled swipe included. Spotify 9.1.78 presents the player+// through SPTBarInteractivePresentationController, never through NowPlaying_ViewPageImpl's+// Show/CloseFullscreenAnimatedTransitioning animators, whose hooks never once fired.+#import "Core/SGCore.h"+#import "PlayerEvents.h"++NSString *const SGPlayerTransitionNotification = @"spotifyglass.playerTransition";+NSString *const SGPlayerTransitionEndedNotification = @"spotifyglass.playerTransitionEnded";+static CFTimeInterval sg_transitionEnds;+static NSUInteger sg_transitionGeneration;++CFTimeInterval SGPlayerTransitionEnds(void) {+ return sg_transitionEnds > CACurrentMediaTime() ? sg_transitionEnds : 0;+}++static void announceTransition(UIViewController *unit, BOOL animated, NSString *what) {+ id<UIViewControllerTransitionCoordinator> coordinator = unit.transitionCoordinator;+ if (!animated || !coordinator) return;+ NSTimeInterval duration = MAX(0.1, coordinator.transitionDuration);+ NSUInteger generation = ++sg_transitionGeneration;+ sg_transitionEnds = CACurrentMediaTime() + duration;+ [NSNotificationCenter.defaultCenter postNotificationName:SGPlayerTransitionNotification object:nil];+ [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {+ if (generation != sg_transitionGeneration) return;+ sg_transitionEnds = 0;+ [NSNotificationCenter.defaultCenter postNotificationName:SGPlayerTransitionEndedNotification object:nil];+ }];+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"player %@ over %.2fs, by its appearance callbacks", what, duration); });+}++%hook _TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController+- (void)viewWillAppear:(BOOL)animated {+ %orig;+ announceTransition((UIViewController *)self, animated, @"opens");+}+- (void)viewWillDisappear:(BOOL)animated {+ %orig;+ announceTransition((UIViewController *)self, animated, @"closes");+}+%end++%ctor {+ %init;+ SGRequireClasses(@[@"_TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController"]);+}diff --git a/tweak/Sources/Shared/Player/PlayerSettings.h b/tweak/Sources/Shared/Player/PlayerSettings.hnew file mode 100644index 00000000..29ac7011--- /dev/null+++ b/tweak/Sources/Shared/Player/PlayerSettings.h@@ -0,0 +1,4 @@+// Settings of the player that hold for either look.+#import <UIKit/UIKit.h>++UIViewController *SGLockScreenWidgetPage(void);diff --git a/tweak/Sources/Shared/Player/PlayerSettings.m b/tweak/Sources/Shared/Player/PlayerSettings.mnew file mode 100644index 00000000..5ecc8527--- /dev/null+++ b/tweak/Sources/Shared/Player/PlayerSettings.m@@ -0,0 +1,26 @@+// The player's settings that do not depend on the look: the lock screen widget's flags.+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "PlayerSettings.h"++// Flag rows show the flag's name as their subtitle by default.+static SGModRow *bare(SGModRow *row) {+ row.subtitle = nil;+ return row;+}++UIViewController *SGLockScreenWidgetPage(void) {+ return [[SGModPage alloc] initWithTitle:@"Lock screen widget" intro:SGRestartNote sections:@[+ SGSection(@"Controls", @[+ bare(SGFlagRow(@"Like and dislike buttons", @"ios-feature-lockscreen.like_dislike_enabled")),+ bare(SGFlagRow(@"Skip button on podcasts", @"ios-feature-lockscreen.skip_button_on_podcasts")),+ bare(SGFlagRow(@"Chapter skip controls", @"ios-feature-lockscreen.enable_chapter_skip_controls")),+ bare(SGFlagRow(@"Burst skip", @"ios-feature-lockscreen.burst_skip_enabled")),+ ]),+ SGSection(@"Artwork", @[+ bare(SGFlagRow(@"Animated artwork", @"ios-feature-lockscreen.animated_artwork_enabled")),+ bare(SGFlagRow(@"Video artwork", @"ios-feature-lockscreen.vit_artwork_enabled")),+ bare(SGFlagRow(@"Companion content", @"ios-feature-lockscreen.companion_content_enabled")),+ ]),+ ] footer:nil];+}