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: Spotify's icons in the redesigned player and the AI DJ's footer, and the DJ button as a waveform (#180)

Andrew9e8b3080bb81
diff --git a/tweak/Sources/Redesigned/Player/DJPlayer.x b/tweak/Sources/Redesigned/Player/DJPlayer.x
index 15a5f9f8..d343fbd6 100644
--- a/tweak/Sources/Redesigned/Player/DJPlayer.x
+++ b/tweak/Sources/Redesigned/Player/DJPlayer.x
@@ -12,18 +12,23 @@
// Footer: DJMFooterUnitView holds the share button, the DJ button, Connect and an empty view, not in a stack.
// Connect and the DJ button stay Spotify's and are only moved, by a transform that survives relayout. Lyrics
// and Queue are the Kit's glyph buttons; Queue, the Music app's list.bullet (issue #109), opens spotify:now-playing:queue.
+// The DJ button's blue disc is masked away and the Music app's waveform drawn over it: the mask hides what the button
+// draws but not its touches or its accessibility, which stay Spotify's. With Spotify's icons (SGRKeyPlayerSpotifyIcons)
+// the disc stays, and Lyrics and Queue draw Spotify's Encore glyphs.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
#import "Shared/Navigation/Links.h"
#import "Player.h"
static const CGFloat kSkipGlyphSize = 32, kFooterGlyphSize = 20;
+// Spotify's Encore queue glyph is drawn larger than the glyphs beside it; this much of its size looks theirs.
+static const CGFloat kEncoreQueueScale = 0.85;
// Where the four footer glyphs sit, as parts of the footer's width: Lyrics, Connect, Queue, the DJ button.
static const CGFloat kSlots[4] = {0.2, 0.4, 0.6, 0.8};
// The DJ button's blue disc is 48pt, a good deal more than the glyphs beside it; drawn this much of that.
static const CGFloat kDJButtonScale = 0.88;
static char kPrevKey, kNextKey, kPlayKey, kGlyphKey;
-static char kShareKey, kConnectKey, kDJKey, kQueueKey;
+static char kShareKey, kConnectKey, kDJKey, kQueueKey, kDJMaskKey, kDJGlyphKey;
#pragma mark - previous and next
@@ -121,6 +126,40 @@ static SGRGlyphButton *glyphButtonIn(UIView *host, const void *key, NSString *sy
return button;
}
+// Nothing of `view` drawn, by an empty mask on its layer: Spotify gives the share button and its holder their alpha back
+// after the footer lays out, which the DJ's disc hid until the waveform took its place, and leaves a mask alone.
+static char kEmptyMaskKey;
+static void maskAway(UIView *view) {
+ if (!view) return;
+ CALayer *mask = objc_getAssociatedObject(view, &kEmptyMaskKey);
+ if (!mask) {
+ mask = [CALayer layer];
+ objc_setAssociatedObject(view, &kEmptyMaskKey, mask, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (view.layer.mask != mask) view.layer.mask = mask;
+}
+
+// The DJ button as the Music app's waveform: an empty mask over its holder, so nothing of Spotify's disc is drawn while
+// the button still takes the touches, and the glyph above it, which takes none.
+static void waveformOver(UIView *host, UIView *djHolder) {
+ CALayer *mask = objc_getAssociatedObject(djHolder, &kDJMaskKey);
+ if (!mask) {
+ mask = [CALayer layer];
+ objc_setAssociatedObject(djHolder, &kDJMaskKey, mask, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (djHolder.layer.mask != mask) djHolder.layer.mask = mask;
+ SGRGlyphView *glyph = objc_getAssociatedObject(host, &kDJGlyphKey);
+ if (!glyph) {
+ glyph = [[SGRGlyphView alloc] initWithSymbol:@"waveform" pointSize:kFooterGlyphSize weight:UIImageSymbolWeightRegular];
+ glyph.tintColor = SGRPrimary();
+ objc_setAssociatedObject(host, &kDJGlyphKey, glyph, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (glyph.superview != host) [host addSubview:glyph];
+ else if (host.subviews.lastObject != glyph) [host bringSubviewToFront:glyph];
+ // Where the holder is drawn: its center moved by the transform that places it.
+ glyph.center = CGPointMake(djHolder.center.x + djHolder.transform.tx, djHolder.center.y + djHolder.transform.ty);
+}
+
#pragma mark the row
static void styleFooter(UIViewController *unit) {
@@ -130,10 +169,14 @@ static void styleFooter(UIViewController *unit) {
BOOL rtl = host.effectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
CGFloat (^slot)(NSUInteger) = ^CGFloat(NSUInteger i) { return round(width * (rtl ? 1 - kSlots[i] : kSlots[i])); };
- // No share button; its holder goes too, since a view that takes touches swallows them with nothing on it.
+ // No share button; its holder goes too, since a view that takes touches swallows them with nothing on it. It sits
+ // under the DJ button, so it is masked away as well as vanished (maskAway).
UIView *share = SGRFindByIdentifier(host, @"ShareButtonNowPlayingView", &kShareKey);
+ UIView *shareHolder = holderIn(host, share);
SGRPlayerVanish(share);
- SGRPlayerVanish(holderIn(host, share));
+ SGRPlayerVanish(shareHolder);
+ maskAway(share);
+ maskAway(shareHolder);
SGRGlyphButton *lyrics = SGRPlayerLyricsGlyphIn(host);
lyrics.bounds = CGRectMake(0, 0, 44, 44);
@@ -156,6 +199,7 @@ static void styleFooter(UIViewController *unit) {
});
queue.bounds = CGRectMake(0, 0, 44, 44);
queue.center = CGPointMake(slot(2), middleY);
+ if (SGRPlayerSpotifyIcons()) SGRPlayerEncoreGlyphIn(queue, @"queue").transform = CGAffineTransformMakeScale(kEncoreQueueScale, kEncoreQueueScale);
// The DJ button at the last place. Connect's view reaches a long way to the right of its glyph, so the
// DJ's goes above it in the stack, or Connect would take its touches.
@@ -165,6 +209,7 @@ static void styleFooter(UIViewController *unit) {
placeHolder(djHolder, djHolder.center.x, slot(3), kDJButtonScale);
NSArray<UIView *> *order = host.subviews;
if (connectHolder && [order indexOfObject:djHolder] < [order indexOfObject:connectHolder]) [host bringSubviewToFront:djHolder];
+ if (!SGRPlayerSpotifyIcons()) waveformOver(host, djHolder);
}
SGRPlayerLowerRow(host);
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index 22922277..0801d2e5 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -136,6 +136,15 @@ void SGRPlayerPaintCover(UIView *stack);
#define SGRKeyPlayerHideShuffle @"spotifyglass.redesign.player.hideShuffle"
#define SGRKeyPlayerHideRepeat @"spotifyglass.redesign.player.hideRepeat"
+// Spotify's icons in the footer row (PlayerFooter.x, DJPlayer.x): Connect and the queue keep Spotify's own glyphs
+// instead of the Music app's, Lyrics and the AI DJ's Queue draw Spotify's Encore glyphs, and the AI DJ's button keeps
+// its blue disc instead of the waveform. Off until switched on, read at launch.
+#define SGRKeyPlayerSpotifyIcons @"spotifyglass.redesign.player.spotifyIcons"
+BOOL SGRPlayerSpotifyIcons(void);
+// Spotify's Encore glyph `name` (an SPTEncoreIcon class method: "lyrics", "queue") centered in `button` in place of its
+// symbol, which is hidden; kept on the button, so a second call hands back the same view. Nil if Spotify has none.
+UIView *SGRPlayerEncoreGlyphIn(SGRGlyphButton *button, NSString *name);
+
// The lyrics turn sideways with the phone onto a landscape screen of their own (PlayerLandscape.x). On
// until switched off. Shown or put away by hand for the harness.
#define SGRKeyLyricsLandscape @"spotifyglass.redesign.lyrics.landscape"
diff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.x
index 58b99fb3..10e76de2 100644
--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x
+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x
@@ -16,6 +16,8 @@
// Spotify has no lyrics control down here, so that one is the Kit's glyph button, and it turns the
// lyrics in the player on and off (PlayerLyrics.x): filled while they are up, dimmed and dead for a
// track that has none.
+// Spotify's icons (SGRKeyPlayerSpotifyIcons) leaves Connect's and the queue's glyphs Spotify's, and draws the Lyrics
+// glyph as Spotify's Encore "lyrics", lit in the primary color while the lyrics are up.
//
// The row sits lower than Spotify puts it, just over the home indicator the way the Music app's does
// (issue #54): the footer unit's view is translated down, the controls follow it part of the way, and a
@@ -31,6 +33,7 @@
#import "Redesigned/Kit/SGRKit.h"
#import "Headers/SPTEncoreIconView.h"
#import "Player.h"
+#import <objc/message.h>
static const CGFloat kLyricsGlyphSize = 20;
// Filled and at full strength while the lyrics are up, the way the Music app marks the control that is on.
@@ -55,6 +58,7 @@ static const CGFloat kVolumeLift = 10;
// "airplayaudio" is the name iOS 16 knows; iOS 18 calls it airplay.audio and keeps this one as its alias.
static NSString *const kConnectSymbol = @"airplayaudio", *const kQueueSymbol = @"list.bullet";
+static char kEncoreKey;
static char kConnectKey, kShareKey, kTrimmerKey, kSharedByKey, kQueueKey, kQueueIconKey, kLyricsGlyphKey, kReachKey, kRowKey;
static __weak SGRGlyphButton *sg_lyricsGlyph;
@@ -81,6 +85,44 @@ static CGFloat moveTo(UIView *arranged, UIView *view, CGPoint point, UIView *hos
return from;
}
+#pragma mark - Spotify's icons
+
+BOOL SGRPlayerSpotifyIcons(void) {
+ static BOOL on;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ on = SGHidden(SGRKeyPlayerSpotifyIcons); });
+ return on;
+}
+
+UIView *SGRPlayerEncoreGlyphIn(SGRGlyphButton *button, NSString *name) {
+ if (!button) return nil;
+ SPTEncoreIconView *encore = objc_getAssociatedObject(button, &kEncoreKey);
+ if (!encore) {
+ Class icons = NSClassFromString(@"SPTEncoreIcon"), view = NSClassFromString(@"SPTEncoreIconView");
+ SEL glyphSel = NSSelectorFromString(name);
+ if (!icons || !view || ![icons respondsToSelector:glyphSel]) {
+ SGLog(@"redesign player: no Encore glyph %@, the Music app's stays", name);
+ return nil;
+ }
+ id glyph = ((id (*)(id, SEL))objc_msgSend)(icons, glyphSel);
+ encore = glyph ? [[view alloc] initWithIcon:glyph] : nil;
+ if (!encore) return nil;
+ encore.userInteractionEnabled = NO;
+ encore.isAccessibilityElement = NO;
+ CGSize size = encore.intrinsicContentSize;
+ encore.bounds = CGRectMake(0, 0, size.width > 0 ? size.width : 24, size.height > 0 ? size.height : 24);
+ encore.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
+ | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
+ encore.foregroundColor = button.glyph.tintColor ?: SGRPrimary();
+ objc_setAssociatedObject(button, &kEncoreKey, encore, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ // Hidden rather than clear: the button puts its glyph's alpha back as it is pressed.
+ button.glyph.hidden = YES;
+ if (encore.superview != button) [button addSubview:encore];
+ encore.center = CGPointMake(CGRectGetMidX(button.bounds), CGRectGetMidY(button.bounds));
+ return encore;
+}
+
#pragma mark - lyrics
void SGRPlayerLyricsChanged(void) {
@@ -98,6 +140,7 @@ void SGRPlayerLyricsChanged(void) {
void (^mark)(void) = ^{
glyph.enabled = enabled;
glyph.glyph.tintColor = open ? SGRPrimary() : SGRSecondary();
+ ((SPTEncoreIconView *)objc_getAssociatedObject(glyph, &kEncoreKey)).foregroundColor = glyph.glyph.tintColor;
};
if (animated) SGRAnimate(SGRMotionFade, mark, nil);
else mark();
@@ -112,6 +155,7 @@ SGRGlyphButton *SGRPlayerLyricsGlyphIn(UIView *host) {
objc_setAssociatedObject(host, &kLyricsGlyphKey, glyph, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
if (glyph.superview != host) [host addSubview:glyph];
+ if (SGRPlayerSpotifyIcons()) SGRPlayerEncoreGlyphIn(glyph, @"lyrics");
sg_lyricsGlyph = glyph;
return glyph;
}
@@ -189,6 +233,7 @@ static void takeConnectImage(UIImageView *drawn) {
// tells the stand-in; the clear image set back in reports too, and stops there. Each pass looks too, at the cost of a
// compare, for a view the image cannot be watched on.
static void standInForConnect(UIImageView *drawn) {
+ if (SGRPlayerSpotifyIcons()) return;
BOOL made = objc_getAssociatedObject(drawn, &kStandInKey) != nil;
if (!standIn(drawn, kConnectSymbol)) return;
takeConnectImage(drawn);
@@ -208,6 +253,7 @@ static void tintQueueStandIn(SPTEncoreIconView *icon) {
}
static void standInForQueue(SPTEncoreIconView *icon) {
+ if (SGRPlayerSpotifyIcons()) return;
if (![icon isKindOfClass:%c(SPTEncoreIconView)]) return;
BOOL made = objc_getAssociatedObject(icon, &kStandInKey) != nil;
if (!standIn(icon, kQueueSymbol) || made) return;
diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.m
index 1362ce6b..955d28aa 100644
--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m
+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m
@@ -361,15 +361,17 @@ UIViewController *SGRPlayerSettingsPage(NSArray *more) {
SGNotedSection(nil, fluid, @"Brightness above 100% can make white text harder to read. A paused song holds the "
@"background still. Animated and Visualizer use these where they show Fluid."),
SGNotedSection(@"Controls", @[SGSwitchRow(@"Volume", nil, SGRKeyPlayerVolume),
- SGOptionRow(@"Follow the cover", nil, SGRKeyPlayerFollowsCover)],
+ SGOptionRow(@"Follow the cover", nil, SGRKeyPlayerFollowsCover),
+ SGOptionRow(@"Spotify's icons", @"Lyrics, device, queue and the AI DJ's button", SGRKeyPlayerSpotifyIcons)],
@"Volume puts a slider under the controls for this iPhone, or the speaker's while Spotify plays on another device. "
- @"Follow the cover paints the like, shuffle, repeat, device and queue buttons, and the mini player's device and like, in the color of the song playing."),
+ @"Follow the cover paints the like, shuffle, repeat, device and queue buttons, and the mini player's device and like, in the color of the song playing. "
+ @"Spotify's icons keeps Spotify's own glyphs in the row under the controls instead of the Music app's."),
SGNotedSection(@"Mini player", SGRNowPlayingBarRows(),
@"Apple Music style moves the now playing bar in between two tabs as you scroll down."), nil];
[sections addObjectsFromArray:more];
// Fluid, Animated and Visualizer share the field (PlayerMotion.x reads the choice on every track, PlayerVisualiser.m
// on the field's layout); Still and Colors are a field of another kind, made once a launch (PlayerField.x).
- NSString *footer = @"Fluid, Animated and Visualizer change with the next song. Still, Colors and Hide on the player apply after you restart Spotify.";
+ NSString *footer = @"Fluid, Animated and Visualizer change with the next song. Still, Colors, Hide on the player and Spotify's icons apply after you restart Spotify.";
SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:footer];
weakPage = page;
page.showcase = showcase;