Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: Accent color offers a preset menu and a saved custom color
My-Name-Is-Jeffd36d7c63e37d
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 53054faa..2d4a18ac 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -369,9 +369,15 @@ 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: Redesigned UI, then the stored look's accent colour, and in the native-look AMOLED (the redesign is always black); Spotify's green is offered from the colour row once a colour-is set. Last comes the Font, under either look and on any iOS, below 26 too. Redesigned UI is the one switch between the two looks (see Layers): it glows+they change. It opens on the Appearance row, on a card of its own under the signing warning, which opens the Appearance+page: Redesigned UI, then in the native look AMOLED (the redesign is always black), then the stored look's Accent colour+preset, a pull-down of Spotify, Apple Music and Custom read off the colour stored (a colour set before the presets+existed reads as Custom, Apple Music's red as Apple Music), and Accent colour, the hex and a swatch of the colour in+effect, which opens the system picker in a sheet that stores only from its checkmark, as Custom. The custom colour is+kept aside while a preset is in place, so Custom brings it back. Last come the Font, under either look and on any+iOS, below 26 too, with Custom font among its choices (a .ttf or .otf imported from Files by the row under it,+copied to Application Support/Vitrine/Font and registered again at each launch, Spotify's font coming back when the+file is gone), and the App icon. Everything on the page applies after a restart. Redesigned UI is the one switch between the two looks (see Layers): it glows(Settings/SGGlowSwitch), its ⓘ says what it changes, and flipping it offers to restart Spotify.The pages show only what the stored look has: a page opened after flipping the switch already showswhat the restart will bring. Then a card of parts. Navbar: the tab editor of the stored look, each withdiff --git a/harness/appearance-page/README.md b/harness/appearance-page/README.mdnew file mode 100644index 00000000..1a0fd87d--- /dev/null+++ b/harness/appearance-page/README.md@@ -0,0 +1,25 @@+# Appearance page harness++Mod Settings > Appearance as `App/Pages.m` builds it: either look's accent rows (`Native/Appearance/AppearanceSettings.m`,+`Redesigned/Kit/SGRAppearanceSettings.m`), the Font rows and their import (`Shared/Fonts/FontImport.m`) and the real+Settings/ framework (the pull-down menu row, the swatch, the colour sheet), with `stubs.m` reading the accent and+font keys the way the Logos files do.++ ./build.sh+ xcrun simctl install <udid> build/AppearancePageHarness.app+ xcrun simctl launch --console <udid> com.vojta.appearancepageharness accent=123456 menu=1.1:0 dump menu=1.1:2 dump+ xcrun simctl io <udid> screenshot shot.png++Make a simulator of your own (`xcrun simctl create`) and address it by UDID. `main.m` lists the setup words+(`redesign`, `accent=`, `raccent=`, `font=`, `keep`) and the actions: a menu item picked, a row tapped, the+colour sheet moved, confirmed or closed, a font file handed to the import as Files would, and `dump`, which logs the+stored keys, the colour in effect, what the launch would register for the font and what every row reads.++2026-10-05, iPhone 17 Pro on iOS 27.0: an old Apple Music red reads Apple Music, an old #123456 reads Custom, nothing+stored reads Spotify (native) or Custom #37F200 (redesign); Custom → Spotify → Custom brings #123456 back; the sheet's+close keeps the colour, its checkmark stores it as Custom; a text file named .ttf is refused with nothing stored;+Chalkduster.ttf (a face iOS already has) and then a Noto .otf import, the second replacing the first, and a deleted+file registers nothing.++What it does not cover: a finger on the pull-down (UIKit opens it only from a touch), the document picker itself,+and Fonts.x's hooks, which only Spotify can show.diff --git a/harness/appearance-page/build.sh b/harness/appearance-page/build.shnew file mode 100755index 00000000..9d51a3c1--- /dev/null+++ b/harness/appearance-page/build.sh@@ -0,0 +1,41 @@+#!/bin/sh+# Builds the Appearance page harness for the simulator: either look's appearance rows, the font rows and their+# import, the Settings/ framework as they are in the tweak, stubs.m for what the hooks hold.+set -e+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)+OUT=$(dirname "$0")/build+rm -rf "$OUT"; mkdir -p "$OUT/AppearancePageHarness.app"++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \+ -I"$SRC" -isysroot "$SDK" -Wall -Werror -Wno-deprecated-declarations \+ "$(dirname "$0")/main.m" "$(dirname "$0")/../scene.m" "$(dirname "$0")/stubs.m" \+ "$SRC"/Native/Appearance/AppearanceSettings.m "$SRC"/Redesigned/Kit/SGRAppearanceSettings.m "$SRC"/Shared/Fonts/FontImport.m \+ "$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m "$SRC"/Settings/SGModPage.m "$SRC"/Settings/SGGlowSwitch.m \+ "$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation -framework CoreText -framework UniformTypeIdentifiers \+ -o "$OUT/AppearancePageHarness.app/AppearancePageHarness"++cat > "$OUT/AppearancePageHarness.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>AppearancePageHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.appearancepageharness</string>+<key>CFBundleName</key><string>AppearancePageHarness</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>SGRHarnessScene</string>+ </dict></array>+ </dict>+</dict>+</dict></plist>+PLIST+echo "built $OUT/AppearancePageHarness.app"diff --git a/harness/appearance-page/main.m b/harness/appearance-page/main.mnew file mode 100644index 00000000..96171d17--- /dev/null+++ b/harness/appearance-page/main.m@@ -0,0 +1,164 @@+// Mod Settings > Appearance as App/Pages.m builds it, with the real rows of either look's accent+// (Native/Appearance/AppearanceSettings.m, Redesigned/Kit/SGRAppearanceSettings.m), the font rows and their import+// (Shared/Fonts/FontImport.m) and the Settings/ framework, stubs.m for the hooks. The launch line sets the keys up+// and then plays actions, one every 0.9 s from 1 s in; screenshot after.+//+// ./build.sh && xcrun simctl install <udid> build/AppearancePageHarness.app+// xcrun simctl launch --console-pty <udid> com.vojta.appearancepageharness [setup...] [action...]+//+// Setup: keep (the stored settings stay; otherwise every spotifyglass.accent / .redesign.accent / .font key is+// cleared first), redesign (the redesign's rows), accent=<hex|-1>, raccent=<hex|-1>, font=<n>.+// Actions: open=<section>.<row> (the row's menu opened as a tap does), menu=<section>.<row>:<n> (its nth item+// picked), select=<section>.<row> (a tap on the row), color=<hex> (the open picker moved there), confirm (its+// checkmark), close (the sheet dismissed without it), import=<path> (that file handed to the font import as+// Files would), dismiss (whatever is presented goes), dump (the stored keys and every row with what it reads).+#import <UIKit/UIKit.h>+#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Native/Appearance/Appearance.h"+#import "Redesigned/Kit/SGRAccent.h"+#import "Shared/Fonts/Fonts.h"++static void findViews(UIView *root, Class kind, NSMutableArray *found) {+ if ([root isKindOfClass:kind]) [found addObject:root];+ for (UIView *sub in root.subviews) findViews(sub, kind, found);+}++static NSInteger hex(NSString *text) {+ return [text isEqualToString:@"-1"] ? -1 : (NSInteger)strtol(text.UTF8String, NULL, 16);+}++@interface AppDelegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@property (nonatomic, strong) UINavigationController *nav;+@end++@implementation AppDelegate++// SGAppearancePage's sections, the Redesigned UI switch standing in for either first row.+- (UIViewController *)appearancePage {+ SGModRow *look = SGOptionRow(@"Redesigned UI", nil, SGKeyRedesign);+ look.glows = YES;+ return [[SGModPage alloc] initWithTitle:@"Appearance" intro:SGRestartNote sections:@[+ SGSection(nil, @[SGWithSymbol(look, @"sparkles")]),+ SGSection(nil, SGFlag(SGKeyRedesign, NO) ? SGRAppearanceRows() : SGNativeAppearanceRows()),+ SGSection(nil, SGAppFontRows()),+ ] footer:nil];+}++- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;+ if (![args containsObject:@"keep"]) {+ for (NSString *key in store.dictionaryRepresentation.allKeys) {+ if ([key hasPrefix:@"spotifyglass.accent"] || [key hasPrefix:@"spotifyglass.redesign.accent"] || [key hasPrefix:@"spotifyglass.font"] ||+ [key isEqualToString:SGKeyRedesign]) [store removeObjectForKey:key];+ }+ }+ NSMutableArray<NSString *> *actions = [NSMutableArray array];+ for (NSString *arg in [args subarrayWithRange:NSMakeRange(1, args.count - 1)]) {+ if ([arg isEqualToString:@"redesign"]) SGSetEnabled(SGKeyRedesign, YES);+ else if ([arg hasPrefix:@"accent="]) SGSetInt(SGKeyAccent, hex([arg substringFromIndex:7]));+ else if ([arg hasPrefix:@"raccent="]) SGSetInt(SGRKeyAccent, hex([arg substringFromIndex:8]));+ else if ([arg hasPrefix:@"font="]) SGSetInt(SGKeyAppFont, [arg substringFromIndex:5].integerValue);+ else if (![arg isEqualToString:@"keep"]) [actions addObject:arg];+ }++ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.nav = [[UINavigationController alloc] initWithRootViewController:[self appearancePage]];+ self.window.rootViewController = self.nav;+ [self.window makeKeyAndVisible];++ [actions enumerateObjectsUsingBlock:^(NSString *action, NSUInteger i, BOOL *stop) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((1 + 0.9 * i) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ NSLog(@"[harness] %@", action);+ [self run:action];+ });+ }];+ return YES;+}++- (UITableView *)table {+ return ((UITableViewController *)self.nav.topViewController).tableView;+}++- (NSIndexPath *)pathFrom:(NSString *)text {+ NSArray<NSString *> *at = [text componentsSeparatedByString:@"."];+ return [NSIndexPath indexPathForRow:at[1].integerValue inSection:at[0].integerValue];+}++- (UIButton *)buttonAt:(NSString *)text {+ NSMutableArray<UIButton *> *buttons = [NSMutableArray array];+ findViews([self.table cellForRowAtIndexPath:[self pathFrom:text]], UIButton.class, buttons);+ return buttons.firstObject;+}++- (UIColorPickerViewController *)picker {+ UINavigationController *sheet = (UINavigationController *)self.nav.presentedViewController;+ return [sheet isKindOfClass:UINavigationController.class] ? (UIColorPickerViewController *)sheet.viewControllers.firstObject : nil;+}++- (void)run:(NSString *)action {+ NSArray<NSString *> *parts = [action componentsSeparatedByString:@"="];+ NSString *verb = parts.firstObject, *value = parts.count > 1 ? parts[1] : @"";+ UITableView *table = self.table;+ if ([verb isEqualToString:@"open"]) {+ UIButton *button = [self buttonAt:value];+ if (@available(iOS 17.4, *)) [button performPrimaryAction];+ } else if ([verb isEqualToString:@"menu"]) {+ NSArray<NSString *> *at = [value componentsSeparatedByString:@":"];+ UIButton *button = [self buttonAt:at[0]];+ UIAction *item = (UIAction *)button.menu.children[(NSUInteger)at[1].integerValue];+ NSLog(@"[harness] menu offers %@, picking %@", [[button.menu.children valueForKey:@"title"] componentsJoinedByString:@" / "], item.title);+ [item performWithSender:button target:nil];+ } else if ([verb isEqualToString:@"select"]) {+ [table.delegate tableView:table didSelectRowAtIndexPath:[self pathFrom:value]];+ } else if ([verb isEqualToString:@"color"]) {+ self.picker.selectedColor = SGColorRGB(hex(value));+ } else if ([verb isEqualToString:@"confirm"]) {+ UIBarButtonItem *done = self.picker.navigationItem.rightBarButtonItem;+ NSLog(@"[harness] the sheet's bar: left %@, right %@", self.picker.navigationItem.leftBarButtonItems, done);+ [UIApplication.sharedApplication sendAction:done.action to:done.target from:done forEvent:nil];+ } else if ([verb isEqualToString:@"close"]) {+ UIBarButtonItem *close = self.picker.navigationItem.leftBarButtonItem;+ [UIApplication.sharedApplication sendAction:close.action to:close.target from:close forEvent:nil];+ } else if ([verb isEqualToString:@"dismiss"]) {+ [self.nav dismissViewControllerAnimated:YES completion:nil];+ } else if ([verb isEqualToString:@"import"]) {+ id picker = [NSClassFromString(@"SGFontPicker") new];+ [picker documentPicker:[[UIDocumentPickerViewController alloc] initForOpeningContentTypes:@[UTTypeFont] asCopy:YES] didPickDocumentsAtURLs:@[[NSURL fileURLWithPath:value]]];+ } else if ([verb isEqualToString:@"dump"]) {+ NSDictionary *all = NSUserDefaults.standardUserDefaults.dictionaryRepresentation;+ for (NSString *key in [all.allKeys sortedArrayUsingSelector:@selector(compare:)]) {+ if ([key hasPrefix:@"spotifyglass.accent"] || [key hasPrefix:@"spotifyglass.redesign.accent"] || [key hasPrefix:@"spotifyglass.font"])+ NSLog(@"[harness] stored %@ = %@", key, [all[key] isKindOfClass:NSNumber.class] && [all[key] integerValue] >= 0 ? [NSString stringWithFormat:@"%06lX", (long)[all[key] integerValue]] : all[key]);+ }+ NSLog(@"[harness] in effect: native #%06lX, redesign #%06lX", (long)SGAccentRGB(), (long)SGRAccentRGB());+ // What Fonts.x's launch would get: the file registered again, and a font made from its name.+ NSString *name = SGRegisterCustomFont();+ NSLog(@"[harness] the launch registers %@, which makes %@", name, name ? [UIFont fontWithName:name size:13] : nil);+ for (NSInteger section = 0; section < table.numberOfSections; section++) {+ NSMutableArray<NSString *> *rows = [NSMutableArray array];+ for (NSInteger row = 0; row < [table numberOfRowsInSection:section]; row++) {+ UITableViewCell *cell = [table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];+ NSMutableArray<UILabel *> *labels = [NSMutableArray array];+ findViews(cell.accessoryView, UILabel.class, labels);+ UIButton *button = [self buttonAt:[NSString stringWithFormat:@"%ld.%ld", (long)section, (long)row]];+ NSString *reads = button ? [NSString stringWithFormat:@"menu \"%@\" (VoiceOver: %@, %@)", button.configuration.attributedTitle.string, button.accessibilityLabel, button.accessibilityValue]+ : labels.firstObject.text;+ [rows addObject:[NSString stringWithFormat:@"%@ [%@]", [(UIListContentConfiguration *)cell.contentConfiguration text], reads ?: @""]];+ }+ NSLog(@"[harness] section %ld: %@", (long)section, [rows componentsJoinedByString:@", "]);+ }+ }+}++@end++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class));+ }+}diff --git a/harness/appearance-page/stubs.m b/harness/appearance-page/stubs.mnew file mode 100644index 00000000..d05475f4--- /dev/null+++ b/harness/appearance-page/stubs.m@@ -0,0 +1,24 @@+// What the Logos files hold for the page: the accent colours as Accent.x and SGRAccent.x read them, and the+// font choice as Fonts.x reads it.+#import "Core/SGCore.h"+#import "Native/Appearance/Appearance.h"+#import "Redesigned/Kit/SGRAccent.h"+#import "Shared/Fonts/Fonts.h"++static NSInteger valid(NSInteger rgb) {+ return rgb >= 0 && rgb <= 0xFFFFFF ? rgb : -1;+}++UIColor *SGAccentColor(void) { return valid(SGInt(SGKeyAccent, -1)) < 0 ? nil : UIColor.redColor; }+NSInteger SGAccentRGB(void) { NSInteger rgb = valid(SGInt(SGKeyAccent, -1)); return rgb < 0 ? SGSpotifyGreen : rgb; }+UIColor *SGRAccentColor(void) { return valid(SGInt(SGRKeyAccent, SGRDefaultAccent)) < 0 ? nil : UIColor.redColor; }+NSInteger SGRAccentRGB(void) { NSInteger rgb = valid(SGInt(SGRKeyAccent, SGRDefaultAccent)); return rgb < 0 ? SGSpotifyGreen : rgb; }++SGAppFont SGAppFontChosen(void) {+ NSInteger font = SGInt(SGKeyAppFont, SGAppFontSpotify);+ return font >= SGAppFontSpotify && font <= SGAppFontCustom ? font : SGAppFontSpotify;+}++NSArray<NSString *> *SGAppFontNames(void) {+ return @[@"Spotify", @"System", @"Rounded", @"Serif", @"Mono", @"Custom font"];+}diff --git a/tweak/Sources/Core/SGPrefs.h b/tweak/Sources/Core/SGPrefs.hindex 4ec218e8..f139ec69 100644--- a/tweak/Sources/Core/SGPrefs.h+++ b/tweak/Sources/Core/SGPrefs.h@@ -34,3 +34,5 @@ void SGRestartSpotify(void);// Apple Music's red, 0xRRGGBB, offered under either look's accent colour.#define SGAppleMusicRed 0xFA2D48+// Spotify's own green, the token either look's accent replaces.+#define SGSpotifyGreen 0x1ED760diff --git a/tweak/Sources/Native/Appearance/Accent.x b/tweak/Sources/Native/Appearance/Accent.xindex 93a29236..9efc76dc 100644--- a/tweak/Sources/Native/Appearance/Accent.x+++ b/tweak/Sources/Native/Appearance/Accent.x@@ -6,7 +6,6 @@// out of reach.#import "Core/SGCore.h"#import "Appearance.h"-#import "Settings/SGPageStyle.h"// The greens the app is known to build from literals: the token, and the older brand green the// upsell backend still names.@@ -33,38 +32,9 @@ UIColor *SGAccentColor(void) {return [UIColor colorWithRed:r green:g blue:b alpha:1];}-NSString *SGAccentLabel(void) {+NSInteger SGAccentRGB(void) {NSInteger rgb = chosen();- if (rgb == SGAppleMusicRed) return @"Apple Music red";- return rgb < 0 ? @"Spotify green" : [NSString stringWithFormat:@"#%06lX", (long)rgb];-}--#pragma mark - picker--@interface SGAccentPicker : NSObject <UIColorPickerViewControllerDelegate>-@end--@implementation SGAccentPicker--- (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)picker {- CGFloat r = 0, g = 0, b = 0, a = 0;- [picker.selectedColor getRed:&r green:&g blue:&b alpha:&a];- uint32_t rgb = ((uint32_t)lround(MIN(1, MAX(0, r)) * 255) << 16)- | ((uint32_t)lround(MIN(1, MAX(0, g)) * 255) << 8)- | (uint32_t)lround(MIN(1, MAX(0, b)) * 255);- SGSetInt(SGKeyAccent, rgb);-}--@end--void SGPickAccent(void) {- static SGAccentPicker *delegate;- if (!delegate) delegate = [SGAccentPicker new];- UIColorPickerViewController *picker = [UIColorPickerViewController new];- picker.supportsAlpha = NO;- picker.selectedColor = SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];- picker.delegate = delegate;- [SGTopController() presentViewController:picker animated:YES completion:nil];+ return rgb < 0 ? SGSpotifyGreen : rgb;}// A darker green than the token comes out as the accent darkened by the same amount, so the twodiff --git a/tweak/Sources/Native/Appearance/Appearance.h b/tweak/Sources/Native/Appearance/Appearance.hindex 0ba3fdf0..5b170d99 100644--- a/tweak/Sources/Native/Appearance/Appearance.h+++ b/tweak/Sources/Native/Appearance/Appearance.h@@ -5,10 +5,11 @@#define SGKeyAmoled @"spotifyglass.amoled"#define SGKeyAccent @"spotifyglass.accent" // 0xRRGGBB; unset or negative keeps Spotify's own green+// The last colour picked, kept while a preset is in place so Custom brings it back.+#define SGKeyAccentCustom @"spotifyglass.accent.custom"UIColor *SGAccentColor(void); // nil while Spotify's own green is kept-NSString *SGAccentLabel(void); // "#RRGGBB", or the name of Spotify's own-void SGPickAccent(void); // the system colour picker over the top of the app, stored on the way out+NSInteger SGAccentRGB(void); // the colour in effect, 0xRRGGBB, Spotify's green included@class SGModRow;-NSArray<SGModRow *> *SGNativeAppearanceRows(void); // AMOLED and the accent colour, for the Appearance card+NSArray<SGModRow *> *SGNativeAppearanceRows(void); // AMOLED and the accent colour, for the Appearance pagediff --git a/tweak/Sources/Native/Appearance/AppearanceSettings.m b/tweak/Sources/Native/Appearance/AppearanceSettings.mindex 6d1c2aa0..6276fa10 100644--- a/tweak/Sources/Native/Appearance/AppearanceSettings.m+++ b/tweak/Sources/Native/Appearance/AppearanceSettings.m@@ -3,26 +3,41 @@#import "Settings/SGPageStyle.h"#import "Appearance.h"-// Apple Music's red is one tap away, unless it is the colour already. 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.-static void chooseAccent(void) {- UIViewController *top = SGTopController();- UIAlertController *sheet = [UIAlertController alertControllerWithTitle:@"Accent colour" message:nil preferredStyle:UIAlertControllerStyleActionSheet];- if (SGInt(SGKeyAccent, -1) != SGAppleMusicRed)- [sheet addAction:[UIAlertAction actionWithTitle:@"Apple Music red" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGSetInt(SGKeyAccent, SGAppleMusicRed); }]];- [sheet addAction:[UIAlertAction actionWithTitle:@"Pick a colour" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGPickAccent(); }]];- if (SGAccentColor()) [sheet addAction:[UIAlertAction actionWithTitle:@"Spotify green" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGSetInt(SGKeyAccent, -1); }]];- [sheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- sheet.popoverPresentationController.sourceView = top.view;- sheet.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(top.view.bounds), CGRectGetMidY(top.view.bounds), 0, 0);- sheet.popoverPresentationController.permittedArrowDirections = 0;- [top presentViewController:sheet animated:YES completion:nil];+// The preset is read off the colour stored, so the hooks keep the one key they read and a colour set before+// presets existed stays in effect: Apple Music's red reads as Apple Music, any other colour as Custom, none+// as Spotify. The custom colour is put aside while a preset is in place, so Custom brings it back.+static NSArray<NSString *> *presets(void) {+ return @[@"Spotify", @"Apple Music", @"Custom"];}-// The native look's rows of the Appearance card (App/Pages.m).+static NSInteger preset(void) {+ NSInteger rgb = SGInt(SGKeyAccent, -1);+ if (rgb < 0 || rgb > 0xFFFFFF) return 0;+ return rgb == SGAppleMusicRed ? 1 : 2;+}++static void choosePreset(NSInteger index) {+ if (preset() == 2) SGSetInt(SGKeyAccentCustom, SGInt(SGKeyAccent, -1));+ NSInteger custom = SGInt(SGKeyAccentCustom, SGSpotifyGreen);+ if (custom < 0 || custom > 0xFFFFFF) custom = SGSpotifyGreen;+ SGSetInt(SGKeyAccent, index == 0 ? -1 : index == 1 ? SGAppleMusicRed : custom);+}++// The native look's rows of the Appearance page (App/Pages.m): the preset from a menu, then the colour in+// effect, which opens the picker; a colour stored from there is Custom.NSArray<SGModRow *> *SGNativeAppearanceRows(void) {+ SGModRow *menu = SGMenuRow(@"Accent colour preset", presets(), ^NSString *{ return presets()[(NSUInteger)preset()]; },+ ^(NSInteger index) { choosePreset(index); });+ SGModRow *colour = SGStatActionRow(@"Accent colour", nil, ^NSString *{ return [NSString stringWithFormat:@"#%06lX", (long)SGAccentRGB()]; }, ^{+ SGPickColor(@"Accent colour", SGAccentRGB(), ^(NSInteger rgb) {+ SGSetInt(SGKeyAccent, rgb);+ SGSetInt(SGKeyAccentCustom, rgb);+ });+ });+ colour.swatch = ^UIColor *{ return SGColorRGB(SGAccentRGB()); };return @[SGWithSymbol(SGOptionRow(@"AMOLED background", nil, SGKeyAmoled), @"moon"),- SGWithSymbol(SGStatActionRow(@"Accent colour", nil, ^NSString *{ return SGAccentLabel(); }, ^{ chooseAccent(); }), @"paintpalette"),+ SGWithSymbol(menu, @"paintpalette"),+ SGWithSymbol(colour, @"eyedropper"),];}diff --git a/tweak/Sources/Redesigned/Kit/SGRAccent.h b/tweak/Sources/Redesigned/Kit/SGRAccent.hindex 16a9a102..42b058ee 100644--- a/tweak/Sources/Redesigned/Kit/SGRAccent.h+++ b/tweak/Sources/Redesigned/Kit/SGRAccent.h@@ -3,10 +3,13 @@#import <UIKit/UIKit.h>#define SGRKeyAccent @"spotifyglass.redesign.accent" // 0xRRGGBB+// The last colour picked, kept while a preset is in place so Custom brings it back.+#define SGRKeyAccentCustom @"spotifyglass.redesign.accent.custom"+// The redesign's own green until another is picked; Spotify's is a pick of its own, stored as -1.+#define SGRDefaultAccent 0x37F200UIColor *SGRAccentColor(void); // nil while Spotify's own green is kept-NSString *SGRAccentLabel(void); // "#RRGGBB", or the name of Spotify's own-void SGRPickAccent(void); // the system colour picker over the top of the app, stored on the way out+NSInteger SGRAccentRGB(void); // the colour in effect, 0xRRGGBB, Spotify's green included@class SGModRow;-NSArray<SGModRow *> *SGRAppearanceRows(void); // the accent colour, for the Appearance card+NSArray<SGModRow *> *SGRAppearanceRows(void); // the accent colour, for the Appearance pagediff --git a/tweak/Sources/Redesigned/Kit/SGRAccent.x b/tweak/Sources/Redesigned/Kit/SGRAccent.xindex 54cbbece..0b29f78d 100644--- a/tweak/Sources/Redesigned/Kit/SGRAccent.x+++ b/tweak/Sources/Redesigned/Kit/SGRAccent.x@@ -7,7 +7,6 @@// out of reach.#import "Core/SGCore.h"#import "SGRAccent.h"-#import "Settings/SGPageStyle.h"// The greens the app is known to build from literals: the token, and the older brand green the// upsell backend still names.@@ -15,11 +14,8 @@ static const uint32_t kGreens[] = {0x1ED760, 0x1DB954};static NSInteger sg_accent = -1; // 0xRRGGBB once chosen, read at launch-// The redesign's own green until another is picked; Spotify's is a pick of its own, stored as -1.-static const NSInteger kDefaultAccent = 0x37F200;-static NSInteger chosen(void) {- NSInteger rgb = SGInt(SGRKeyAccent, kDefaultAccent);+ NSInteger rgb = SGInt(SGRKeyAccent, SGRDefaultAccent);return rgb >= 0 && rgb <= 0xFFFFFF ? rgb : -1;}@@ -37,38 +33,9 @@ UIColor *SGRAccentColor(void) {return [UIColor colorWithRed:r green:g blue:b alpha:1];}-NSString *SGRAccentLabel(void) {+NSInteger SGRAccentRGB(void) {NSInteger rgb = chosen();- if (rgb == SGAppleMusicRed) return @"Apple Music red";- return rgb < 0 ? @"Spotify green" : [NSString stringWithFormat:@"#%06lX", (long)rgb];-}--#pragma mark - picker--@interface SGRAccentPicker : NSObject <UIColorPickerViewControllerDelegate>-@end--@implementation SGRAccentPicker--- (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)picker {- CGFloat r = 0, g = 0, b = 0, a = 0;- [picker.selectedColor getRed:&r green:&g blue:&b alpha:&a];- uint32_t rgb = ((uint32_t)lround(MIN(1, MAX(0, r)) * 255) << 16)- | ((uint32_t)lround(MIN(1, MAX(0, g)) * 255) << 8)- | (uint32_t)lround(MIN(1, MAX(0, b)) * 255);- SGSetInt(SGRKeyAccent, rgb);-}--@end--void SGRPickAccent(void) {- static SGRAccentPicker *delegate;- if (!delegate) delegate = [SGRAccentPicker new];- UIColorPickerViewController *picker = [UIColorPickerViewController new];- picker.supportsAlpha = NO;- picker.selectedColor = SGRAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1];- picker.delegate = delegate;- [SGTopController() presentViewController:picker animated:YES completion:nil];+ return rgb < 0 ? SGSpotifyGreen : rgb;}// A darker green than the token comes out as the accent darkened by the same amount, so the twodiff --git a/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m b/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.mindex 24ddf43f..7681bd25 100644--- a/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m+++ b/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m@@ -3,25 +3,41 @@#import "Settings/SGPageStyle.h"#import "SGRAccent.h"-// Apple Music's red is one tap away, unless it is the colour already. 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.-static void chooseAccent(void) {- UIViewController *top = SGTopController();- UIAlertController *sheet = [UIAlertController alertControllerWithTitle:@"Accent colour" message:nil preferredStyle:UIAlertControllerStyleActionSheet];- if (SGInt(SGRKeyAccent, -1) != SGAppleMusicRed)- [sheet addAction:[UIAlertAction actionWithTitle:@"Apple Music red" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGSetInt(SGRKeyAccent, SGAppleMusicRed); }]];- [sheet addAction:[UIAlertAction actionWithTitle:@"Pick a colour" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGRPickAccent(); }]];- if (SGRAccentColor()) [sheet addAction:[UIAlertAction actionWithTitle:@"Spotify green" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { SGSetInt(SGRKeyAccent, -1); }]];- [sheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];- sheet.popoverPresentationController.sourceView = top.view;- sheet.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(top.view.bounds), CGRectGetMidY(top.view.bounds), 0, 0);- sheet.popoverPresentationController.permittedArrowDirections = 0;- [top presentViewController:sheet animated:YES completion:nil];+// The preset is read off the colour stored, so the hooks keep the one key they read and a colour set before+// presets existed stays in effect: Apple Music's red reads as Apple Music, Spotify's own (-1) as Spotify, and+// any other colour as Custom, the redesign's own green when nothing is stored among them. The custom colour+// is put aside while a preset is in place, so Custom brings it back.+static NSArray<NSString *> *presets(void) {+ return @[@"Spotify", @"Apple Music", @"Custom"];}-// The redesign's rows of the Appearance card (App/Pages.m). AMOLED has no row: the redesign is always black.+static NSInteger preset(void) {+ NSInteger rgb = SGInt(SGRKeyAccent, SGRDefaultAccent);+ if (rgb < 0 || rgb > 0xFFFFFF) return 0;+ return rgb == SGAppleMusicRed ? 1 : 2;+}++static void choosePreset(NSInteger index) {+ if (preset() == 2) SGSetInt(SGRKeyAccentCustom, SGRAccentRGB());+ NSInteger custom = SGInt(SGRKeyAccentCustom, SGRDefaultAccent);+ if (custom < 0 || custom > 0xFFFFFF) custom = SGRDefaultAccent;+ SGSetInt(SGRKeyAccent, index == 0 ? -1 : index == 1 ? SGAppleMusicRed : custom);+}++// The redesign's rows of the Appearance page (App/Pages.m): the preset from a menu, then the colour in effect,+// which opens the picker; a colour stored from there is Custom. AMOLED has no row: the redesign is always black.NSArray<SGModRow *> *SGRAppearanceRows(void) {+ SGModRow *menu = SGMenuRow(@"Accent colour preset", presets(), ^NSString *{ return presets()[(NSUInteger)preset()]; },+ ^(NSInteger index) { choosePreset(index); });+ SGModRow *colour = SGStatActionRow(@"Accent colour", nil, ^NSString *{ return [NSString stringWithFormat:@"#%06lX", (long)SGRAccentRGB()]; }, ^{+ SGPickColor(@"Accent colour", SGRAccentRGB(), ^(NSInteger rgb) {+ SGSetInt(SGRKeyAccent, rgb);+ SGSetInt(SGRKeyAccentCustom, rgb);+ });+ });+ colour.swatch = ^UIColor *{ return SGColorRGB(SGRAccentRGB()); };return @[- SGWithSymbol(SGStatActionRow(@"Accent colour", nil, ^NSString *{ return SGRAccentLabel(); }, ^{ chooseAccent(); }), @"paintpalette"),+ SGWithSymbol(menu, @"paintpalette"),+ SGWithSymbol(colour, @"eyedropper"),];}diff --git a/tweak/Sources/Settings/SGModPage.h b/tweak/Sources/Settings/SGModPage.hindex fd33f529..5c7a636b 100644--- a/tweak/Sources/Settings/SGModPage.h+++ b/tweak/Sources/Settings/SGModPage.h@@ -40,6 +40,10 @@@property (nonatomic, copy) double (^number)(void);@property (nonatomic, copy) void (^setNumber)(double value);@property (nonatomic, copy) NSString *(^format)(double value);+// A menu row's (SGMenuRow): the names its pull-down menu offers, the current one being whichever `value` reads.+@property (nonatomic, copy) NSArray<NSString *> *menu;+// A small rounded square of this colour before the row's value.+@property (nonatomic, copy) UIColor *(^swatch)(void);@end@interface SGModSection : NSObject@@ -78,6 +82,14 @@ SGModRow *SGChoiceRow(NSString *title, NSString *subtitle, NSString *key, NSArra// changes applies while it is dragged. `subtitle` may be nil.SGModRow *SGSliderRow(NSString *title, NSString *subtitle, double minimum, double maximum, double step,double (^get)(void), void (^set)(double value), NSString *(^format)(double value));+// A setting picked from a short list without leaving the page: the value is a button whose pull-down menu+// lists `choices`, a checkmark against the one `value` reads, and picking one runs `chosen` with its index,+// after which the page reads every row again.+SGModRow *SGMenuRow(NSString *title, NSArray<NSString *> *choices, NSString *(^value)(void), void (^chosen)(NSInteger index));+// The system colour picker in a page sheet, opaque colours only: the checkmark hands 0xRRGGBB to `picked`,+// closing or swiping the sheet away keeps what was there.+void SGPickColor(NSString *title, NSInteger initial, void (^picked)(NSInteger rgb));+UIColor *SGColorRGB(NSInteger rgb); // 0xRRGGBB, opaqueSGModRow *SGLinkRow(NSString *title, NSString *subtitle, NSString *url);SGModRow *SGStatActionRow(NSString *title, NSString *subtitle, NSString *(^value)(void), void (^action)(void));SGModSection *SGSection(NSString *title, NSArray<SGModRow *> *rows);diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.mindex 95086ab8..360c97fb 100644--- a/tweak/Sources/Settings/SGModPage.m+++ b/tweak/Sources/Settings/SGModPage.m@@ -199,6 +199,68 @@ SGModRow *SGSliderRow(NSString *title, NSString *subtitle, double minimum, doublreturn row;}+// The page builds the button and its menu (-menuButtonFor:), since it is the page that reads the rows again.+SGModRow *SGMenuRow(NSString *title, NSArray<NSString *> *choices, NSString *(^value)(void), void (^chosen)(NSInteger index)) {+ SGModRow *row = SGStatRow(title, value);+ row.menu = choices;+ row.chosen = chosen;+ return row;+}++#pragma mark - the colour sheet++// Holds the picker's callback for as long as the sheet is up: the checkmark is the one way a colour is stored.+@interface SGColorSheet : NSObject+@property (nonatomic, weak) UIColorPickerViewController *picker;+@property (nonatomic, copy) void (^picked)(NSInteger rgb);+@end++@implementation SGColorSheet++- (void)confirm {+ CGFloat r = 0, g = 0, b = 0, a = 0;+ [self.picker.selectedColor getRed:&r green:&g blue:&b alpha:&a];+ NSInteger rgb = (lround(MIN(1, MAX(0, r)) * 255) << 16) | (lround(MIN(1, MAX(0, g)) * 255) << 8) | lround(MIN(1, MAX(0, b)) * 255);+ void (^picked)(NSInteger rgb) = self.picked;+ [self.picker.navigationController dismissViewControllerAnimated:YES completion:nil];+ if (picked) picked(rgb);+}++- (void)cancel {+ [self.picker.navigationController dismissViewControllerAnimated:YES completion:nil];+}++@end++// Made from a CGColor: either look's accent hooks swap Spotify's green as UIColor makes it from components, and+// this colour has to stay the one asked for, Spotify's green included, to show what a preset is.+UIColor *SGColorRGB(NSInteger rgb) {+ CGColorRef cg = CGColorCreateSRGB(((rgb >> 16) & 0xFF) / 255.0, ((rgb >> 8) & 0xFF) / 255.0, (rgb & 0xFF) / 255.0, 1);+ UIColor *color = [UIColor colorWithCGColor:cg];+ CGColorRelease(cg);+ return color;+}++void SGPickColor(NSString *title, NSInteger initial, void (^picked)(NSInteger rgb)) {+ UIColorPickerViewController *picker = [UIColorPickerViewController new];+ picker.navigationItem.title = title;+ picker.supportsAlpha = NO;+ picker.selectedColor = SGColorRGB(initial);+ SGColorSheet *sheet = [SGColorSheet new];+ sheet.picker = picker;+ sheet.picked = picked;+ UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"checkmark"] style:UIBarButtonItemStyleDone target:sheet action:@selector(confirm)];+ done.accessibilityLabel = @"Done";+ picker.navigationItem.rightBarButtonItem = done;+ // Inside a navigation controller the picker drops its own close button, so the bar carries one.+ picker.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemClose target:sheet action:@selector(cancel)];+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:picker];+ nav.modalPresentationStyle = UIModalPresentationPageSheet;+ nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ objc_setAssociatedObject(nav, @selector(confirm), sheet, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ [SGTopController() presentViewController:nav animated:YES completion:nil];+}+SGModRow *SGLinkRow(NSString *title, NSString *subtitle, NSString *url) {return SGActionRow(title, subtitle, ^{ SGOpenURL(url); });}@@ -250,6 +312,36 @@ static UIView *valueAndChevron(NSString *text) {return box;}+// What a row with a value and no page shows on the right: the value, after a swatch of the row's colour+// when it has one, rounded like the cards and edged with a hairline so a dark colour still shows on them.+// The swatch is drawn into an image, past the accent hooks on layer backgrounds (see SGColorRGB).+static UIView *valueView(SGModRow *row) {+ UILabel *label = [UILabel new];+ label.font = SGTitleFont();+ label.textColor = SGGrey();+ label.text = row.value();+ [label sizeToFit];+ if (!row.swatch) return label;+ CGFloat side = 16, height = MAX(side, label.bounds.size.height);+ UIColor *fill = row.swatch();+ UIImage *image = [[[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(side, side)] imageWithActions:^(UIGraphicsImageRendererContext *context) {+ [fill setFill];+ [context fillRect:CGRectMake(0, 0, side, side)];+ }];+ UIImageView *swatch = [[UIImageView alloc] initWithImage:image];+ swatch.frame = CGRectMake(0, (height - side) / 2, side, side);+ swatch.clipsToBounds = YES;+ swatch.layer.cornerRadius = 4;+ swatch.layer.cornerCurve = kCACornerCurveContinuous;+ swatch.layer.borderWidth = 1 / UIScreen.mainScreen.scale;+ swatch.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.3].CGColor;+ UIView *box = [[UIView alloc] initWithFrame:CGRectMake(0, 0, side + 8 + label.bounds.size.width, height)];+ label.center = CGPointMake(side + 8 + label.bounds.size.width / 2, height / 2);+ [box addSubview:swatch];+ [box addSubview:label];+ return box;+}+// On means the row's own override is in place; anything else, including the opposite override// somebody set from the All flags page, reads as off.static BOOL flagRowOn(SGModRow *row) {@@ -534,6 +626,11 @@ static const CGFloat kSliderTop = 12, kSliderLine = 18, kSliderSubtitle = 14, kScell.accessoryView = valueAndChevron(text);continue;}+ if (row.swatch) {+ UILabel *shown = (UILabel *)cell.accessoryView.subviews.lastObject;+ if ([shown isKindOfClass:UILabel.class] && ![shown.text isEqualToString:row.value()]) cell.accessoryView = valueView(row);+ continue;+ }UILabel *label = (UILabel *)cell.accessoryView;if (!row.value || row.page || ![label isKindOfClass:UILabel.class]) continue;label.text = row.value();@@ -625,13 +722,10 @@ static const CGFloat kSliderTop = 12, kSliderLine = 18, kSliderSubtitle = 14, kSUIView *link = row.value ? valueAndChevron(row.value()) : SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);cell.accessoryView = row.info ? [self infoButtonBeside:link] : link;cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ } else if (row.menu) {+ cell.accessoryView = [self menuButtonFor:row];} else if (row.value) {- UILabel *label = [UILabel new];- label.font = SGTitleFont();- label.textColor = SGGrey();- label.text = row.value();- [label sizeToFit];- cell.accessoryView = label;+ cell.accessoryView = valueView(row);cell.selectionStyle = row.action ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;} else if (row.action) {cell.selectionStyle = UITableViewCellSelectionStyleDefault;@@ -653,6 +747,37 @@ static const CGFloat kSliderTop = 12, kSliderLine = 18, kSliderSubtitle = 14, kS[self readValues];}+// A menu row's value as a pop-up button, the way Settings draws one: the name in grey over the up and down+// chevrons, the menu opening on the first touch and anchored to the button, so it points at the row on iPad.+// A pick runs the row's block and every row is read again, the ones that follow from it with it.+- (UIButton *)menuButtonFor:(SGModRow *)row {+ NSString *current = row.value();+ NSMutableArray<UIAction *> *items = [NSMutableArray array];+ __weak typeof(self) weakSelf = self;+ [row.menu enumerateObjectsUsingBlock:^(NSString *name, NSUInteger i, BOOL *stop) {+ UIAction *item = [UIAction actionWithTitle:name image:nil identifier:nil handler:^(UIAction *action) {+ if (row.chosen) row.chosen((NSInteger)i);+ [weakSelf.tableView reloadData];+ }];+ item.state = [name isEqualToString:current] ? UIMenuElementStateOn : UIMenuElementStateOff;+ [items addObject:item];+ }];+ UIButtonConfiguration *look = [UIButtonConfiguration plainButtonConfiguration];+ look.attributedTitle = [[NSAttributedString alloc] initWithString:current ?: @"" attributes:@{NSFontAttributeName: SGTitleFont()}];+ look.image = [UIImage systemImageNamed:@"chevron.up.chevron.down" withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:11 weight:UIImageSymbolWeightSemibold]];+ look.imagePlacement = NSDirectionalRectEdgeTrailing;+ look.imagePadding = 5;+ look.baseForegroundColor = SGGrey();+ look.contentInsets = NSDirectionalEdgeInsetsMake(8, 8, 8, 0);+ UIButton *button = [UIButton buttonWithConfiguration:look primaryAction:nil];+ button.menu = [UIMenu menuWithChildren:items];+ button.showsMenuAsPrimaryAction = YES;+ button.accessibilityLabel = row.title;+ button.accessibilityValue = current;+ [button sizeToFit];+ return button;+}+// The ⓘ to the left of the switch (or of a choice's name and chevron), the grey of a subtitle, 30pt across// so it is easy to hit next to it.- (UIView *)infoButtonBeside:(UIView *)toggle {