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

fix: a redesigned playlist, album or artist page takes the cover's main color

My-Name-Is-Jeffe0f721eaf57c
diff --git a/harness/palette/README.md b/harness/palette/README.md
new file mode 100644
index 00000000..f41497ff
--- /dev/null
+++ b/harness/palette/README.md
@@ -0,0 +1,8 @@
+# Palette check
+
+ ./build.sh && build/palette-check
+
+runs `Redesigned/Kit/SGRPalette.m` on the Mac (as Mac Catalyst, for UIKit): a blue cover with a pale border along
+its foot, read once by its bottom edge (the player's field) and once by its main colour (a playlist, album or
+artist page, `mainColor`). The edge has to come out grey and the main colour blue. It prints PASS or FAIL; the exit
+status is the number of failures.
diff --git a/harness/palette/build.sh b/harness/palette/build.sh
new file mode 100755
index 00000000..457fda24
--- /dev/null
+++ b/harness/palette/build.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Builds the palette check for the Mac (Mac Catalyst, for UIKit): Redesigned/Kit/SGRPalette.m as the tweak compiles it.
+set -e
+cd "$(dirname "$0")"
+SRC=../../tweak/Sources
+SDK=$(xcrun --sdk macosx --show-sdk-path)
+mkdir -p build
+xcrun clang -fobjc-arc -O0 -g -target arm64-apple-ios17.0-macabi -isysroot "$SDK" \
+ -iframework "$SDK/System/iOSSupport/System/Library/Frameworks" -isystem "$SDK/System/iOSSupport/usr/include" \
+ -I"$SRC" check.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m \
+ -framework UIKit -framework CoreImage -framework CoreGraphics -framework QuartzCore -o build/palette-check
+echo "built build/palette-check"
diff --git a/harness/palette/check.m b/harness/palette/check.m
new file mode 100644
index 00000000..723cc22a
--- /dev/null
+++ b/harness/palette/check.m
@@ -0,0 +1,37 @@
+// The field colour a page takes from its cover: the main colour, not the bottom edge. A blue cover with a
+// pale scanner border along its foot, which read by the edge turned the album page grey (device, 2026-09-18).
+#import <UIKit/UIKit.h>
+#import "Redesigned/Kit/SGRPalette.h"
+
+// SGRTokens.m's accent comes from SGRAccent.x, which this does not compile.
+UIColor *SGRAccentColor(void) { return UIColor.greenColor; }
+
+static UIImage *cover(void) {
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(300, 300)];
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
+ [[UIColor colorWithRed:0.1 green:0.3 blue:0.9 alpha:1] setFill];
+ UIRectFill(CGRectMake(0, 0, 300, 300));
+ [[UIColor colorWithWhite:0.85 alpha:1] setFill];
+ UIRectFill(CGRectMake(0, 255, 300, 45));
+ }];
+}
+
+int main(void) {
+ @autoreleasepool {
+ __block int done = 0, fails = 0;
+ for (int main = 0; main < 2; main++) {
+ SGRPaletteRequest request = {CGSizeZero, NO, YES, NO, main};
+ [SGRPalette paletteForImage:cover() request:request completion:^(SGRPalette *palette) {
+ CGFloat r, g, b, a;
+ [palette.fieldColor getRed:&r green:&g blue:&b alpha:&a];
+ BOOL blue = b > r + 0.05 && b > g;
+ printf("%s: field %.3f %.3f %.3f, %s\n", main ? "main colour" : "bottom edge", r, g, b, blue ? "blue" : "grey");
+ if (blue != (BOOL)main) fails++;
+ done++;
+ }];
+ }
+ while (done < 2) [NSRunLoop.mainRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
+ printf(fails ? "FAIL\n" : "PASS\n");
+ return fails;
+ }
+}
diff --git a/tweak/Sources/Redesigned/Album/Album.h b/tweak/Sources/Redesigned/Album/Album.h
index 54787081..45d4f341 100644
--- a/tweak/Sources/Redesigned/Album/Album.h
+++ b/tweak/Sources/Redesigned/Album/Album.h
@@ -59,6 +59,6 @@ UIView *SGRAlbumPageOf(UIView *view);
UIColor *SGRAlbumFieldColor(UIView *view);
// The cover of the page `view` is on, for its field to take its colour from. The same image again is a no-op.
void SGRAlbumSetArtwork(UIView *view, UIImage *image);
-// The colour Spotify picked for the album, read off the wash it paints behind the header: the field takes it
-// over the one read from the cover's bottom edge. The same colour again is a no-op.
+// The colour Spotify picked for the album, read off the wash it paints behind the header: the field shows it
+// until the cover's own main colour has been read, and not after.
void SGRAlbumSetSpotifyColor(UIView *view, UIColor *color);
diff --git a/tweak/Sources/Redesigned/Album/AlbumField.x b/tweak/Sources/Redesigned/Album/AlbumField.x
index 954bf1f8..fb577bef 100644
--- a/tweak/Sources/Redesigned/Album/AlbumField.x
+++ b/tweak/Sources/Redesigned/Album/AlbumField.x
@@ -14,11 +14,11 @@
// repaint hook while sgr_albumRoot is this page, and by the list's own pass below, which paints itself
// rather than through a layer the repaint hook would hear about.
//
-// The colour is Spotify's own for the album, read off the wash it paints behind the header, which
-// AlbumHeader.x hands over as it conceals it. Spotify reads the whole cover; the Kit's palette reads its
-// bottom edge, and a scanned cover's bottom edge is the scanner's pale border, which turned the field grey
-// where Spotify had it blue (device, 2026-09-18). The colour read from the cover is what shows until
-// Spotify's arrives, or for good if it never does, and before either the field is the neutral one.
+// The colour is the cover's main colour, as the playlist's and the artist's are. Read off the bottom edge
+// it was a scanned cover's pale border, which turned the field grey where the cover is blue (device,
+// 2026-09-18); for a while Spotify's own colour, read off the wash it paints behind the header, won over
+// it for that reason. That colour is now only what shows until the cover has been read (AlbumHeader.x
+// hands it over as it conceals the wash), and before either the field is the neutral one.
//
// The page is the album's by its identifier, which is how Native/Album/Album.x has told it apart since it
// shipped: the artist page is TemplateKit's TemplateView instead. A podcast's episode page is built from
@@ -78,7 +78,7 @@ void SGRAlbumSetArtwork(UIView *view, UIImage *image) {
}
void SGRAlbumSetSpotifyColor(UIView *view, UIColor *color) {
- if (color) [fieldOn(view) setPreferredColor:color];
+ if (color) [fieldOn(view) setProvisionalColor:color];
}
static SGRArtworkField *fieldIn(UIView *page) {
@@ -86,6 +86,7 @@ static SGRArtworkField *fieldIn(UIView *page) {
if (field) return field;
field = [[SGRArtworkField alloc] initWithFrame:page.bounds];
field.bleed = kBleed;
+ field.mainColor = YES;
objc_setAssociatedObject(page, &kFieldKey, field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
SGLog(@"redesign album: field on the page %.0fx%.0f", page.bounds.size.width, page.bounds.size.height);
return field;
diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.x
index 443c77ff..669cd76d 100644
--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x
+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x
@@ -502,7 +502,7 @@ static UIColor *washColorOf(UIView *gradient) {
}
// Spotify's colour wash behind the header goes, so the page's field shows through, and the colour it was
-// painted in goes to the field: Spotify reads the whole cover for it, where the Kit reads the bottom edge.
+// painted in goes to the field, to show until the cover's own main colour has been read.
//
// The navigation bar's gradient goes too. Hidden at rest, it is shown as the page scrolls under the
// title, and over the field it was a flat dark band across the top (device, 2026-09-18). What keeps the
diff --git a/tweak/Sources/Redesigned/Artist/ArtistField.x b/tweak/Sources/Redesigned/Artist/ArtistField.x
index 7f64f9e1..0faa7222 100644
--- a/tweak/Sources/Redesigned/Artist/ArtistField.x
+++ b/tweak/Sources/Redesigned/Artist/ArtistField.x
@@ -57,6 +57,8 @@ static SGRArtworkField *fieldIn(UIView *page) {
if (field) return field;
field = [[SGRArtworkField alloc] initWithFrame:page.bounds];
field.bleed = kBleed;
+ // The photo's main colour, not its bottom edge, which on a portrait is the artist's shirt.
+ field.mainColor = YES;
objc_setAssociatedObject(page, &kFieldKey, field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
SGLog(@"redesign artist: field on the page %.0fx%.0f", page.bounds.size.width, page.bounds.size.height);
return field;
diff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.h
index 1593bc41..69ed1617 100644
--- a/tweak/Sources/Redesigned/Kit/SGRField.h
+++ b/tweak/Sources/Redesigned/Kit/SGRField.h
@@ -1,5 +1,5 @@
-// The artwork field: one continuous colour taken from the artwork's bottom edge (SGRPalette.h) behind
-// a whole redesigned page, with no card and no seam anywhere. The player's field also carries the
+// The artwork field: one continuous colour taken from the artwork (SGRPalette.h) behind a whole
+// redesigned page, with no card and no seam anywhere. The player's field also carries the
// artwork itself at the top, blurred and dimmed and dissolving into the colour (showsBackdrop).
//
// Nothing is blurred live and nothing is masked: the view draws a solid colour layer, a black gradient
@@ -41,13 +41,14 @@ extern NSNotificationName const SGRFieldColorDidChangeNotification;
// SGRNeutralField until a colour arrives.
@property (nonatomic, readonly) UIColor *fieldColor;
-// A colour Spotify already has for the page (the player's background colour), made fit to be a field
-// and shown until the first artwork has been read; ignored after that.
+// The colour from the artwork's main colour rather than its bottom edge (SGRPaletteRequest's mainColor): a
+// playlist, album or artist page, whose cover dissolves into the field. The player keeps the edge, where its
+// backdrop meets the colour. Set before the first artwork.
+@property (nonatomic) BOOL mainColor;
+
+// A colour Spotify already has for the page (the player's background colour, the album's wash), made fit
+// to be a field and shown until the first artwork has been read; ignored after that.
- (void)setProvisionalColor:(UIColor *)color;
-// A colour the page already picked for itself (Spotify's own for an album), made fit to be a field; it wins
-// over the one read from the artwork's bottom edge, which on a scanned cover is the scanner's grey border
-// rather than the picture. nil keeps what is set.
-- (void)setPreferredColor:(UIColor *)color;
// Reads the artwork off the main thread and crossfades the result in (without animation when
// `animated` is NO or the field is not in a window). The same image, or the same non-nil identity,
// as the last call is a no-op, and a result that lands after a newer call is dropped. nil keeps
diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.m
index 5f5fcb13..bd0d1949 100644
--- a/tweak/Sources/Redesigned/Kit/SGRField.m
+++ b/tweak/Sources/Redesigned/Kit/SGRField.m
@@ -39,7 +39,6 @@ static NSDictionary *noActions(void) {
SGRFluidLayer *_fluidLayer;
BOOL _watching;
UIColor *_color;
- UIColor *_preferred; // the page's own colour, made fit; wins over the artwork's
UIImage *_image;
NSString *_identity;
NSUInteger _generation;
@@ -228,21 +227,13 @@ static NSDictionary *noActions(void) {
[self applyColor:SGRFieldColorFor(color) animated:self.window != nil];
}
-- (void)setPreferredColor:(UIColor *)color {
- if (!color) return;
- UIColor *fit = SGRFieldColorFor(color);
- if (_preferred && CGColorEqualToColor(fit.CGColor, _preferred.CGColor)) return;
- _preferred = fit;
- [self applyColor:fit animated:self.window != nil];
-}
-
- (void)setArtwork:(UIImage *)image identity:(NSString *)identity animated:(BOOL)animated {
if (!image || image == _image || (identity && [identity isEqualToString:_identity])) return;
_image = image;
_identity = [identity copy];
if (_fluid) [_fluidLayer setArtwork:image animated:animated && self.window != nil];
NSUInteger generation = ++_generation;
- SGRPaletteRequest request = {CGSizeZero, NO, YES, _flows};
+ SGRPaletteRequest request = {CGSizeZero, NO, YES, _flows, _mainColor};
if (_showsBackdrop && !_flows && !_fluid) request.backdropSize = CGSizeMake(self.bounds.size.width > 0 ? self.bounds.size.width : 402, [self backdropHeightNow]);
__weak SGRArtworkField *weakSelf = self;
[SGRPalette paletteForImage:image request:request completion:^(SGRPalette *palette) {
@@ -259,7 +250,7 @@ static NSDictionary *noActions(void) {
_flow.hidden = NO;
[self updateMotion];
// Past the moving field's edges (the pull that dismisses the player) the colour under it goes on.
- [self applyColor:_preferred ?: _flow.baseColor animated:animated];
+ [self applyColor:_flow.baseColor animated:animated];
return;
}
if (_showsBackdrop && !_flows && !_fluid && palette.backdrop) {
@@ -275,7 +266,7 @@ static NSDictionary *noActions(void) {
_backdrop.hidden = NO;
[CATransaction commit];
}
- [self applyColor:_preferred ?: palette.fieldColor animated:animated];
+ [self applyColor:palette.fieldColor animated:animated];
}
@end
diff --git a/tweak/Sources/Redesigned/Kit/SGRPalette.h b/tweak/Sources/Redesigned/Kit/SGRPalette.h
index 6b62b5a8..c5ee14d9 100644
--- a/tweak/Sources/Redesigned/Kit/SGRPalette.h
+++ b/tweak/Sources/Redesigned/Kit/SGRPalette.h
@@ -1,8 +1,8 @@
// What a redesigned page takes from its artwork, worked out off the main thread in one pass: the
-// colour along the artwork's bottom edge, the field colour made from it, and the blurred bitmaps the
-// field (SGRField.h) draws instead of a live blur.
+// colour along the artwork's bottom edge, the field colour made from it (or from the artwork's main
+// colour, for a page), and the blurred bitmaps the field (SGRField.h) draws instead of a live blur.
//
-// The field colour is the edge colour with its saturation held to 0.55 and its relative luminance to
+// The field colour is the edge or main colour with its saturation held to 0.55 and its relative luminance to
// 0.07 (0.04 with Increase Contrast). On anything that dark white text is past 8:1 and SGRSecondary
// (white 65%) past 4.5:1, WCAG AA, whatever the hue.
//
@@ -22,6 +22,10 @@ typedef struct {
BOOL amoled;
// The colours of a moving field (SGRFlow.h): the artwork's main colour in each quarter and overall.
BOOL flow;
+ // The field colour from the artwork's main colour (the one +tintForImage: finds) rather than its bottom
+ // edge: for a page, whose cover dissolves into the field across its whole width, where the bottom edge
+ // is a scanned cover's pale border or whatever strip happens to sit at the foot of the picture.
+ BOOL mainColor;
} SGRPaletteRequest;
@interface SGRPalette : NSObject
diff --git a/tweak/Sources/Redesigned/Kit/SGRPalette.m b/tweak/Sources/Redesigned/Kit/SGRPalette.m
index 2306e763..7df4ccb8 100644
--- a/tweak/Sources/Redesigned/Kit/SGRPalette.m
+++ b/tweak/Sources/Redesigned/Kit/SGRPalette.m
@@ -285,7 +285,10 @@ static UIColor *tintOf(CGImageRef image, UIColor *surface) {
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
palette = [SGRPalette new];
palette.edgeColor = edge;
- palette.fieldColor = fieldColorFor(edge, ceiling);
+ CGFloat main[3];
+ UIColor *base = request.mainColor && dominantColorOf(cg, main)
+ ? [UIColor colorWithRed:toEncoded(main[0]) green:toEncoded(main[1]) blue:toEncoded(main[2]) alpha:1] : edge;
+ palette.fieldColor = fieldColorFor(base, ceiling);
CGSize area = request.backdropSize;
if (area.width > 0 && area.height > 0) {
size_t width = (size_t)kBackdropWidth, height = (size_t)MIN(kBackdropMaxHeight, round(kBackdropWidth * area.height / area.width));
diff --git a/tweak/Sources/Redesigned/Playlist/PlaylistField.x b/tweak/Sources/Redesigned/Playlist/PlaylistField.x
index 6309edab..5eeb8b1e 100644
--- a/tweak/Sources/Redesigned/Playlist/PlaylistField.x
+++ b/tweak/Sources/Redesigned/Playlist/PlaylistField.x
@@ -12,8 +12,9 @@
// exactly this field's colour. What Spotify paints over the field -- the page, the list and every row, all
// of them the base surface -- is kept clear by the Kit's repaint hook while sgr_playlistRoot is this page.
//
-// The colour is read from the cover the header shows (PlaylistHeader.x hands it over), and until that has
-// loaded the field is the neutral one, as it is for a playlist with no cover at all.
+// The colour is the main colour of the cover the header shows (PlaylistHeader.x hands it over), not its
+// bottom edge, and until that has loaded the field is the neutral one, as it is for a playlist with no
+// cover at all.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
#import "Playlist.h"
@@ -49,6 +50,7 @@ static SGRArtworkField *fieldIn(UIView *page) {
if (field) return field;
field = [[SGRArtworkField alloc] initWithFrame:page.bounds];
field.bleed = kBleed;
+ field.mainColor = YES;
objc_setAssociatedObject(page, &kFieldKey, field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
SGLog(@"redesign playlist: field on the page %.0fx%.0f", page.bounds.size.width, page.bounds.size.height);
return field;