Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: Add a tab opens a sheet with a name, link and icon picker
My-Name-Is-Jeff8c8a08e245f8
diff --git a/harness/addtab/README.md b/harness/addtab/README.mdnew file mode 100644index 00000000..758567b7--- /dev/null+++ b/harness/addtab/README.md@@ -0,0 +1,22 @@+# Add a Tab harness++The Add a Tab sheet (`Shared/Navigation/AddTabSheet.m`) and the icon catalogues (`TabIcons.m`) run for+real in the simulator, over a stand-in for Spotify's `SPTEncoreIcon` (eight glyphs drawn as SF Symbols,+plus class methods that are not glyphs) and `SPTEncoreIconView`. `Links.x` is compiled as it is; with no+link dispatcher every route is "unknown", which lets a link through as it does before Spotify sets the+dispatcher up.++ THEOS=$HOME/theos ./build.sh+ xcrun simctl install <udid> build/AddTabHarness.app+ xcrun simctl launch <udid> com.vitrine.addtabharness added+ xcrun simctl io <udid> screenshot shot.png+ xcrun simctl spawn <udid> log show --last 1m --style compact --predicate 'process == "AddTabHarness" AND (eventMessage CONTAINS "[harness]" OR eventMessage CONTAINS "add tab")'++Launch words: `sheet` the sheet as it opens; `preset` Liked Songs picked, which fills the name and the+icon; `glyphs` Choose an Icon on Encore; `symbols` Choose an Icon searching SF Symbols for "heart";+`pick` one of those results tapped while the search is up, then the page it lands on logged; `added`+Liked Songs with the SF Symbol music.mic added, the tab logged. The glyphs the enumeration kept and how+long the SF Symbol list took to read are logged on every launch.++What it does not cover: Spotify's real Encore classes and router, a real finger (the steps call the+table's delegate and set the search text), the keyboard over the compact detent, and iPad.diff --git a/harness/addtab/build.sh b/harness/addtab/build.shnew file mode 100755index 00000000..31e47b5c--- /dev/null+++ b/harness/addtab/build.sh@@ -0,0 +1,44 @@+#!/bin/sh+set -e+# The sources of the checkout this harness sits in, unless SRC names others.+SRC=${SRC:-$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)}+OUT=$(dirname "$0")/build+rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/AddTabHarness.app"+"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Shared/Navigation/Links.x" > "$OUT/gen/Links.m"++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \+ -I"$SRC" -I"$SRC/Shared/Navigation" -isysroot "$SDK" -Wno-deprecated-declarations \+ "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" "$OUT/gen/Links.m" \+ "$SRC"/Shared/Navigation/AddTabSheet.m "$SRC"/Shared/Navigation/TabIcons.m \+ "$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m \+ "$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \+ "$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation \+ -o "$OUT/AddTabHarness.app/AddTabHarness"++# iOS 27 ends an app without a scene delegate at launch, so the scene is named here.+cat > "$OUT/AddTabHarness.app/Info.plist" <<'PLIST'+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0"><dict>+<key>CFBundleExecutable</key><string>AddTabHarness</string>+<key>CFBundleIdentifier</key><string>com.vitrine.addtabharness</string>+<key>CFBundleName</key><string>AddTabHarness</string>+<key>CFBundleVersion</key><string>1</string>+<key>CFBundleShortVersionString</key><string>1.0</string>+<key>UIUserInterfaceStyle</key><string>Dark</string>+<key>UILaunchScreen</key><dict/>+<key>UIApplicationSceneManifest</key><dict>+ <key>UIApplicationSupportsMultipleScenes</key><false/>+ <key>UISceneConfigurations</key><dict>+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>+ <key>UISceneConfigurationName</key><string>Default</string>+ <key>UISceneDelegateClassName</key><string>SGHarnessScene</string>+ </dict></array>+ </dict>+</dict>+</dict></plist>+PLIST+codesign -f -s - "$OUT/AddTabHarness.app" >/dev/null 2>&1+echo "built $OUT/AddTabHarness.app"diff --git a/harness/addtab/main.m b/harness/addtab/main.mnew file mode 100644index 00000000..b418aa6f--- /dev/null+++ b/harness/addtab/main.m@@ -0,0 +1,157 @@+// Add a Tab harness: Shared/Navigation/AddTabSheet.m and TabIcons.m run for real in the simulator, over a+// stand-in for Spotify's Encore classes (a few glyphs drawn as SF Symbols), with Links.x compiled as it+// is (no dispatcher, so every link is "unknown" and let through, as before Spotify has set it up).+#import <UIKit/UIKit.h>+#import <objc/message.h>+#import "Shared/Navigation/AddTabSheet.h"+#import "Shared/Navigation/TabIcons.h"++#pragma mark - Spotify's classes, by the names TabIcons.m looks for++@interface SGHarnessGlyph : NSObject+@property (nonatomic, copy) NSString *name;+@end+@implementation SGHarnessGlyph+@end++@interface SPTEncoreIcon : NSObject+@end+@implementation SPTEncoreIcon+static id glyph(NSString *name) { SGHarnessGlyph *g = [SGHarnessGlyph new]; g.name = name; return g; }++ (id)home { return glyph(@"home"); }++ (id)search { return glyph(@"search"); }++ (id)heart { return glyph(@"heart"); }++ (id)podcasts { return glyph(@"podcasts"); }++ (id)star { return glyph(@"star"); }++ (id)playlist { return glyph(@"playlist"); }++ (id)plus { return glyph(@"plus"); }++ (id)queue { return glyph(@"queue"); }+// Not glyphs: one takes an argument, one returns no object, one has no name.++ (id)iconNamed:(NSString *)name { return glyph(name); }++ (NSInteger)count { return 8; }++ (id)helper { return [NSObject new]; }+@end++@interface SPTEncoreIconView : UIImageView+- (instancetype)initWithIcon:(id)icon;+- (void)setForegroundColor:(UIColor *)color;+@end+@implementation SPTEncoreIconView+- (instancetype)initWithIcon:(id)icon {+ NSDictionary *symbols = @{@"home": @"house", @"search": @"magnifyingglass", @"heart": @"heart", @"podcasts": @"mic",+ @"star": @"star", @"playlist": @"music.note.list", @"plus": @"plus", @"queue": @"list.bullet"};+ if (!(self = [super initWithImage:[UIImage systemImageNamed:symbols[[icon name]] ?: @"questionmark"]])) return nil;+ self.contentMode = UIViewContentModeScaleAspectFit;+ return self;+}+- (void)setForegroundColor:(UIColor *)color { self.tintColor = color; }+@end++#pragma mark - the app++@interface SGHarnessRoot : UIViewController+@end+@implementation SGHarnessRoot+- (void)viewDidLoad {+ [super viewDidLoad];+ self.view.backgroundColor = UIColor.blackColor;+}+@end++@interface SGHarnessScene : UIResponder <UIWindowSceneDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++static void after(double seconds, dispatch_block_t block) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);+}++static UITableViewController *topPage(UIViewController *root) {+ UINavigationController *nav = (UINavigationController *)root.presentedViewController;+ return (UITableViewController *)nav.topViewController;+}++static void tap(UITableViewController *page, NSInteger section, NSInteger row) {+ NSLog(@"[harness] tap %ld.%ld on %@", (long)section, (long)row, page.title);+ [page.tableView.delegate tableView:page.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];+}++@implementation SGHarnessScene++// Launch words: `sheet` the sheet as it opens; `preset` Liked Songs picked from Choose a Link; `glyphs`+// Choose an Icon on Encore; `symbols` Choose an Icon searching SF Symbols for "heart"; `pick` one of its results+// tapped mid-search; `added` Liked Songs with+// the SF Symbol music.mic added, the tab logged. The glyph enumeration and the symbol list's size and time are logged.+- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)options {+ self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];+ SGHarnessRoot *root = [SGHarnessRoot new];+ self.window.rootViewController = root;+ [self.window makeKeyAndVisible];+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;+ NSString *mode = args.count > 1 ? args[1] : @"sheet";++ NSLog(@"[harness] glyphs %@", SGEncoreGlyphNames());+ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();+ SGLoadSymbolNames(^(NSArray<NSString *> *names) {+ NSLog(@"[harness] %lu symbols in %.2f s, first %@, has heart.circle %d, has a .ar %d", (unsigned long)names.count,+ CFAbsoluteTimeGetCurrent() - start, names.firstObject, [names containsObject:@"heart.circle"],+ [names containsObject:@"0.circle.ar"]);+ });++ NSArray *presets = @[+ @{SGTabTitle: @"Liked Songs", SGTabURI: @"spotify:collection:tracks", SGTabIcon: @"heart"},+ @{SGTabTitle: @"Podcasts", SGTabURI: @"spotify:collection:podcasts", SGTabIcon: @"podcasts"},+ @{SGTabTitle: @"Queue", SGTabURI: @"spotify:now-playing:queue", SGTabIcon: @"queue"},+ ];+ after(0.5, ^{+ SGPresentAddTabSheet(root, presets, ^(NSDictionary *tab) { NSLog(@"[harness] added %@", tab); });+ });+ if ([mode isEqualToString:@"sheet"]) return;+ after(2.5, ^{ tap(topPage(root), 1, 0); });+ after(3.5, ^{+ if ([mode isEqualToString:@"preset"] || [mode isEqualToString:@"added"]) tap(topPage(root), 0, 0);+ else [topPage(root).navigationController popViewControllerAnimated:NO];+ });+ if ([mode isEqualToString:@"preset"]) return;+ after(4.5, ^{ tap(topPage(root), 1, 1); });+ if ([mode isEqualToString:@"glyphs"]) return;+ after(5.5, ^{+ UITableViewController *page = topPage(root);+ UISegmentedControl *sets = (UISegmentedControl *)page.navigationItem.titleView;+ sets.selectedSegmentIndex = 1;+ [sets sendActionsForControlEvents:UIControlEventValueChanged];+ if (![mode isEqualToString:@"symbols"] && ![mode isEqualToString:@"pick"]) return;+ page.navigationItem.searchController.active = YES;+ page.navigationItem.searchController.searchBar.text = @"heart";+ [page.navigationItem.searchController.searchResultsUpdater updateSearchResultsForSearchController:page.navigationItem.searchController];+ });+ if ([mode isEqualToString:@"symbols"]) return;+ // `pick`: a result tapped while the search is still up, as a finger would.+ if ([mode isEqualToString:@"pick"]) {+ after(7.0, ^{+ UITableViewController *page = topPage(root);+ NSLog(@"[harness] before pick: active %d, page presents %@, nav presents %@, search bar in window %d, rows %ld", page.navigationItem.searchController.active,+ page.presentedViewController, page.navigationController.presentedViewController,+ page.navigationItem.searchController.searchBar.window != nil, (long)[page.tableView numberOfRowsInSection:0]);+ tap(page, 0, 0);+ });+ after(9.5, ^{ NSLog(@"[harness] after pick: %@", topPage(root).title); });+ return;+ }+ after(7.0, ^{+ tap(topPage(root), 0, 6);+ });+ after(8.5, ^{+ UIBarButtonItem *add = topPage(root).navigationItem.rightBarButtonItem;+ NSLog(@"[harness] add enabled %d", add.enabled);+ ((void (*)(id, SEL))objc_msgSend)(add.target, add.action);+ });+}++@end++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, nil);+ }+}diff --git a/harness/addtab/stubs.m b/harness/addtab/stubs.mnew file mode 100644index 00000000..085483df--- /dev/null+++ b/harness/addtab/stubs.m@@ -0,0 +1,4 @@+// What the harness does not compile: Mod Settings' opener, which SGPage.h declares.+#import <UIKit/UIKit.h>++void SGOpenModSettings(UIView *source) {}diff --git a/tweak/Sources/Native/Navbar/Navbar.h b/tweak/Sources/Native/Navbar/Navbar.hindex 3491c4dd..e839abd7 100644--- a/tweak/Sources/Native/Navbar/Navbar.h+++ b/tweak/Sources/Native/Navbar/Navbar.h@@ -8,7 +8,8 @@extern NSString *const SGNavbarID; // NSString, the entry's identityextern NSString *const SGNavbarTitle; // NSString, the name in the settings list and under the iconextern NSString *const SGNavbarURI; // NSString, the mod's own tabs only: what a tap opens-extern NSString *const SGNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts"+extern NSString *const SGNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts", or an SF Symbol+extern NSString *const SGNavbarIconSet; // NSString, SGTabIconSetSymbols when the icon is an SF Symbol; none is Encoreextern NSString *const SGNavbarHidden; // NSNumberNSArray<NSDictionary *> *SGNavbarLayout(void);void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);diff --git a/tweak/Sources/Native/Navbar/Navbar.x b/tweak/Sources/Native/Navbar/Navbar.xindex 5346e2e6..3fcc0477 100644--- a/tweak/Sources/Native/Navbar/Navbar.x+++ b/tweak/Sources/Native/Navbar/Navbar.x@@ -15,8 +15,8 @@// 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 "Shared/Navigation/TabIcons.h"#import <objc/message.h>static const CGFloat kIconSize = 24;@@ -42,27 +42,10 @@ static UIColor *itemColor(void) { return [UIColor colorWithWhite:0xB3 / 255.0 al#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;+// Drawn the way Spotify's own are, an Encore glyph or an SF Symbol at the glyphs' size+// (Shared/Navigation/TabIcons.h).+static UIView *iconView(NSDictionary *entry) {+ return SGTabIconView(entry[SGNavbarIcon], [entry[SGNavbarIconSet] isEqual:SGTabIconSetSymbols], itemColor());}@interface SGTabItemView : UIControl@@ -91,11 +74,12 @@ static UIView *iconView(NSString *name) {- (void)applyEntry:(NSDictionary *)entry {self.uri = entry[SGNavbarURI];_title.text = entry[SGNavbarTitle];- NSString *name = entry[SGNavbarIcon] ?: @"star";+ // The set is part of the name: "star" is a glyph in one and a symbol in the other.+ NSString *name = [NSString stringWithFormat:@"%@ %@", entry[SGNavbarIconSet] ?: @"encore", entry[SGNavbarIcon] ?: @"star"];if ([name isEqualToString:_iconName]) return;[_icon removeFromSuperview];_iconName = [name copy];- _icon = iconView(name);+ _icon = iconView(entry);// Encore's views lay themselves out from constraints; this one is placed by frame._icon.translatesAutoresizingMaskIntoConstraints = YES;[self addSubview:_icon];diff --git a/tweak/Sources/Native/Navbar/NavbarLayout.m b/tweak/Sources/Native/Navbar/NavbarLayout.mindex f4666be0..a3cf249f 100644--- a/tweak/Sources/Native/Navbar/NavbarLayout.m+++ b/tweak/Sources/Native/Navbar/NavbarLayout.m@@ -5,6 +5,7 @@ NSString *const SGNavbarID = @"id";NSString *const SGNavbarTitle = @"title";NSString *const SGNavbarURI = @"uri";NSString *const SGNavbarIcon = @"icon";+NSString *const SGNavbarIconSet = @"iconSet";NSString *const SGNavbarHidden = @"hidden";static NSString *const kNavbarLayout = @"spotifyglass.navbar.layout";diff --git a/tweak/Sources/Native/Navbar/NavbarSettings.m b/tweak/Sources/Native/Navbar/NavbarSettings.mindex 66ff83fd..4ae1f085 100644--- a/tweak/Sources/Native/Navbar/NavbarSettings.m+++ b/tweak/Sources/Native/Navbar/NavbarSettings.m@@ -2,28 +2,29 @@#import "Settings/SGPage.h"#import "Settings/SGPageStyle.h"#import "Navbar.h"+#import "Shared/Navigation/AddTabSheet.h"// What "Add a tab" offers: URIs Spotify's own router resolves to a page of its own, each with the// name of the SPTEncoreIcon class method that draws its glyph.static NSArray<NSDictionary *> *tabPresets(void) {return @[- @{SGNavbarTitle: @"Home", SGNavbarURI: @"spotify:home", SGNavbarIcon: @"home"},- @{SGNavbarTitle: @"Search", SGNavbarURI: @"spotify:search", SGNavbarIcon: @"search"},- @{SGNavbarTitle: @"Your Library", SGNavbarURI: @"spotify:collection", SGNavbarIcon: @"collection"},- @{SGNavbarTitle: @"Liked Songs", SGNavbarURI: @"spotify:collection:tracks", SGNavbarIcon: @"heart"},- @{SGNavbarTitle: @"Playlists", SGNavbarURI: @"spotify:playlists", SGNavbarIcon: @"playlist"},- @{SGNavbarTitle: @"Albums", SGNavbarURI: @"spotify:collection:albums", SGNavbarIcon: @"album"},- @{SGNavbarTitle: @"Artists", SGNavbarURI: @"spotify:collection:artists", SGNavbarIcon: @"artist"},- @{SGNavbarTitle: @"Podcasts", SGNavbarURI: @"spotify:collection:podcasts", SGNavbarIcon: @"podcasts"},- @{SGNavbarTitle: @"Audiobooks", SGNavbarURI: @"spotify:collection:audiobooks", SGNavbarIcon: @"audiobook"},- @{SGNavbarTitle: @"Downloads", SGNavbarURI: @"spotify:collection:downloads", SGNavbarIcon: @"downloaded"},- @{SGNavbarTitle: @"Your Episodes", SGNavbarURI: @"spotify:collection:your-episodes", SGNavbarIcon: @"bookmark"},- @{SGNavbarTitle: @"Browse", SGNavbarURI: @"spotify:browse", SGNavbarIcon: @"browse"},- @{SGNavbarTitle: @"New Releases", SGNavbarURI: @"spotify:new-releases", SGNavbarIcon: @"star"},- @{SGNavbarTitle: @"Made For You", SGNavbarURI: @"spotify:made-for-you", SGNavbarIcon: @"user"},- @{SGNavbarTitle: @"Concerts", SGNavbarURI: @"spotify:concerts", SGNavbarIcon: @"events"},- @{SGNavbarTitle: @"Queue", SGNavbarURI: @"spotify:now-playing:queue", SGNavbarIcon: @"queue"},- @{SGNavbarTitle: @"Create", SGNavbarURI: @"spotify:create-menu", SGNavbarIcon: @"plus"},+ @{SGTabTitle: @"Home", SGTabURI: @"spotify:home", SGTabIcon: @"home"},+ @{SGTabTitle: @"Search", SGTabURI: @"spotify:search", SGTabIcon: @"search"},+ @{SGTabTitle: @"Your Library", SGTabURI: @"spotify:collection", SGTabIcon: @"collection"},+ @{SGTabTitle: @"Liked Songs", SGTabURI: @"spotify:collection:tracks", SGTabIcon: @"heart"},+ @{SGTabTitle: @"Playlists", SGTabURI: @"spotify:playlists", SGTabIcon: @"playlist"},+ @{SGTabTitle: @"Albums", SGTabURI: @"spotify:collection:albums", SGTabIcon: @"album"},+ @{SGTabTitle: @"Artists", SGTabURI: @"spotify:collection:artists", SGTabIcon: @"artist"},+ @{SGTabTitle: @"Podcasts", SGTabURI: @"spotify:collection:podcasts", SGTabIcon: @"podcasts"},+ @{SGTabTitle: @"Audiobooks", SGTabURI: @"spotify:collection:audiobooks", SGTabIcon: @"audiobook"},+ @{SGTabTitle: @"Downloads", SGTabURI: @"spotify:collection:downloads", SGTabIcon: @"downloaded"},+ @{SGTabTitle: @"Your Episodes", SGTabURI: @"spotify:collection:your-episodes", SGTabIcon: @"bookmark"},+ @{SGTabTitle: @"Browse", SGTabURI: @"spotify:browse", SGTabIcon: @"browse"},+ @{SGTabTitle: @"New Releases", SGTabURI: @"spotify:new-releases", SGTabIcon: @"star"},+ @{SGTabTitle: @"Made For You", SGTabURI: @"spotify:made-for-you", SGTabIcon: @"user"},+ @{SGTabTitle: @"Concerts", SGTabURI: @"spotify:concerts", SGTabIcon: @"events"},+ @{SGTabTitle: @"Queue", SGTabURI: @"spotify:now-playing:queue", SGTabIcon: @"queue"},+ @{SGTabTitle: @"Create", SGTabURI: @"spotify:create-menu", SGTabIcon: @"plus"},];}@@ -50,107 +51,13 @@ static NSMutableArray<NSMutableDictionary *> *navbarEntries(void) {// A tab of the mod's own carries an identity of its own, so the same page can sit on the bar twice// and renaming one does not shuffle the order.static void appendTab(NSDictionary *tab) {- NSMutableDictionary *entry = [tab mutableCopy];- entry[SGNavbarID] = NSUUID.UUID.UUIDString;+ NSMutableDictionary *entry = [@{SGNavbarID: NSUUID.UUID.UUIDString, SGNavbarTitle: tab[SGTabTitle],+ SGNavbarURI: tab[SGTabURI], SGNavbarIcon: tab[SGTabIcon]} mutableCopy];+ entry[SGNavbarIconSet] = tab[SGTabIconSet];SGSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);SGRefreshTabBar();}-@interface SGTabPickerPage : SGPage-@end--@implementation SGTabPickerPage {- UIView *_footer;-}--- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;- self.title = @"Add a Tab";- return self;-}--- (void)viewDidLoad {- [super viewDidLoad];- _footer = SGNote(@"Paste a share link or a spotify: URI. Icons: home, search, collection, heart, "- "playlist, album, artist, podcasts, audiobook, downloaded, bookmark, browse, star, "- "user, events, queue, plus, radio, gears, spotifyLogo.");- self.tableView.tableFooterView = _footer;-}--- (void)viewWillLayoutSubviews {- [super viewWillLayoutSubviews];- SGFitNote(self.tableView, _footer, 16, 24);-}--- (void)viewDidLayoutSubviews {- [super viewDidLayoutSubviews];- SGInsetForBars(self.tableView);-}--- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {- return 2;-}--- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return section == 0 ? (NSInteger)tabPresets().count : 1;-}--- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {- return SGSectionHeader(table, section == 0 ? @"Spotify's pages" : @"Anywhere else");-}--- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;-}--- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {- return CGFLOAT_MIN;-}--- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {- UITableViewCell *cell = SGDequeueCell(table, @"pick");- if (path.section == 0) {- NSDictionary *tab = tabPresets()[(NSUInteger)path.row];- SGFillCell(cell, tab[SGNavbarTitle], tab[SGNavbarURI], nil, nil);- } else {- SGFillCell(cell, @"Any link…", nil, nil, @"link");- }- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- return cell;-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- [table deselectRowAtIndexPath:path animated:YES];- if (path.section == 0) {- appendTab(tabPresets()[(NSUInteger)path.row]);- [self.navigationController popViewControllerAnimated:YES];- return;- }- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Any link" message:@"Where the tab goes, and the glyph on it." preferredStyle:UIAlertControllerStyleAlert];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) { field.placeholder = @"Name"; }];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {- field.placeholder = @"spotify:playlist:…";- field.autocapitalizationType = UITextAutocapitalizationTypeNone;- field.autocorrectionType = UITextAutocorrectionTypeNo;- }];- [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {- field.placeholder = @"Icon";- field.text = @"star";- field.autocapitalizationType = UITextAutocapitalizationTypeNone;- field.autocorrectionType = UITextAutocorrectionTypeNo;- }];- [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- [alert addAction:[UIAlertAction actionWithTitle:@"Add" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {- NSString *title = alert.textFields[0].text, *uri = alert.textFields[1].text, *icon = alert.textFields[2].text;- if (!uri.length) return;- appendTab(@{SGNavbarTitle: title.length ? title : uri, SGNavbarURI: uri, SGNavbarIcon: icon.length ? icon : @"star"});- [self.navigationController popViewControllerAnimated:YES];- }]];- [self presentViewController:alert animated:YES completion:nil];-}--@end-typedef NS_ENUM(NSInteger, SGNavbarSection) {SGNavbarSectionSwitch,SGNavbarSectionTabs,@@ -185,9 +92,7 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {_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];+- (void)reload {_entries = navbarEntries();[self.tableView reloadData];}@@ -305,7 +210,11 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {[self save];[table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];} else if (path.section == SGNavbarSectionAdd) {- [self.navigationController pushViewController:[SGTabPickerPage new] animated:YES];+ __weak typeof(self) weakSelf = self;+ SGPresentAddTabSheet(self, tabPresets(), ^(NSDictionary *tab) {+ appendTab(tab);+ [weakSelf reload];+ });} else if (path.section == SGNavbarSectionReset) {[self reset];}diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hindex e49f59bf..d12bb80e 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.h+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -11,7 +11,8 @@extern NSString *const SGRNavbarID; // NSString, the entry's identityextern NSString *const SGRNavbarTitle; // NSString, the name in the settings list and under the iconextern 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 SGRNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts", or an SF Symbol+extern NSString *const SGRNavbarIconSet; // NSString, SGTabIconSetSymbols when the icon is an SF Symbol; none is Encoreextern NSString *const SGRNavbarHidden; // NSNumberNSArray<NSDictionary *> *SGRNavbarLayout(void);void SGRSetNavbarLayout(NSArray<NSDictionary *> *layout);diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.x b/tweak/Sources/Redesigned/Navbar/Navbar.xindex 8c295216..ca8d7432 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.x+++ b/tweak/Sources/Redesigned/Navbar/Navbar.x@@ -16,8 +16,8 @@// 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 "Shared/Navigation/TabIcons.h"#import <objc/message.h>static const CGFloat kIconSize = 24;@@ -43,27 +43,10 @@ static UIColor *itemColor(void) { return [UIColor colorWithWhite:0xB3 / 255.0 al#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;+// Drawn the way Spotify's own are, an Encore glyph or an SF Symbol at the glyphs' size+// (Shared/Navigation/TabIcons.h).+static UIView *iconView(NSDictionary *entry) {+ return SGTabIconView(entry[SGRNavbarIcon], [entry[SGRNavbarIconSet] isEqual:SGTabIconSetSymbols], itemColor());}@interface SGRTabItemView : UIControl@@ -92,11 +75,12 @@ static UIView *iconView(NSString *name) {- (void)applyEntry:(NSDictionary *)entry {self.uri = entry[SGRNavbarURI];_title.text = entry[SGRNavbarTitle];- NSString *name = entry[SGRNavbarIcon] ?: @"star";+ // The set is part of the name: "star" is a glyph in one and a symbol in the other.+ NSString *name = [NSString stringWithFormat:@"%@ %@", entry[SGRNavbarIconSet] ?: @"encore", entry[SGRNavbarIcon] ?: @"star"];if ([name isEqualToString:_iconName]) return;[_icon removeFromSuperview];_iconName = [name copy];- _icon = iconView(name);+ _icon = iconView(entry);// Encore's views lay themselves out from constraints; this one is placed by frame._icon.translatesAutoresizingMaskIntoConstraints = YES;[self addSubview:_icon];diff --git a/tweak/Sources/Redesigned/Navbar/NavbarLayout.m b/tweak/Sources/Redesigned/Navbar/NavbarLayout.mindex 7009ff1a..f7de2503 100644--- a/tweak/Sources/Redesigned/Navbar/NavbarLayout.m+++ b/tweak/Sources/Redesigned/Navbar/NavbarLayout.m@@ -6,6 +6,7 @@ NSString *const SGRNavbarID = @"id";NSString *const SGRNavbarTitle = @"title";NSString *const SGRNavbarURI = @"uri";NSString *const SGRNavbarIcon = @"icon";+NSString *const SGRNavbarIconSet = @"iconSet";NSString *const SGRNavbarHidden = @"hidden";static NSString *const kNavbarLayout = @"spotifyglass.redesign.navbar.layout";diff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.mindex 555d989e..99b7dd96 100644--- a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m@@ -2,7 +2,7 @@#import "Settings/SGPage.h"#import "Settings/SGPageStyle.h"#import "Navbar.h"-#import "Shared/Navigation/Links.h"+#import "Shared/Navigation/AddTabSheet.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. Playlists was spotify:collection:playlists@@ -11,23 +11,23 @@// The picker still asks the dispatcher about each one and leaves out what it has nowhere to send.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: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"},+ @{SGTabTitle: @"Home", SGTabURI: @"spotify:home", SGTabIcon: @"home"},+ @{SGTabTitle: @"Search", SGTabURI: @"spotify:search", SGTabIcon: @"search"},+ @{SGTabTitle: @"Your Library", SGTabURI: @"spotify:collection", SGTabIcon: @"collection"},+ @{SGTabTitle: @"Liked Songs", SGTabURI: @"spotify:collection:tracks", SGTabIcon: @"heart"},+ @{SGTabTitle: @"Playlists", SGTabURI: @"spotify:playlists", SGTabIcon: @"playlist"},+ @{SGTabTitle: @"Albums", SGTabURI: @"spotify:collection:albums", SGTabIcon: @"album"},+ @{SGTabTitle: @"Artists", SGTabURI: @"spotify:collection:artists", SGTabIcon: @"artist"},+ @{SGTabTitle: @"Podcasts", SGTabURI: @"spotify:collection:podcasts", SGTabIcon: @"podcasts"},+ @{SGTabTitle: @"Audiobooks", SGTabURI: @"spotify:collection:audiobooks", SGTabIcon: @"audiobook"},+ @{SGTabTitle: @"Downloads", SGTabURI: @"spotify:collection:downloads", SGTabIcon: @"downloaded"},+ @{SGTabTitle: @"Your Episodes", SGTabURI: @"spotify:collection:your-episodes", SGTabIcon: @"bookmark"},+ @{SGTabTitle: @"Browse", SGTabURI: @"spotify:browse", SGTabIcon: @"browse"},+ @{SGTabTitle: @"New Releases", SGTabURI: @"spotify:new-releases", SGTabIcon: @"star"},+ @{SGTabTitle: @"Made For You", SGTabURI: @"spotify:made-for-you", SGTabIcon: @"user"},+ @{SGTabTitle: @"Concerts", SGTabURI: @"spotify:concerts", SGTabIcon: @"events"},+ @{SGTabTitle: @"Queue", SGTabURI: @"spotify:now-playing:queue", SGTabIcon: @"queue"},+ @{SGTabTitle: @"Create", SGTabURI: @"spotify:create-menu", SGTabIcon: @"plus"},];}@@ -54,139 +54,13 @@ static NSMutableArray<NSMutableDictionary *> *navbarEntries(void) {// 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;+ NSMutableDictionary *entry = [@{SGRNavbarID: NSUUID.UUID.UUIDString, SGRNavbarTitle: tab[SGTabTitle],+ SGRNavbarURI: tab[SGTabURI], SGRNavbarIcon: tab[SGTabIcon]} mutableCopy];+ entry[SGRNavbarIconSet] = tab[SGTabIconSet];SGRSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);SGRRefreshTabBar();}-@interface SGRTabPickerPage : SGPage-@end--// The presets the dispatcher can send somewhere, each verdict logged. When it cannot be asked (not set-// up yet, or 9.1.78's registry is not where it was) every preset stays, as before.-static NSArray<NSDictionary *> *openablePresets(void) {- NSMutableArray<NSDictionary *> *kept = [NSMutableArray array];- for (NSDictionary *tab in tabPresets()) {- NSString *via = nil;- SGLinkRoute route = SGSpotifyURIRoute([NSURL URLWithString:tab[SGRNavbarURI]], &via);- SGLog(@"navbar: preset %@ -> %@", tab[SGRNavbarURI],- route == SGLinkRouteOpens ? via : route == SGLinkRouteNone ? @"no handler, left out" : @"unknown");- if (route != SGLinkRouteNone) [kept addObject:tab];- }- return kept;-}--@implementation SGRTabPickerPage {- UIView *_footer;- NSArray<NSDictionary *> *_presets;-}--- (instancetype)init {- if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;- self.title = @"Add a Tab";- _presets = openablePresets();- return self;-}--// Said here rather than by Spotify's alert on the bar later, every time the tab is tapped.-- (void)refuse:(NSString *)uri {- NSString *message = [NSString stringWithFormat:@"Spotify has nowhere to open %@, so it would not work as a tab.", uri];- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Can't open that link" message:message preferredStyle:UIAlertControllerStyleAlert];- [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];- [self presentViewController:alert animated:YES completion:nil];-}--- (void)viewDidLoad {- [super viewDidLoad];- _footer = SGNote(@"Paste a share link or a spotify: URI. Icons: 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)_presets.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 = _presets[(NSUInteger)path.row];- SGFillCell(cell, tab[SGRNavbarTitle], tab[SGRNavbarURI], nil, nil);- } else {- SGFillCell(cell, @"Any link…", nil, nil, @"link");- }- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- return cell;-}--- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {- [table deselectRowAtIndexPath:path animated:YES];- if (path.section == 0) {- appendTab(_presets[(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, *icon = alert.textFields[2].text;- NSString *uri = SGSpotifyURIFromText(alert.textFields[1].text).absoluteString;- if (!uri.length) return;- NSString *via = nil;- SGLinkRoute route = SGSpotifyURIRoute([NSURL URLWithString:uri], &via);- SGLog(@"navbar: custom %@ -> %@", uri, route == SGLinkRouteOpens ? via : route == SGLinkRouteNone ? @"no handler" : @"unknown");- if (route == SGLinkRouteNone) {- [self refuse:uri];- 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,@@ -221,9 +95,7 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {_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];+- (void)reload {_entries = navbarEntries();[self.tableView reloadData];}@@ -344,7 +216,11 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {[self save];[table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];} else if (path.section == SGRNavbarSectionAdd) {- [self.navigationController pushViewController:[SGRTabPickerPage new] animated:YES];+ __weak typeof(self) weakSelf = self;+ SGPresentAddTabSheet(self, tabPresets(), ^(NSDictionary *tab) {+ appendTab(tab);+ [weakSelf reload];+ });} else if (path.section == SGRNavbarSectionReset) {[self reset];}diff --git a/tweak/Sources/Shared/Navigation/AddTabSheet.h b/tweak/Sources/Shared/Navigation/AddTabSheet.hnew file mode 100644index 00000000..1352bbda--- /dev/null+++ b/tweak/Sources/Shared/Navigation/AddTabSheet.h@@ -0,0 +1,14 @@+// "Add a Tab", the same for either look: a sheet with the tab's name, the page it opens and the icon on+// it, each picked rather than typed (Choose a Link, Choose an Icon). The sheet stores nothing; the look's+// own editor keeps what it hands back in that look's list.+#import <UIKit/UIKit.h>++// The keys of a preset and of the tab handed back.+extern NSString *const SGTabTitle; // NSString+extern NSString *const SGTabURI; // NSString, a spotify: URI+extern NSString *const SGTabIcon; // NSString, an Encore glyph or an SF Symbol+extern NSString *const SGTabIconSet; // SGTabIconSetSymbols (TabIcons.h) for an SF Symbol, absent for Encore++// `presets` carry Encore icons; those Spotify's router has nowhere to send are left out. `add` is given+// the tab when Add is tapped, then the sheet goes; Cancel hands back nothing.+void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, void (^add)(NSDictionary *tab));diff --git a/tweak/Sources/Shared/Navigation/AddTabSheet.m b/tweak/Sources/Shared/Navigation/AddTabSheet.mnew file mode 100644index 00000000..70b91e3f--- /dev/null+++ b/tweak/Sources/Shared/Navigation/AddTabSheet.m@@ -0,0 +1,518 @@+#import "Core/SGCore.h"+#import "AddTabSheet.h"+#import "Links.h"+#import "TabIcons.h"+#import "Settings/SGPage.h"+#import "Settings/SGPageStyle.h"++NSString *const SGTabTitle = @"title";+NSString *const SGTabURI = @"uri";+NSString *const SGTabIcon = @"icon";+NSString *const SGTabIconSet = @"iconSet";++static NSString *const kCompactDetent = @"spotifyglass.addTab.compact";++// The tab being put together, shared by the sheet's three pages.+@interface SGTabDraft : NSObject+@property (nonatomic, copy) NSString *title, *uri, *icon;+@property (nonatomic) BOOL symbols;+// Once an icon is picked, a preset picked after it leaves the icon alone.+@property (nonatomic) BOOL iconChosen;+@end++@implementation SGTabDraft+@end++// What the dispatcher makes of a URI, logged, so a link left out or refused says why. Unknown (the+// dispatcher is not set up yet, or not where 9.1.78 keeps it) lets the link through, as before.+static SGLinkRoute routeOf(NSURL *url, NSString *what) {+ NSString *via = nil;+ SGLinkRoute route = SGSpotifyURIRoute(url, &via);+ SGLog(@"add tab: %@ %@ -> %@", what, url.absoluteString,+ route == SGLinkRouteOpens ? via : route == SGLinkRouteNone ? @"no handler" : @"unknown");+ return route;+}++static NSString *iconSummary(SGTabDraft *draft) {+ return [NSString stringWithFormat:@"%@ · %@", draft.symbols ? @"SF Symbols" : @"Spotify Encore", draft.icon];+}++// An icon at `size`, centred in a box of that size, for the right of a row.+static UIView *previewOf(NSString *name, BOOL symbols, CGFloat size) {+ UIView *box = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size, size)];+ UIView *icon = SGTabIconView(name, symbols, UIColor.whiteColor);+ // Encore's views lay themselves out from constraints; this one is placed by frame.+ icon.translatesAutoresizingMaskIntoConstraints = YES;+ icon.frame = box.bounds;+ if ([icon isKindOfClass:UIImageView.class]) icon.contentMode = UIViewContentModeScaleAspectFit;+ [box addSubview:icon];+ box.isAccessibilityElement = NO;+ box.accessibilityElementsHidden = YES;+ return box;+}++static UIView *withChevron(UIView *view) {+ UIImageView *chevron = SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);+ CGFloat height = MAX(view.bounds.size.height, chevron.bounds.size.height);+ UIView *box = [[UIView alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width + 8 + chevron.bounds.size.width, height)];+ view.center = CGPointMake(view.bounds.size.width / 2, height / 2);+ chevron.center = CGPointMake(box.bounds.size.width - chevron.bounds.size.width / 2, height / 2);+ [box addSubview:view];+ [box addSubview:chevron];+ return box;+}++static void showProblem(UIViewController *page, NSString *title, NSString *message) {+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];+ [page presentViewController:alert animated:YES completion:nil];+}++#pragma mark - Choose a Link++@interface SGTabLinkPage : SGPage+- (instancetype)initWithDraft:(SGTabDraft *)draft presets:(NSArray<NSDictionary *> *)presets;+@end++@implementation SGTabLinkPage {+ SGTabDraft *_draft;+ NSArray<NSDictionary *> *_presets;+}++- (instancetype)initWithDraft:(SGTabDraft *)draft presets:(NSArray<NSDictionary *> *)presets {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Choose a Link";+ _draft = draft;+ _presets = presets;+ return self;+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return 2;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return section == 0 ? (NSInteger)_presets.count : 1;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ return SGSectionHeader(table, section == 0 ? @"Spotify's pages" : @"Custom link");+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ return SGSectionHeaderHeight;+}++- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {+ return section == 1 ? SGSectionFooter(table, @"Paste a share link or a spotify: URI.") : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return section == 1 ? SGSectionFooterHeight(table, @"Paste a share link or a spotify: URI.") : CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"link");+ if (path.section == 0) {+ NSDictionary *tab = _presets[(NSUInteger)path.row];+ BOOL current = [tab[SGTabURI] isEqualToString:_draft.uri];+ SGFillCell(cell, tab[SGTabTitle], tab[SGTabURI], nil, nil);+ cell.accessoryView = current ? SGSymbolView(@"checkmark", 15, UIImageSymbolWeightSemibold, 24) : previewOf(tab[SGTabIcon], NO, 24);+ } else {+ SGFillCell(cell, @"Enter a custom link…", nil, nil, @"link");+ }+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ return cell;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ if (path.section == 0) {+ NSDictionary *tab = _presets[(NSUInteger)path.row];+ _draft.uri = tab[SGTabURI];+ if (!_draft.title.length) _draft.title = tab[SGTabTitle];+ if (!_draft.iconChosen) {+ _draft.icon = tab[SGTabIcon];+ _draft.symbols = NO;+ }+ [self.navigationController popViewControllerAnimated:YES];+ return;+ }+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Custom Link" message:@"A share link or a spotify: URI." preferredStyle:UIAlertControllerStyleAlert];+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {+ field.placeholder = @"spotify:playlist:…";+ field.text = self->_draft.uri;+ field.keyboardType = UIKeyboardTypeURL;+ field.clearButtonMode = UITextFieldViewModeWhileEditing;+ field.autocapitalizationType = UITextAutocapitalizationTypeNone;+ field.autocorrectionType = UITextAutocorrectionTypeNo;+ }];+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Use Link" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {+ [self useLink:alert.textFields.firstObject.text];+ }]];+ [self presentViewController:alert animated:YES completion:nil];+}++// Said here rather than by Spotify's "Couldn't open link" on the bar later, every time the tab is tapped.+- (void)useLink:(NSString *)text {+ NSURL *url = SGSpotifyURIFromText(text);+ BOOL spotify = [url.scheme.lowercaseString isEqualToString:@"spotify"];+ if (!spotify || routeOf(url, @"custom") == SGLinkRouteNone) {+ NSString *what = text.length ? text : @"nothing";+ showProblem(self, @"Can't Use That Link",+ spotify ? [NSString stringWithFormat:@"Spotify has nowhere to open %@, so it would not work as a tab.", url.absoluteString]+ : [NSString stringWithFormat:@"%@ is not a share link or a spotify: URI.", what]);+ return;+ }+ _draft.uri = url.absoluteString;+ if (!_draft.title.length) _draft.title = _draft.uri;+ [self.navigationController popViewControllerAnimated:YES];+}++@end++#pragma mark - Choose an Icon++@interface SGTabIconPage : SGPage <UISearchResultsUpdating, UISearchControllerDelegate>+- (instancetype)initWithDraft:(SGTabDraft *)draft;+@end++@implementation SGTabIconPage {+ SGTabDraft *_draft;+ UISegmentedControl *_sets;+ UISearchController *_search;+ NSArray<NSString *> *_symbols; // every SF Symbol, once SGLoadSymbolNames has them+ NSArray<NSArray<NSString *> *> *_sections;+ NSArray<NSString *> *_headers;+ NSString *_footer;+ NSUInteger _generation; // a search that finishes after a newer one began is dropped+ BOOL _popAfterSearch;+}++- (instancetype)initWithDraft:(SGTabDraft *)draft {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Choose an Icon";+ _draft = draft;+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ _sets = [[UISegmentedControl alloc] initWithItems:@[@"Spotify Encore", @"SF Symbols"]];+ _sets.selectedSegmentIndex = _draft.symbols ? 1 : 0;+ [_sets addTarget:self action:@selector(setChanged) forControlEvents:UIControlEventValueChanged];+ self.navigationItem.titleView = _sets;++ _search = [[UISearchController alloc] initWithSearchResultsController:nil];+ _search.searchResultsUpdater = self;+ _search.delegate = self;+ _search.obscuresBackgroundDuringPresentation = NO;+ _search.searchBar.placeholder = @"Search icons";+ _search.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;+ _search.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;+ self.navigationItem.searchController = _search;+ self.navigationItem.hidesSearchBarWhenScrolling = NO;+ // On 26 the field waits as a button in a toolbar at the bottom, where the thumb is.+ if (@available(iOS 26.0, *)) {+ self.navigationItem.preferredSearchBarPlacement = UINavigationItemSearchBarPlacementIntegratedButton;+ self.navigationItem.searchBarPlacementAllowsToolbarIntegration = YES;+ self.toolbarItems = @[[UIBarButtonItem flexibleSpaceItem], self.navigationItem.searchBarPlacementBarButtonItem];+ }+ self.definesPresentationContext = YES;++ __weak typeof(self) weakSelf = self;+ SGLoadSymbolNames(^(NSArray<NSString *> *names) {+ typeof(self) page = weakSelf;+ if (!page) return;+ page->_symbols = names;+ if (page->_sets.selectedSegmentIndex == 1 && page->_search.searchBar.text.length) [page filterNow];+ });+ [self filterNow];+}++- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ if (@available(iOS 26.0, *)) [self.navigationController setToolbarHidden:NO animated:animated];+ // Hundreds of rows want the whole height.+ UISheetPresentationController *sheet = self.navigationController.sheetPresentationController;+ [sheet animateChanges:^{+ sheet.selectedDetentIdentifier = UISheetPresentationControllerDetentIdentifierLarge;+ }];+}++- (void)viewWillDisappear:(BOOL)animated {+ [super viewWillDisappear:animated];+ _search.active = NO;+ [self.navigationController setToolbarHidden:YES animated:animated];+}++- (void)didDismissSearchController:(UISearchController *)search {+ if (!_popAfterSearch) return;+ _popAfterSearch = NO;+ [self.navigationController popViewControllerAnimated:YES];+}++- (void)setChanged {+ [self filterNow];+}++- (void)updateSearchResultsForSearchController:(UISearchController *)search {+ NSUInteger generation = ++_generation;+ __weak typeof(self) weakSelf = self;+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ typeof(self) page = weakSelf;+ if (page && page->_generation == generation) [page filterNow];+ });+}++// Encore: the common glyphs, then the rest. SF Symbols: the common ones, or with a search, any symbol+// this iOS draws whose name holds the text.+- (void)filterNow {+ _generation++;+ NSString *text = [_search.searchBar.text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];+ BOOL symbols = _sets.selectedSegmentIndex == 1;+ _footer = nil;+ if (text.length) {+ NSArray<NSString *> *pool = symbols ? (_symbols ?: SGCommonTabSymbols()) : SGEncoreGlyphNames();+ NSPredicate *match = [NSPredicate predicateWithFormat:@"SELF CONTAINS[c] %@", text];+ NSArray<NSString *> *found = [pool filteredArrayUsingPredicate:match];+ _sections = @[found];+ _headers = @[@""];+ if (!found.count) _footer = symbols && !_symbols ? @"Still reading the list of SF Symbols…" : @"No icon has that in its name.";+ } else if (symbols) {+ _sections = @[SGCommonTabSymbols()];+ _headers = @[@"Suggested"];+ _footer = @"Search finds any SF Symbol.";+ } else {+ NSArray<NSString *> *common = SGCommonTabGlyphs();+ NSMutableArray<NSString *> *rest = [SGEncoreGlyphNames() mutableCopy];+ [rest removeObjectsInArray:common];+ _sections = @[common, rest];+ _headers = @[@"Suggested", @"All glyphs"];+ if (!SGEncoreGlyphNames().count) _footer = @"This version of Spotify has no glyphs to offer. SF Symbols still work.";+ }+ [self.tableView reloadData];+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return (NSInteger)_sections.count;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return (NSInteger)_sections[(NSUInteger)section].count;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ NSString *title = _headers[(NSUInteger)section];+ return title.length && _sections[(NSUInteger)section].count ? SGSectionHeader(table, title) : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ NSString *title = _headers[(NSUInteger)section];+ return title.length && _sections[(NSUInteger)section].count ? SGSectionHeaderHeight : SGSectionGap;+}++- (BOOL)isLast:(NSInteger)section {+ return section == (NSInteger)_sections.count - 1;+}++- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {+ return _footer && [self isLast:section] ? SGSectionFooter(table, _footer) : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return _footer && [self isLast:section] ? SGSectionFooterHeight(table, _footer) : CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ UITableViewCell *cell = SGDequeueCell(table, @"icon");+ NSString *name = _sections[(NSUInteger)path.section][(NSUInteger)path.row];+ BOOL symbols = _sets.selectedSegmentIndex == 1;+ BOOL current = symbols == _draft.symbols && [name isEqualToString:_draft.icon];+ SGFillCell(cell, name, current ? @"Current icon" : nil, nil, nil);+ // A preview is one of Spotify's views; setting a new accessory takes the old one off the reused cell.+ cell.accessoryView = previewOf(name, symbols, 28);+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ return cell;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ _draft.icon = _sections[(NSUInteger)path.section][(NSUInteger)path.row];+ _draft.symbols = _sets.selectedSegmentIndex == 1;+ _draft.iconChosen = YES;+ // A search still up is presented over the page and holds it there, so the pop waits for the search+ // to have gone (harness/addtab, `pick`).+ if (!_search.active) {+ [self.navigationController popViewControllerAnimated:YES];+ return;+ }+ _popAfterSearch = YES;+ _search.active = NO;+}++@end++#pragma mark - Add a Tab++typedef NS_ENUM(NSInteger, SGAddTabSection) {+ SGAddTabSectionName,+ SGAddTabSectionCustomize,+ SGAddTabSectionCount,+};++@interface SGAddTabPage : SGPage <UITextFieldDelegate>+- (instancetype)initWithPresets:(NSArray<NSDictionary *> *)presets add:(void (^)(NSDictionary *tab))add;+@end++@implementation SGAddTabPage {+ SGTabDraft *_draft;+ NSArray<NSDictionary *> *_presets;+ void (^_add)(NSDictionary *tab);+ UITextField *_name;+}++- (instancetype)initWithPresets:(NSArray<NSDictionary *> *)presets add:(void (^)(NSDictionary *tab))add {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Add a Tab";+ _draft = [SGTabDraft new];+ _draft.icon = @"star";+ _add = [add copy];+ NSMutableArray<NSDictionary *> *kept = [NSMutableArray array];+ for (NSDictionary *tab in presets) {+ if (routeOf([NSURL URLWithString:tab[SGTabURI]], @"preset") != SGLinkRouteNone) [kept addObject:tab];+ }+ _presets = kept;+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addTab)];+ self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;++ _name = [UITextField new];+ _name.placeholder = @"Name";+ _name.accessibilityLabel = @"Name";+ _name.font = SGTitleFont();+ _name.textColor = UIColor.whiteColor;+ _name.clearButtonMode = UITextFieldViewModeWhileEditing;+ _name.autocorrectionType = UITextAutocorrectionTypeNo;+ _name.returnKeyType = UIReturnKeyDone;+ _name.delegate = self;+ [_name addTarget:self action:@selector(nameChanged) forControlEvents:UIControlEventEditingChanged];+}++// The pages pushed from here change the draft.+- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ if (![_name.text isEqualToString:_draft.title ?: @""]) _name.text = _draft.title;+ self.navigationItem.rightBarButtonItem.enabled = _draft.uri.length > 0;+ [self.tableView reloadData];+}++- (void)nameChanged {+ _draft.title = _name.text;+}++- (BOOL)textFieldShouldReturn:(UITextField *)field {+ [field resignFirstResponder];+ return NO;+}++- (void)cancel {+ [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];+}++- (void)addTab {+ if (!_draft.uri.length) return;+ NSString *title = [_name.text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];+ NSMutableDictionary *tab = [@{SGTabTitle: title.length ? title : _draft.uri, SGTabURI: _draft.uri, SGTabIcon: _draft.icon ?: @"star"} mutableCopy];+ if (_draft.symbols) tab[SGTabIconSet] = SGTabIconSetSymbols;+ SGLog(@"add tab: %@", tab);+ void (^add)(NSDictionary *) = _add;+ [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];+ if (add) add(tab);+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return SGAddTabSectionCount;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return section == SGAddTabSectionName ? 1 : 2;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ return SGSectionHeader(table, section == SGAddTabSectionName ? @"Name" : @"Customize");+}++- (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 {+ if (path.section == SGAddTabSectionName) {+ UITableViewCell *cell = SGDequeueCell(table, @"name");+ SGFillCell(cell, nil, nil, nil, nil);+ if (_name.superview != cell.contentView) {+ _name.translatesAutoresizingMaskIntoConstraints = NO;+ [cell.contentView addSubview:_name];+ [NSLayoutConstraint activateConstraints:@[+ [_name.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:16],+ [_name.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-16],+ [_name.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor],+ [_name.bottomAnchor constraintEqualToAnchor:cell.contentView.bottomAnchor],+ [_name.heightAnchor constraintGreaterThanOrEqualToConstant:44],+ ]];+ }+ return cell;+ }+ UITableViewCell *cell = SGDequeueCell(table, @"customize");+ if (path.row == 0) {+ SGFillCell(cell, @"Link", _draft.uri ?: @"Choose a page or paste a link", nil, @"link");+ cell.accessoryView = SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);+ } else {+ SGFillCell(cell, @"Icon", iconSummary(_draft), nil, @"square.grid.2x2");+ cell.accessoryView = withChevron(previewOf(_draft.icon, _draft.symbols, 24));+ }+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ return cell;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ if (path.section != SGAddTabSectionCustomize) {+ [_name becomeFirstResponder];+ return;+ }+ [_name resignFirstResponder];+ UIViewController *page = path.row == 0 ? [[SGTabLinkPage alloc] initWithDraft:_draft presets:_presets]+ : [[SGTabIconPage alloc] initWithDraft:_draft];+ [self.navigationController pushViewController:page animated:YES];+}++@end++void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, void (^add)(NSDictionary *tab)) {+ SGAddTabPage *page = [[SGAddTabPage alloc] initWithPresets:presets add:add];+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:page];+ // Outside Spotify's own stacks the sheet would take the system's appearance, light in light mode.+ nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ UISheetPresentationController *sheet = nav.sheetPresentationController;+ // Tall enough for the name and the two rows under the navigation bar; the keyboard lifts it.+ UISheetPresentationControllerDetent *compact = [UISheetPresentationControllerDetent customDetentWithIdentifier:kCompactDetent resolver:^CGFloat(id<UISheetPresentationControllerDetentResolutionContext> context) {+ return MIN(320, context.maximumDetentValue);+ }];+ sheet.detents = @[compact, UISheetPresentationControllerDetent.largeDetent];+ sheet.selectedDetentIdentifier = kCompactDetent;+ sheet.prefersGrabberVisible = YES;+ sheet.prefersScrollingExpandsWhenScrolledToEdge = YES;+ [owner presentViewController:nav animated:YES completion:nil];+}diff --git a/tweak/Sources/Shared/Navigation/TabIcons.h b/tweak/Sources/Shared/Navigation/TabIcons.hnew file mode 100644index 00000000..283ab69f--- /dev/null+++ b/tweak/Sources/Shared/Navigation/TabIcons.h@@ -0,0 +1,21 @@+// The icons a tab of the mod's own can wear, on either look's bar: one of Spotify's Encore glyphs or an+// SF Symbol. Each look keeps which of the two an entry's icon name belongs to under its own key; an entry+// saved before there was a choice has none and means Encore.+#import <UIKit/UIKit.h>++// The value either look stores for a tab whose icon is an SF Symbol.+extern NSString *const SGTabIconSetSymbols;++// The icon drawn the way the bar draws Spotify's own: an Encore glyph by its SPTEncoreIcon class method,+// or an SF Symbol at Encore's visual size (19 pt semibold) in `color`. A symbol name that does not+// resolve tries Encore, and a glyph name Encore does not have ends in star.fill.+UIView *SGTabIconView(NSString *name, BOOL symbol, UIColor *color);++// Every glyph SPTEncoreIcon has, sorted case-insensitively, asked of the class once; empty if it is gone.+NSArray<NSString *> *SGEncoreGlyphNames(void);+// A few glyphs and symbols a tab is likely to want, in that order, kept to the ones that draw here.+NSArray<NSString *> *SGCommonTabGlyphs(void);+NSArray<NSString *> *SGCommonTabSymbols(void);+// Every SF Symbol this iOS draws, read once in the background, handed back on the main queue. Without+// the system's list of names it is the common ones only.+void SGLoadSymbolNames(void (^done)(NSArray<NSString *> *names));diff --git a/tweak/Sources/Shared/Navigation/TabIcons.m b/tweak/Sources/Shared/Navigation/TabIcons.mnew file mode 100644index 00000000..b92ae404--- /dev/null+++ b/tweak/Sources/Shared/Navigation/TabIcons.m@@ -0,0 +1,156 @@+#import "Core/SGCore.h"+#import "TabIcons.h"+#import "Headers/SPTEncoreIconView.h"+#import <objc/message.h>+#import <objc/runtime.h>++NSString *const SGTabIconSetSymbols = @"symbols";++static UIImage *symbolImage(NSString *name) {+ if (!name.length) return nil;+ return [UIImage systemImageNamed:name withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:19 weight:UIImageSymbolWeightSemibold]];+}++// SPTEncoreIcon exposes one class method per glyph ("podcasts", "heart"), 538 of them in 9.1.78.+static UIView *encoreView(NSString *name, UIColor *color) {+ Class icon = NSClassFromString(@"SPTEncoreIcon");+ Class view = NSClassFromString(@"SPTEncoreIconView");+ SEL glyphSel = NSSelectorFromString(name.length ? name : @"star");+ if (!icon || !view || ![icon respondsToSelector:glyphSel]) return nil;+ id glyph = ((id (*)(id, SEL))objc_msgSend)(icon, glyphSel);+ SPTEncoreIconView *encore = glyph ? [[view alloc] initWithIcon:glyph] : nil;+ [encore setForegroundColor:color];+ return encore;+}++static UIView *symbolView(UIImage *image, UIColor *color) {+ UIImageView *view = [[UIImageView alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];+ view.tintColor = color;+ view.contentMode = UIViewContentModeCenter;+ return view;+}++UIView *SGTabIconView(NSString *name, BOOL symbol, UIColor *color) {+ UIImage *image = symbol ? symbolImage(name) : nil;+ if (image) return symbolView(image, color);+ return encoreView(name, color) ?: symbolView(symbolImage(@"star.fill"), color);+}++#pragma mark - the catalogues++// Methods every class answers, which are not glyphs and some of which must not be called bare.+static BOOL notAGlyph(NSString *name) {+ static NSSet *names;+ if (!names) names = [NSSet setWithArray:@[@"alloc", @"new", @"class", @"superclass", @"copy", @"mutableCopy", @"description",+ @"debugDescription", @"initialize", @"load", @"hash", @"self", @"dealloc", @"init"]];+ return [name hasPrefix:@"_"] || [name hasPrefix:@"."] || [names containsObject:name];+}++// The class methods on SPTEncoreIcon's metaclass that take nothing and return an object, each called+// once and kept when what it returns has a name.+NSArray<NSString *> *SGEncoreGlyphNames(void) {+ static NSArray<NSString *> *glyphs;+ if (glyphs) return glyphs;+ Class icon = NSClassFromString(@"SPTEncoreIcon");+ NSMutableArray<NSString *> *found = [NSMutableArray array];+ unsigned int count = 0;+ Method *methods = icon ? class_copyMethodList(object_getClass(icon), &count) : NULL;+ for (unsigned int i = 0; i < count; i++) {+ NSString *name = NSStringFromSelector(method_getName(methods[i]));+ // Two arguments are self and _cmd: a selector with no colon of its own.+ if (method_getNumberOfArguments(methods[i]) != 2 || [name containsString:@":"] || notAGlyph(name)) continue;+ const char *types = method_getTypeEncoding(methods[i]);+ if (!types || types[0] != '@') continue;+ @try {+ id glyph = ((id (*)(id, SEL))objc_msgSend)(icon, method_getName(methods[i]));+ if ([glyph respondsToSelector:@selector(name)] && [[glyph name] isKindOfClass:NSString.class] && [glyph name].length) [found addObject:name];+ } @catch (NSException *e) {+ SGLog(@"tab icons: +[SPTEncoreIcon %@] threw %@", name, e.reason);+ }+ }+ free(methods);+ glyphs = [found sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];+ SGLog(@"tab icons: %lu Encore glyphs", (unsigned long)glyphs.count);+ return glyphs;+}++NSArray<NSString *> *SGCommonTabGlyphs(void) {+ NSArray<NSString *> *all = SGEncoreGlyphNames();+ NSMutableArray<NSString *> *kept = [NSMutableArray array];+ for (NSString *name in @[@"home", @"search", @"collection", @"heart", @"playlist", @"album", @"artist", @"podcasts",+ @"audiobook", @"downloaded", @"bookmark", @"browse", @"star", @"user", @"events", @"queue",+ @"radio", @"plus"]) {+ if ([all containsObject:name]) [kept addObject:name];+ }+ return kept;+}++NSArray<NSString *> *SGCommonTabSymbols(void) {+ NSMutableArray<NSString *> *kept = [NSMutableArray array];+ for (NSString *name in @[@"house.fill", @"magnifyingglass", @"books.vertical.fill", @"heart.fill", @"music.note.list",+ @"square.stack.fill", @"music.mic", @"mic.fill", @"globe", @"radio.fill", @"headphones",+ @"star.fill", @"clock.fill", @"arrow.down.circle.fill", @"bookmark.fill", @"person.crop.circle.fill",+ @"sparkles", @"flame.fill", @"chart.bar.fill", @"waveform", @"calendar", @"ticket.fill",+ @"list.bullet", @"plus"]) {+ if (symbolImage(name)) [kept addObject:name];+ }+ return kept;+}++// The same symbol drawn for a script (heart.text.square.ar, .hi, .ja…), which a search would list+// once per language.+static BOOL scriptVariant(NSString *name) {+ static NSSet *scripts;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ scripts = [NSSet setWithArray:@[@"ar", @"hi", @"he", @"ja", @"th", @"zh", @"bn", @"gu", @"kn", @"ko", @"ml",+ @"mr", @"or", @"pa", @"te", @"si", @"ta", @"el", @"ru", @"km", @"my"]];+ });+ NSRange dot = [name rangeOfString:@"." options:NSBackwardsSearch];+ return dot.location != NSNotFound && [scripts containsObject:[name substringFromIndex:dot.location + 1]];+}++// UIKit lists no symbol names. The system's own catalogue does, in CoreGlyphs (a link in CoreServices to+// SFSymbols.framework's bundle on iOS 26 and 27, checked against the iOS 27 simulator runtime): its+// symbol_order.plist names each symbol once, in the SF Symbols app's order.+static NSArray<NSString *> *systemSymbolNames(void) {+ NSBundle *glyphs = [NSBundle bundleWithPath:@"/System/Library/CoreServices/CoreGlyphs.bundle"];+ NSString *path = [glyphs pathForResource:@"symbol_order" ofType:@"plist"];+ NSArray *names = path ? [NSArray arrayWithContentsOfFile:path] : nil;+ if (names.count) return names;+ path = [glyphs pathForResource:@"name_availability" ofType:@"plist"];+ NSDictionary *symbols = path ? [NSDictionary dictionaryWithContentsOfFile:path][@"symbols"] : nil;+ return [symbols isKindOfClass:NSDictionary.class] ? symbols.allKeys : nil;+}++void SGLoadSymbolNames(void (^done)(NSArray<NSString *> *names)) {+ static NSArray<NSString *> *loaded;+ static NSMutableArray *waiting;+ if (loaded) {+ done(loaded);+ return;+ }+ BOOL first = !waiting;+ if (first) waiting = [NSMutableArray array];+ [waiting addObject:[done copy]];+ if (!first) return;+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{+ NSArray *names = systemSymbolNames();+ // Each name is asked of UIKit, 8,500 of them on iOS 27, so the asking is spread over the cores.+ NSUInteger count = names.count;+ BOOL *draws = calloc(count ?: 1, sizeof(BOOL));+ dispatch_apply(count, DISPATCH_APPLY_AUTO, ^(size_t i) {+ id name = names[i];+ draws[i] = [name isKindOfClass:NSString.class] && !scriptVariant(name) && symbolImage(name);+ });+ NSMutableArray<NSString *> *kept = [NSMutableArray array];+ for (NSUInteger i = 0; i < count; i++) if (draws[i]) [kept addObject:names[i]];+ free(draws);+ dispatch_async(dispatch_get_main_queue(), ^{+ loaded = kept.count ? [kept copy] : SGCommonTabSymbols();+ SGLog(@"tab icons: %lu SF Symbols of %lu listed", (unsigned long)kept.count, (unsigned long)names.count);+ for (void (^callback)(NSArray *) in waiting) callback(loaded);+ waiting = nil;+ });+ });+}