Skip to content

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

C

feat: accent color

Vojtěch Škopek9d8a900a718d
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 613fb658..3f9aa9a3 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -36,7 +36,7 @@ app:
Home/ the Home gradient
Playlist/ the playlist header and pills, hidden one switch each
Declutter/ cards under the player and sections of Home collapsed, player buttons hidden; rows on the Now Playing and Home pages
- Appearance/ AMOLED (Amoled.x), the glass search field (SearchField.x), and Repaint.x, which keeps stripped areas transparent
+ Appearance/ AMOLED (Amoled.x), the glass search field (SearchField.x), the accent colour (Accent.x), and Repaint.x, which keeps stripped areas transparent
Flags/ Spotify's remote-config flags: the provider hook, the generated table, the All flags page and the topic pages
Privacy/ telemetry blocking and its counters
AdBlock/ EeveeSpotify's ad blocking: the ad and upsell services silenced (AdServices.x), ad components out of the
diff --git a/tweak/Sources/Features/Appearance/Accent.x b/tweak/Sources/Features/Appearance/Accent.x
new file mode 100644
index 00000000..fa788dc3
--- /dev/null
+++ b/tweak/Sources/Features/Appearance/Accent.x
@@ -0,0 +1,170 @@
+// Accent colour: Spotify's green, #1ED760, is one token. Its three components occur once in the
+// whole binary, and every green the app draws, from the play button to the "Zobrazit vše" links
+// and the progress bar, is that token or a state blended from it. So it is swapped where it is
+// born, in the UIColor initialiser, and the blends follow. Lottie animations carry their own green
+// and are caught at the layer, below. Image assets with green baked in, the logo above all, are
+// 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.
+static const uint32_t kGreens[] = {0x1ED760, 0x1DB954};
+
+static NSInteger sg_accent = -1; // 0xRRGGBB once chosen, read at launch
+
+static NSInteger chosen(void) {
+ NSInteger rgb = SGInt(SGKeyAccent, -1);
+ return rgb >= 0 && rgb <= 0xFFFFFF ? rgb : -1;
+}
+
+static void unpack(uint32_t rgb, CGFloat *r, CGFloat *g, CGFloat *b) {
+ *r = ((rgb >> 16) & 0xFF) / 255.0;
+ *g = ((rgb >> 8) & 0xFF) / 255.0;
+ *b = (rgb & 0xFF) / 255.0;
+}
+
+UIColor *SGAccentColor(void) {
+ NSInteger rgb = chosen();
+ if (rgb < 0) return nil;
+ CGFloat r, g, b;
+ unpack((uint32_t)rgb, &r, &g, &b);
+ return [UIColor colorWithRed:r green:g blue:b alpha:1];
+}
+
+NSString *SGAccentLabel(void) {
+ NSInteger rgb = chosen();
+ 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];
+}
+
+// A darker green than the token comes out as the accent darkened by the same amount, so the two
+// keep their relation.
+static BOOL swap(CGFloat *r, CGFloat *g, CGFloat *b) {
+ for (size_t i = 0; i < sizeof(kGreens) / sizeof(kGreens[0]); i++) {
+ CGFloat gr, gg, gb;
+ unpack(kGreens[i], &gr, &gg, &gb);
+ if (fabs(*r - gr) > 0.01 || fabs(*g - gg) > 0.01 || fabs(*b - gb) > 0.01) continue;
+ CGFloat ar, ag, ab;
+ unpack((uint32_t)sg_accent, &ar, &ag, &ab);
+ CGFloat factor = MAX(gr, MAX(gg, gb)) / (0xD7 / 255.0);
+ *r = MIN(1, ar * factor);
+ *g = MIN(1, ag * factor);
+ *b = MIN(1, ab * factor);
+ return YES;
+ }
+ return NO;
+}
+
+%hook UIColor
+- (UIColor *)initWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b alpha:(CGFloat)a {
+ swap(&r, &g, &b);
+ return %orig(r, g, b, a);
+}
++ (UIColor *)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b alpha:(CGFloat)a {
+ swap(&r, &g, &b);
+ return %orig(r, g, b, a);
+}
+%end
+
+// Lottie draws its animations, the play indicator and the checkmarks among them, from colours
+// in the animation file straight onto shape layers, or into colour keyframes, never through
+// UIColor. The same swap goes on the CGColor. Layers get set off the main thread too, so the
+// copy is made with CoreGraphics alone; NULL when the colour is not one of the greens.
+static CGColorRef swappedCopy(CGColorRef color) {
+ if (!color || CFGetTypeID(color) != CGColorGetTypeID() || CGColorGetNumberOfComponents(color) != 4) return NULL;
+ const CGFloat *c = CGColorGetComponents(color);
+ CGFloat r = c[0], g = c[1], b = c[2];
+ if (!swap(&r, &g, &b)) return NULL;
+ CGFloat out[] = {r, g, b, c[3]};
+ return CGColorCreate(CGColorGetColorSpace(color), out);
+}
+
+static id swappedValue(id value) {
+ CGColorRef swapped = swappedCopy((__bridge CGColorRef)value);
+ if (!swapped) return value;
+ id boxed = (__bridge_transfer id)swapped;
+ return boxed;
+}
+
+%hook CAShapeLayer
+- (void)setFillColor:(CGColorRef)color {
+ CGColorRef swapped = swappedCopy(color);
+ CGColorRef used = swapped ?: color;
+ %orig(used);
+ if (swapped) CGColorRelease(swapped);
+}
+- (void)setStrokeColor:(CGColorRef)color {
+ CGColorRef swapped = swappedCopy(color);
+ CGColorRef used = swapped ?: color;
+ %orig(used);
+ if (swapped) CGColorRelease(swapped);
+}
+%end
+
+%hook CALayer
+- (void)setBackgroundColor:(CGColorRef)color {
+ CGColorRef swapped = swappedCopy(color);
+ CGColorRef used = swapped ?: color;
+ %orig(used);
+ if (swapped) CGColorRelease(swapped);
+}
+%end
+
+%hook CABasicAnimation
+- (void)setFromValue:(id)value {
+ id used = swappedValue(value);
+ %orig(used);
+}
+- (void)setToValue:(id)value {
+ id used = swappedValue(value);
+ %orig(used);
+}
+%end
+
+%hook CAKeyframeAnimation
+- (void)setValues:(NSArray *)values {
+ NSMutableArray *mapped = nil;
+ for (NSUInteger i = 0; i < values.count; i++) {
+ id swapped = swappedValue(values[i]);
+ if (swapped == values[i] && !mapped) continue;
+ if (!mapped) mapped = [values mutableCopy];
+ mapped[i] = swapped;
+ }
+ NSArray *used = mapped ?: values;
+ %orig(used);
+}
+%end
+
+%ctor {
+ sg_accent = chosen();
+ if (sg_accent >= 0) %init;
+}
diff --git a/tweak/Sources/Features/Appearance/Appearance.h b/tweak/Sources/Features/Appearance/Appearance.h
index 1adf919d..84b71aa6 100644
--- a/tweak/Sources/Features/Appearance/Appearance.h
+++ b/tweak/Sources/Features/Appearance/Appearance.h
@@ -1,10 +1,16 @@
-// Appearance: the AMOLED background (Amoled.x), the glass search field (SearchField.x) and
-// Repaint.x, which keeps what the other features stripped transparent when Spotify repaints it.
-// Both switches are off until asked for, as are the tab bar's and Spotify's own glass.
+// Appearance: the AMOLED background (Amoled.x), the glass search field (SearchField.x), the
+// accent colour in place of Spotify's green (Accent.x) and Repaint.x, which keeps what the other
+// features stripped transparent when Spotify repaints it. The switches are off until asked for,
+// as are the tab bar's and Spotify's own glass.
#import <UIKit/UIKit.h>
#define SGKeyAmoled @"spotifyglass.amoled"
#define SGKeySearchField @"spotifyglass.searchField"
+#define SGKeyAccent @"spotifyglass.accent" // 0xRRGGBB; unset or negative keeps Spotify's own green
+
+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
// Liquid Glass UI, the one switch of UI Tweaks that sets others: Spotify's own glass and, with
// it, the search field, the now playing bar, the artwork background and the lyrics card. Each
diff --git a/tweak/Sources/Features/Appearance/AppearanceSettings.m b/tweak/Sources/Features/Appearance/AppearanceSettings.m
index cb1173e5..3517f0d0 100644
--- a/tweak/Sources/Features/Appearance/AppearanceSettings.m
+++ b/tweak/Sources/Features/Appearance/AppearanceSettings.m
@@ -25,6 +25,8 @@ UIViewController *SGAppearanceSettingsPage(void) {
]),
SGSection(@"Theme", @[
SGOptionRow(@"AMOLED background", @"Pure black instead of Spotify's dark grey", SGKeyAmoled),
+ SGStatActionRow(@"Accent colour", @"In place of Spotify's green, everywhere it is drawn; tap to pick", ^NSString *{ return SGAccentLabel(); }, ^{ SGPickAccent(); }),
+ SGActionRow(@"Spotify's green", @"Back to the colour the app came with", ^{ SGSetInt(SGKeyAccent, -1); }),
]),
] footer:nil];
}
diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.m
index dd4fe3e2..bb968550 100644
--- a/tweak/Sources/Settings/SGPageStyle.m
+++ b/tweak/Sources/Settings/SGPageStyle.m
@@ -67,7 +67,7 @@ void SGInsetForBars(UITableView *table) {
table.verticalScrollIndicatorInsets = inset;
}
-UIColor *SGGreen(void) { return [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }
+UIColor *SGGreen(void) { return SGAccentColor() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }
UIColor *SGRed(void) { return [UIColor colorWithRed:0xF1 / 255.0 green:0x5E / 255.0 blue:0x6B / 255.0 alpha:1]; }
UIColor *SGPageBackground(void) { return SGFlag(SGKeyAmoled, NO) ? UIColor.blackColor : [UIColor colorWithWhite:0x12 / 255.0 alpha:1]; }