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: the download button shows waiting, progress and downloaded, and shuffle is white when off (#65)

Vojtěch Škopekf8d0e433b39a
diff --git a/harness/album/README.md b/harness/album/README.md
index f7fb77c5..7d63b9ca 100644
--- a/harness/album/README.md
+++ b/harness/album/README.md
@@ -45,3 +45,10 @@ The log says what the redesign answered with.
What it does not cover: the real element framework's autolayout and the heights it measures, the page
scrolling (Spotify fades the header out by alpha as it goes, which the mock does not), and the flags
`AlbumField.x` forces.
+
+`download` on the launch line plays the download button's states instead of the header's (issue #65), from
+`../download-mock.h`: Spotify's button drawn by Lottie with no image view, its state in its accessibility
+identifier and in a mock of the Encore object behind it (`currentState`, `progress`), and shuffle's "on" dot.
+None, waiting, downloading (held at 50%), downloaded, shuffle on, removed with shuffle off, error, each held a
+few seconds and announced with a `[harness] state:` line to take a screenshot on. Nothing in it lays anything
+out, as on the phone.
diff --git a/harness/album/build.sh b/harness/album/build.sh
index 31de3bdf..30caacff 100755
--- a/harness/album/build.sh
+++ b/harness/album/build.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
-SRC=/Users/vojta/Documents/quick/custom_spotify/custom_spotify/tweak/Sources
+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/AlbumHarness.app"
@@ -19,7 +19,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
- "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
+ "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \
-o "$OUT/AlbumHarness.app/AlbumHarness"
diff --git a/harness/album/main.m b/harness/album/main.m
index b09fcd64..797d6f76 100644
--- a/harness/album/main.m
+++ b/harness/album/main.m
@@ -1,6 +1,8 @@
// A mock of Spotify's album page under its own class names and accessibility identifiers, built from
// trees/clean/album/03.txt, so Redesigned/Album can be laid out and looked at on the Mac.
#import <UIKit/UIKit.h>
+#import <objc/runtime.h>
+#import "../download-mock.h"
#pragma mark - Spotify's classes, by name
@@ -99,6 +101,11 @@ static UIImage *playGlyph(void) {
// button inside it at the same size, and a glyph in the button.
static UIView *actionButton(UIView *row, CGRect frame, NSString *identifier, NSString *symbol, NSString *a11y) {
UIView *element = box(row, UIView.class, frame, nil);
+ // Drawn by Lottie, its state in its identifier and in the Encore object behind it (issue #65).
+ if ([identifier hasPrefix:@"DownloadButton.Granular."]) {
+ mockDownloadButton(element);
+ return element;
+ }
UIView *button = box(element, MockEncoreButton.class, element.bounds, identifier);
button.accessibilityLabel = a11y;
UIImageView *glyph = [[UIImageView alloc] initWithFrame:CGRectInset(button.bounds, 12, 12)];
@@ -255,8 +262,11 @@ static NSString *trailingLabel(UIView *root) {
@[@"Components.UI.ContextMenuButton-3OxfaVgvTxUTy7276t7SPU", @"ellipsis", @"More options", @158, @0, @48, @48]];
// `late` on the launch line: add is not in the row yet, the way an album opened for the first time has it.
BOOL late = [NSProcessInfo.processInfo.arguments containsObject:@"late"];
+ // `download`: an album without add (the row's download is what Play's right shows then), playing the
+ // download button's states (download-mock.h).
+ BOOL downloads = [NSProcessInfo.processInfo.arguments containsObject:@"download"];
for (NSArray *action in actions) {
- if (late && [action[0] isEqualToString:@"Components.UI.AddToButton"]) continue;
+ if ((late || downloads) && [action[0] isEqualToString:@"Components.UI.AddToButton"]) continue;
CGRect frame = CGRectMake([action[3] doubleValue], [action[4] doubleValue], [action[5] doubleValue], [action[6] doubleValue]);
[_actionItems addObject:actionButton(_actionRow, frame, action[0], action[1], action[2])];
[_actionFrames addObject:[NSValue valueWithCGRect:frame]];
@@ -376,10 +386,7 @@ static NSString *trailingLabel(UIView *root) {
UIView *shuffleElement = box(page, UIView.class, CGRectMake(282, 62, 48, 48), nil);
UIView *shuffle = box(shuffleElement, MockEncoreButton.class, shuffleElement.bounds, @"Components.UI.ShuffleButton");
shuffle.accessibilityLabel = @"Shuffle tracks";
- UIImageView *shuffleGlyph = [[UIImageView alloc] initWithFrame:CGRectInset(shuffle.bounds, 12, 12)];
- shuffleGlyph.image = [UIImage systemImageNamed:@"shuffle"];
- shuffleGlyph.tintColor = UIColor.whiteColor;
- [shuffle addSubview:shuffleGlyph];
+ mockShuffleGlyph(shuffle);
UIView *playElement = box(page, UIView.class, CGRectMake(338, 94, 48, 48), nil);
UIView *playButton = box(playElement, _TtC28EncoreConsumerMobile_BaseKit14PlayButtonView.class, playElement.bounds, @"header-play-button");
@@ -393,6 +400,7 @@ static NSString *trailingLabel(UIView *root) {
[condensed addSubview:disc];
[self.window makeKeyAndVisible];
+ if (downloads) downloadScript();
// In `late`, add arrives at 2.5 s, after every pass of the header's and the metadata's re-reads: an arranged
// subview of the row, which lays out the row and nothing above it.
diff --git a/harness/artist/build.sh b/harness/artist/build.sh
index 1f5e20c4..596cafa3 100755
--- a/harness/artist/build.sh
+++ b/harness/artist/build.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
-SRC=/Users/vojta/Documents/quick/custom_spotify/custom_spotify/tweak/Sources
+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/ArtistHarness.app"
@@ -19,7 +19,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
- "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
+ "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \
-o "$OUT/ArtistHarness.app/ArtistHarness"
diff --git a/harness/download-mock.h b/harness/download-mock.h
new file mode 100644
index 00000000..33b0ee5d
--- /dev/null
+++ b/harness/download-mock.h
@@ -0,0 +1,130 @@
+// Spotify's download button and shuffle's "on" dot as the playlist and album harnesses mock them (issue #65).
+//
+// The download button is a UIButton drawn by Lottie -- no image view to copy -- whose accessibility
+// identifier names its state (`DownloadButton.Granular.<None|Waiting|Downloading|Downloaded|Error>`, all five
+// strings in the 9.1.78 binary), and whose action target is Encore's GranularDownloadButton, keeping
+// `currentState` (a one byte enum: none, waiting, downloading, downloadingEndless, downloaded, error) and
+// `progress` (an optional 8 byte number: the value, then a byte that is 1 when there is none) as stored
+// properties the runtime lists by name. The mock has the same names and the same layout.
+//
+// Shuffle marks "on" with a 4pt round view under its glyph that it hides while off (trees/continuous/1.txt),
+// and draws its glyph grey while off, green while on.
+//
+// `download` on the launch line runs downloadScript(): none, waiting, downloading 0 to 100%, downloaded,
+// shuffle on, removed and shuffle off, error -- each held a few seconds and logged, for screenshots.
+#import <UIKit/UIKit.h>
+
+typedef struct {
+ double value;
+ uint8_t none;
+} MockOptionalDouble;
+
+@interface _TtCOOOE32EncoreConsumerMobile_ElementsKitO19LegacyUI_ECMCoreKit10Components22GranularDownloadButton2UI7Private22GranularDownloadButton : NSObject {
+@public
+ __unsafe_unretained UIView *uiView;
+ __unsafe_unretained UIButton *uiButton;
+ uint8_t currentState;
+ MockOptionalDouble progress;
+ BOOL isEnabled;
+}
+- (void)performAction;
+@end
+
+@implementation _TtCOOOE32EncoreConsumerMobile_ElementsKitO19LegacyUI_ECMCoreKit10Components22GranularDownloadButton2UI7Private22GranularDownloadButton
+- (void)performAction {
+ NSLog(@"[harness] Spotify's download button fired (state %d)", currentState);
+}
+@end
+
+typedef _TtCOOOE32EncoreConsumerMobile_ElementsKitO19LegacyUI_ECMCoreKit10Components22GranularDownloadButton2UI7Private22GranularDownloadButton MockDownloadOwner;
+
+// Lottie's view, which draws the glyph without an image view.
+@interface MockLottieView : UIView @end
+@implementation MockLottieView @end
+
+static MockDownloadOwner *sgh_downloadOwner;
+static UIButton *sgh_downloadButton;
+static UIView *sgh_shuffleDot;
+static UIImageView *sgh_shuffleGlyph;
+
+static void setDownload(uint8_t state, double progress) {
+ NSArray<NSString *> *names = @[@"None", @"Waiting", @"Downloading", @"Downloading", @"Downloaded", @"Error"];
+ MockDownloadOwner *owner = sgh_downloadOwner;
+ owner->currentState = state;
+ owner->progress.value = progress < 0 ? 0 : progress;
+ owner->progress.none = progress < 0;
+ sgh_downloadButton.accessibilityIdentifier = [@"DownloadButton.Granular." stringByAppendingString:names[state]];
+ sgh_downloadButton.accessibilityLabel = state == 4 ? @"Remove download" : @"Download";
+}
+
+// The download button as Spotify builds it, inside `host` (48x48).
+static UIButton *mockDownloadButton(UIView *host) {
+ UIButton *button = [[UIButton alloc] initWithFrame:host.bounds];
+ button.accessibilityIdentifier = @"DownloadButton.Granular.None";
+ button.accessibilityLabel = @"Download";
+ [host addSubview:button];
+ UIView *micro = [[UIView alloc] initWithFrame:CGRectMake(12, 12, 24, 24)];
+ [micro addSubview:[[MockLottieView alloc] initWithFrame:micro.bounds]];
+ [button addSubview:micro];
+ MockDownloadOwner *owner = [MockDownloadOwner new];
+ owner->uiButton = button;
+ owner->uiView = button;
+ owner->progress.none = 1;
+ [button addTarget:owner action:@selector(performAction) forControlEvents:UIControlEventTouchUpInside];
+ // Held by the button, as Encore's element holds it.
+ static char kOwnerKey;
+ objc_setAssociatedObject(button, &kOwnerKey, owner, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ sgh_downloadOwner = owner;
+ sgh_downloadButton = button;
+ return button;
+}
+
+static UIImage *shuffleImage(BOOL on) {
+ UIImage *symbol = [UIImage systemImageNamed:@"shuffle"];
+ UIColor *color = on ? [UIColor colorWithRed:0.12 green:0.84 blue:0.38 alpha:1] : [UIColor colorWithWhite:0.70 alpha:1];
+ return [[symbol imageWithTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
+}
+
+// Shuffle's glyph and dot as Spotify draws them, inside `button` (48x48), off.
+static void mockShuffleGlyph(UIView *button) {
+ UIImageView *glyph = [[UIImageView alloc] initWithFrame:CGRectInset(button.bounds, 12, 12)];
+ glyph.image = shuffleImage(NO);
+ [button addSubview:glyph];
+ UIView *dot = [[UIView alloc] initWithFrame:CGRectMake(22, 38, 4, 4)];
+ dot.backgroundColor = [UIColor colorWithRed:0.12 green:0.84 blue:0.38 alpha:1];
+ dot.layer.cornerRadius = 2;
+ dot.hidden = YES;
+ [button addSubview:dot];
+ sgh_shuffleGlyph = glyph;
+ sgh_shuffleDot = dot;
+}
+
+static void setShuffle(BOOL on) {
+ // As Spotify does it: the dot first, then the glyph (which is what the redesign hears).
+ sgh_shuffleDot.hidden = !on;
+ sgh_shuffleGlyph.image = shuffleImage(on);
+}
+
+static void at(NSTimeInterval seconds, void (^block)(void)) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
+}
+
+// Nothing is laid out by any of it, as on the phone: the redesign has to hear it by itself. Each state is
+// held for a few seconds and announced with a "[harness] state:" line, which is what screenshots wait for.
+static void downloadScript(void) {
+ at(1, ^{ NSLog(@"[harness] state: none"); });
+ at(6, ^{ setDownload(1, -1); NSLog(@"[harness] state: waiting"); });
+ for (int i = 0; i <= 12; i++) {
+ // To half way, a pause there, then the rest.
+ NSTimeInterval when = 12 + i * 0.4 + (i > 6 ? 6 : 0);
+ at(when, ^{
+ setDownload(2, i / 12.0);
+ if (i == 6) NSLog(@"[harness] state: downloading 50%%");
+ });
+ }
+ at(23.5, ^{ setDownload(4, -1); NSLog(@"[harness] state: downloaded"); });
+ at(30, ^{ setShuffle(YES); NSLog(@"[harness] state: shuffle on"); });
+ at(36, ^{ setDownload(0, -1); setShuffle(NO); NSLog(@"[harness] state: removed, shuffle off"); });
+ at(42, ^{ setDownload(5, -1); NSLog(@"[harness] state: error"); });
+ at(48, ^{ NSLog(@"[harness] state: end"); });
+}
diff --git a/harness/library/build.sh b/harness/library/build.sh
index dcd1e3a8..a567b4bc 100755
--- a/harness/library/build.sh
+++ b/harness/library/build.sh
@@ -20,7 +20,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
- "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
+ "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \
-o "$OUT/LibraryHarness.app/LibraryHarness"
diff --git a/harness/playlist/README.md b/harness/playlist/README.md
index d5a5e7b0..fe691854 100644
--- a/harness/playlist/README.md
+++ b/harness/playlist/README.md
@@ -42,3 +42,10 @@ it — which is what used to conceal the picture for good and leave the hero bla
`liked` on the launch line (`xcrun simctl launch booted com.vojta.playlistharness liked`) builds Liked Songs
instead, from `trees/continuous/1.txt` (2026-09-18): no cover, a 238pt header, the count in a stack of its own,
the play button 80x48, and `LiquidGlass.gradientContainer`, which it fades in at 3 s as a scroll does.
+
+`download` on the launch line plays the download button's states instead of the header's (issue #65), from
+`../download-mock.h`: Spotify's button drawn by Lottie with no image view, its state in its accessibility
+identifier and in a mock of the Encore object behind it (`currentState`, `progress`), and shuffle's "on" dot.
+None, waiting, downloading (held at 50%), downloaded, shuffle on, removed with shuffle off, error, each held a
+few seconds and announced with a `[harness] state:` line to take a screenshot on. Nothing in it lays anything
+out, as on the phone.
diff --git a/harness/playlist/build.sh b/harness/playlist/build.sh
index 845697ca..eb90ec30 100755
--- a/harness/playlist/build.sh
+++ b/harness/playlist/build.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
-SRC=/Users/vojta/Documents/quick/custom_spotify/custom_spotify/tweak/Sources
+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/PlaylistHarness.app"
@@ -19,7 +19,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
- "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
+ "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \
-o "$OUT/PlaylistHarness.app/PlaylistHarness"
diff --git a/harness/playlist/main.m b/harness/playlist/main.m
index bccf04f1..20d27965 100644
--- a/harness/playlist/main.m
+++ b/harness/playlist/main.m
@@ -1,6 +1,8 @@
// A mock of Spotify's playlist page under its own class names and accessibility identifiers, built from
// trees/clean/playlist/01.txt, so Redesigned/Playlist can be laid out and looked at on the Mac.
#import <UIKit/UIKit.h>
+#import <objc/runtime.h>
+#import "../download-mock.h"
#pragma mark - Spotify's classes, by name
@@ -611,7 +613,9 @@ static void buildLikedSongs(UIViewController *page, CGFloat W) {
} else {
actionButton(actions, CGRectMake(58, 0, 48, 48), @"Components.UI.AddToButton", @"Like");
}
- actionButton(actions, CGRectMake(106, 0, 48, 48), @"DownloadButton.Granular.None", @"Download");
+ // Drawn by Lottie, its state in its identifier and in the Encore object behind it (issue #65).
+ UIView *downloadAction = box(actions, UIView.class, CGRectMake(106, 0, 48, 48), nil);
+ mockDownloadButton(box(downloadAction, UIView.class, downloadAction.bounds, nil));
actionButton(actions, CGRectMake(154, 2, 44, 44), @"Components.UI.ContextMenuButton", @"More options");
UIView *mixShuffle = box(container, UIView.class, CGRectMake(container.bounds.size.width - 124, 0, 124, 48), nil);
@@ -621,10 +625,7 @@ static void buildLikedSongs(UIViewController *page, CGFloat W) {
UIView *shuffleElement = box(shuffleView, UIView.class, shuffleView.bounds, nil);
UIView *shuffle = box(shuffleElement, UIButton.class, shuffleElement.bounds, @"Components.UI.ShuffleButton");
shuffle.accessibilityLabel = @"Shuffle tracks";
- UIImageView *shuffleGlyph = [[UIImageView alloc] initWithFrame:CGRectInset(shuffle.bounds, 12, 12)];
- shuffleGlyph.image = [UIImage systemImageNamed:@"shuffle"];
- shuffleGlyph.tintColor = UIColor.whiteColor;
- [shuffle addSubview:shuffleGlyph];
+ mockShuffleGlyph(shuffle);
// The find-on-page toolbar the header conceals, whose Sort button is what the ⋯ sheet fires: one
// identifier, in the header rather than in a cell the list reuses (trees/continuous/1.txt:1000).
@@ -698,6 +699,13 @@ static void buildLikedSongs(UIViewController *page, CGFloat W) {
NSStringFromCGRect(hero.frame), NSStringFromCGRect([wash convertRect:hero.frame toView:nil]),
[picture isKindOfClass:UIImageView.class] && picture.image ? @"drawn" : @"EMPTY");
};
+ // `download` plays the download button's states instead of the header's (download-mock.h), with the page
+ // left at rest and no sheet over it, for screenshots.
+ BOOL downloads = [NSProcessInfo.processInfo.arguments containsObject:@"download"];
+ if (downloads) {
+ downloadScript();
+ return YES;
+ }
for (NSUInteger i = 0; i < 3; i++) {
NSString *state = @[@"rest", @"collapsed", @"pulled"][i];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((4 + i * 4) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
diff --git a/tweak/Sources/Redesigned/Kit/SGRActionRow.h b/tweak/Sources/Redesigned/Kit/SGRActionRow.h
index 0dbbb504..ca068583 100644
--- a/tweak/Sources/Redesigned/Kit/SGRActionRow.h
+++ b/tweak/Sources/Redesigned/Kit/SGRActionRow.h
@@ -39,6 +39,11 @@
// colour while it is on). Set it for a glyph whose colour is only the weight Spotify gave the control it
// sat in: Encore bakes the colour into the image it draws, so this re-renders the copy as a template.
@property (nonatomic, copy) UIColor *glyphColor;
+// The colour the glyph takes while Spotify's button is on, and glyphColor while it is off, for a button that
+// says it is on with the small dot Encore puts under its glyph (shuffle: trees/continuous/1.txt, a 4pt round
+// view, hidden while off). Spotify's own off grey read as a disabled button beside the white download
+// (issue #65). A button with no such dot keeps Spotify's colours. nil, the default, reads no dot.
+@property (nonatomic, copy) UIColor *onGlyphColor;
// The word on Spotify's button instead of a glyph, in a glass capsule as wide as the word asks for: for a
// text button such as the artist's Follow, whose word is its state ("Follow", "Following") in the app's
// language. Until Spotify's button has a word, the fallback glyph is drawn in the round shape instead. Set
@@ -48,6 +53,11 @@
- (CGFloat)sgr_width;
// Takes the glyph, its colour and the label from `source`, and follows the glyph as Spotify swaps it
// (shuffle turning on). Cheap to call again on every pass.
+//
+// Spotify's download button (SGRDownload.h) is drawn by Lottie, with nothing to copy: for it the button
+// draws the state Spotify reports instead -- the arrow, a ring filling up, the downloaded glyph -- and reads
+// it again while it is on screen, twice a second while a download runs, since nothing Spotify does then
+// lays out anything the page hears.
- (void)feedFrom:(UIView *)source;
@end
diff --git a/tweak/Sources/Redesigned/Kit/SGRActionRow.m b/tweak/Sources/Redesigned/Kit/SGRActionRow.m
index bb7293ef..4a90ac16 100644
--- a/tweak/Sources/Redesigned/Kit/SGRActionRow.m
+++ b/tweak/Sources/Redesigned/Kit/SGRActionRow.m
@@ -10,6 +10,7 @@
#import "SGRRestyle.h"
#import "SGRTokens.h"
#import "SGRAccent.h"
+#import "SGRDownload.h"
// The capsule: the glyph is Spotify's own 48pt canvas with the triangle small in the middle of it, so the
// lead is short and the gap to the word comes out of the canvas itself.
@@ -167,6 +168,24 @@ static UILabel *labelIn(UIView *button) {
return found;
}
+// Whether a button that marks "on" with a small dot under its glyph (Encore's shuffle, a 4pt round view it
+// hides while off) is on. `found` says whether the button has such a dot at all.
+static BOOL indicatorOn(UIView *button, BOOL *found) {
+ __block UIView *dot = nil;
+ SGForEachView(button, ^(UIView *v) {
+ if (dot || v == button || [v isKindOfClass:UIImageView.class] || [v isKindOfClass:UILabel.class]) return;
+ CGSize size = v.bounds.size;
+ if (size.width < 2 || size.width > 8 || size.height < 2 || size.height > 8) return;
+ CGColorRef paint = v.layer.backgroundColor;
+ if (paint && CGColorGetAlpha(paint) > 0.5) dot = v;
+ });
+ if (found) *found = dot != nil;
+ for (UIView *up = dot; up && up != button; up = up.superview) {
+ if (up.hidden || up.alpha <= 0.01) return NO;
+ }
+ return dot != nil;
+}
+
// The text a button shows: the first label under it with something in it.
static NSString *labelTextIn(UIView *button) {
__block NSString *text = nil;
@@ -186,6 +205,9 @@ static NSString *labelTextIn(UIView *button) {
// Spotify's own image, as it was taken: what the copy is compared against, since a copy re-rendered as
// a template is no longer the same object.
UIImage *_takenGlyph;
+ // Standing in for Spotify's download button: its state drawn, and read again while on screen.
+ SGRDownloadGlyph *_download;
+ NSTimer *_downloadTimer;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -230,6 +252,75 @@ static NSString *labelTextIn(UIView *button) {
((UIView *)objc_getAssociatedObject(self, &kWordGlassKey)).hidden = YES;
_glyph.frame = CGRectMake(round((bounds.size.width - kMirrorGlyph) / 2), round((bounds.size.height - kMirrorGlyph) / 2),
kMirrorGlyph, kMirrorGlyph);
+ _download.frame = _glyph.frame;
+}
+
+- (void)didMoveToWindow {
+ [super didMoveToWindow];
+ if (!_download) return;
+ // Read again on the way in -- the download may have moved on while the page was away -- and not at all
+ // while out of the window.
+ if (self.window && self.source) [self feedFrom:self.source];
+ else [self sgr_followDownload:0];
+}
+
+- (void)dealloc {
+ [_downloadTimer invalidate];
+}
+
+// Shows Spotify's download state; YES when `source` is a download button.
+- (BOOL)sgr_feedDownloadFrom:(UIView *)source {
+ SGRDownloadState state;
+ CGFloat progress;
+ if (!SGRReadDownload(source, &state, &progress)) {
+ if (_download && !_download.hidden) {
+ _download.hidden = YES;
+ _glyph.hidden = NO;
+ [self sgr_followDownload:0];
+ }
+ return NO;
+ }
+ if (!_download) {
+ _download = [[SGRDownloadGlyph alloc] initWithFrame:_glyph.frame];
+ [self addSubview:_download];
+ }
+ _download.hidden = NO;
+ _glyph.hidden = YES;
+ [_download showState:state progress:progress animated:YES];
+
+ NSString *word = source.accessibilityLabel ?: wordIn(source);
+ if (word && ![self.accessibilityLabel isEqualToString:word]) self.accessibilityLabel = word;
+ NSString *value = state == SGRDownloadDownloading && progress >= 0
+ ? [NSNumberFormatter localizedStringFromNumber:@(progress) numberStyle:NSNumberFormatterPercentStyle] : nil;
+ if (![self.accessibilityValue ?: @"" isEqualToString:value ?: @""]) self.accessibilityValue = value;
+
+ // Spotify lays nothing out that the page hears as a download moves on, so the state is read again:
+ // twice a second while one runs, for the ring, and now and then otherwise, for one started or removed
+ // from elsewhere (the ⋯ sheet). Only while the button is on screen.
+ BOOL running = state == SGRDownloadWaiting || state == SGRDownloadDownloading;
+ [self sgr_followDownload:self.window ? (running ? 0.5 : 2) : 0];
+ return YES;
+}
+
+// Reads the download again every `interval` seconds; 0 stops.
+- (void)sgr_followDownload:(NSTimeInterval)interval {
+ if (interval <= 0) {
+ [_downloadTimer invalidate];
+ _downloadTimer = nil;
+ return;
+ }
+ if (_downloadTimer.valid && fabs(_downloadTimer.timeInterval - interval) < 0.01) return;
+ [_downloadTimer invalidate];
+ __weak SGRMirrorButton *weakSelf = self;
+ _downloadTimer = [NSTimer scheduledTimerWithTimeInterval:interval repeats:YES block:^(NSTimer *timer) {
+ SGRMirrorButton *button = weakSelf;
+ if (!button || !button.window || !button.source) {
+ [timer invalidate];
+ return;
+ }
+ [button feedFrom:button.source];
+ }];
+ _downloadTimer.tolerance = interval * 0.2;
}
// The glyph is taken as Spotify drew it, colour and all: the shuffle button turns its own glyph the accent
@@ -281,20 +372,35 @@ static NSString *labelTextIn(UIView *button) {
return;
}
+ if ([self sgr_feedDownloadFrom:source]) return;
+
UIImageView *glyph = glyphIn(source, 0);
NSString *word = source.accessibilityLabel ?: wordIn(source);
if (word && ![self.accessibilityLabel isEqualToString:word]) self.accessibilityLabel = word;
- if (glyph.image && _takenGlyph != glyph.image) {
+ // A button that says "on" with its dot is drawn in our colours, on and off. One expected to have a dot
+ // and found without keeps Spotify's colours, which are then all that tells on from off.
+ BOOL hasDot = NO;
+ BOOL on = self.onGlyphColor && indicatorOn(source, &hasDot);
+ UIColor *ownColor = !self.onGlyphColor ? self.glyphColor
+ : hasDot ? (on ? self.onGlyphColor : self.glyphColor ?: SGRPrimary()) : nil;
+ if (glyph.image && (_takenGlyph != glyph.image || (ownColor != nil) != (_glyph.image.renderingMode == UIImageRenderingModeAlwaysTemplate))) {
_takenGlyph = glyph.image;
- _glyph.image = self.glyphColor ? [glyph.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
- : glyph.image;
+ _glyph.image = ownColor ? [glyph.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] : glyph.image;
}
- UIColor *tint = self.glyphColor ?: glyph.tintColor;
- if (tint && ![_glyph.tintColor isEqual:tint]) _glyph.tintColor = tint;
if (!glyph && self.fallbackGlyph && _glyph.image != self.fallbackGlyph) {
_takenGlyph = nil;
_glyph.image = self.fallbackGlyph;
- _glyph.tintColor = self.glyphColor ?: SGRPrimary();
+ }
+ UIColor *tint = ownColor ?: (glyph ? glyph.tintColor : SGRPrimary());
+ if (tint && ![_glyph.tintColor isEqual:tint]) {
+ // Turning on or off is a moment of its own: the colour fades across rather than jumping.
+ BOOL fade = self.window && _glyph.tintColor && hasDot;
+ if (fade) {
+ [UIView transitionWithView:_glyph duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve
+ animations:^{ self->_glyph.tintColor = tint; } completion:nil];
+ } else {
+ _glyph.tintColor = tint;
+ }
}
// As the capsule does: watched per glyph view, so a reused one reports where it is now.
@@ -320,8 +426,8 @@ static NSString *labelTextIn(UIView *button) {
SGRActivate(self.source);
// The word is watched where Spotify writes it, but a button that rebuilds its content on the state it
// just took writes the new word into a label the watch has never seen. So a tap, and only a tap, asks
- // the button again a moment later, which also moves the watch onto whatever label it ended up with.
- if (!self.showsWord) return;
+ // the button again a moment later, which also moves the watch onto whatever label it ended up with. The
+ // same goes for shuffle's dot and a download's state, which change with no image or word to watch.
__weak SGRMirrorButton *weakSelf = self;
for (NSNumber *delay in @[@0.3, @1.0]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
diff --git a/tweak/Sources/Redesigned/Kit/SGRDownload.h b/tweak/Sources/Redesigned/Kit/SGRDownload.h
new file mode 100644
index 00000000..e621a257
--- /dev/null
+++ b/tweak/Sources/Redesigned/Kit/SGRDownload.h
@@ -0,0 +1,35 @@
+// What Spotify's download button says -- not downloaded, waiting, downloading and how far, downloaded, failed
+// -- and the glyph the redesign draws for it, the Music app's: an arrow, a ring filling up with a stop square
+// in it, and a filled arrow in a circle once everything is on the phone (issue #65).
+//
+// Spotify draws that button with Lottie, so there is no image to copy the way the action row copies the
+// other glyphs. What it does have is a state in words: the button's accessibility identifier is
+// `DownloadButton.Granular.<None|Waiting|Downloading|Downloaded|Error>` (every one of the five is a string
+// in the 9.1.78 binary), and the Encore object that owns the button -- the button's own action target --
+// keeps `currentState` and `progress` in stored properties the runtime lists by name (Swift field metadata:
+// GranularDownloadButton { currentState: GranularDownloadButtonState, progress: Optional<8 bytes> }, the
+// state being none, waiting, downloading, downloadingEndless, downloaded, error in that order).
+//
+// Threading: main thread only.
+#import <UIKit/UIKit.h>
+
+typedef NS_ENUM(NSInteger, SGRDownloadState) {
+ SGRDownloadNone,
+ SGRDownloadWaiting, // queued, or downloading with no progress to show: the ring turns
+ SGRDownloadDownloading,
+ SGRDownloadDownloaded,
+ SGRDownloadError,
+};
+
+// YES when `source`, or something under it, is Spotify's download button, with what it says: `progress`
+// is 0...1 while downloading, -1 when Spotify has none to give (an endless download, or not readable).
+BOOL SGRReadDownload(UIView *source, SGRDownloadState *state, CGFloat *progress);
+
+// The glyph, 24pt square, drawn in the middle of a round action row button. A change of state is animated
+// (symbol replaced in place, or the old shape shrinking away as the new one grows in), so the moment the
+// download starts or ends reads as a moment; progress eases along between the reads.
+@interface SGRDownloadGlyph : UIView
+@property (nonatomic, readonly) SGRDownloadState state;
+@property (nonatomic, readonly) BOOL showsState; // NO until the first -showState:
+- (void)showState:(SGRDownloadState)state progress:(CGFloat)progress animated:(BOOL)animated;
+@end
diff --git a/tweak/Sources/Redesigned/Kit/SGRDownload.m b/tweak/Sources/Redesigned/Kit/SGRDownload.m
new file mode 100644
index 00000000..2991901f
--- /dev/null
+++ b/tweak/Sources/Redesigned/Kit/SGRDownload.m
@@ -0,0 +1,347 @@
+// Reading Spotify's download button, and the glyph drawn for it.
+#import <objc/runtime.h>
+#import "Core/SGCore.h"
+#import "SGRDownload.h"
+#import "SGRTokens.h"
+
+#pragma mark - reading Spotify's button
+
+static NSString *const kIdentifierPrefix = @"DownloadButton.Granular.";
+
+static UIView *downloadButtonIn(UIView *source) {
+ __block UIView *found = nil;
+ SGForEachView(source, ^(UIView *v) {
+ if (!found && [v.accessibilityIdentifier hasPrefix:kIdentifierPrefix]) found = v;
+ });
+ return found;
+}
+
+// The Encore object behind the button: the target of the button's own action (-performAction).
+static id ownerOf(UIView *button) {
+ if (![button isKindOfClass:UIControl.class]) return nil;
+ for (id target in ((UIControl *)button).allTargets) {
+ if ([NSStringFromClass(object_getClass(target)) containsString:@"GranularDownloadButton"]) return target;
+ }
+ return nil;
+}
+
+// `length` bytes of the stored property `name`, NULL when the class has no such property or it would reach
+// past the end of the instance.
+static const uint8_t *propertyBytes(id object, const char *name, size_t length) {
+ if (!object) return NULL;
+ Class cls = object_getClass(object);
+ Ivar ivar = class_getInstanceVariable(cls, name);
+ if (!ivar) return NULL;
+ ptrdiff_t offset = ivar_getOffset(ivar);
+ if (offset <= 0 || (size_t)offset + length > class_getInstanceSize(cls)) return NULL;
+ return (const uint8_t *)(__bridge void *)object + offset;
+}
+
+static BOOL stateFromIdentifier(NSString *identifier, SGRDownloadState *state) {
+ NSDictionary<NSString *, NSNumber *> *states = @{
+ @"None": @(SGRDownloadNone), @"Waiting": @(SGRDownloadWaiting), @"Downloading": @(SGRDownloadDownloading),
+ @"Downloaded": @(SGRDownloadDownloaded), @"Error": @(SGRDownloadError),
+ };
+ NSNumber *found = states[[identifier substringFromIndex:kIdentifierPrefix.length]];
+ if (!found) return NO;
+ *state = found.integerValue;
+ return YES;
+}
+
+BOOL SGRReadDownload(UIView *source, SGRDownloadState *state, CGFloat *progress) {
+ UIView *button = source ? downloadButtonIn(source) : nil;
+ if (!button) return NO;
+ SGRDownloadState said = SGRDownloadNone;
+ BOOL named = stateFromIdentifier(button.accessibilityIdentifier, &said);
+
+ // What the button draws from. Its state is a Swift enum without payloads, one byte, its cases numbered
+ // in the order they are declared; its progress an optional 8 byte number, the value then a byte that is
+ // 1 when there is none. The identifier says the same state in words, and is what counts when the model
+ // cannot be read.
+ id owner = ownerOf(button);
+ const uint8_t *current = propertyBytes(owner, "currentState", 1);
+ const uint8_t *stored = propertyBytes(owner, "progress", 9);
+ BOOL modelled = current && *current <= 5;
+ static const SGRDownloadState fromModel[] = {
+ SGRDownloadNone, SGRDownloadWaiting, SGRDownloadDownloading, SGRDownloadWaiting, SGRDownloadDownloaded, SGRDownloadError,
+ };
+ SGRDownloadState modelState = modelled ? fromModel[*current] : SGRDownloadNone;
+ SGRDownloadState result = modelled ? modelState : said;
+ if (!modelled && !named) return NO;
+
+ CGFloat value = -1;
+ if (result == SGRDownloadDownloading && stored && stored[8] == 0) {
+ double raw;
+ memcpy(&raw, stored, sizeof raw);
+ // A fraction, or a percentage should it ever be one.
+ if (isfinite(raw) && raw > 1.0001 && raw <= 100) raw /= 100;
+ if (isfinite(raw) && raw >= 0 && raw <= 1.0001) value = MIN(1, raw);
+ }
+ // Downloading with nothing to show how far is the ring turning, as while waiting.
+ if (result == SGRDownloadDownloading && value < 0) result = SGRDownloadWaiting;
+
+ // Said once for each combination read, so the first device run shows which of the two signals moved.
+ static NSMutableSet<NSString *> *logged;
+ if (!logged) logged = [NSMutableSet set];
+ NSString *mark = [NSString stringWithFormat:@"%@ %d %d", button.accessibilityIdentifier, current ? *current : -1, stored != NULL];
+ if (![logged containsObject:mark]) {
+ [logged addObject:mark];
+ SGLog(@"redesign kit: download %@, model %@ state %d progress %@, label \"%@\" value \"%@\"",
+ button.accessibilityIdentifier, owner ? NSStringFromClass(object_getClass(owner)) : @"missing",
+ current ? *current : -1, stored ? (stored[8] == 0 ? @"set" : @"none") : @"unreadable",
+ button.accessibilityLabel, button.accessibilityValue);
+ }
+ if (modelled && named && modelState != said && !(modelState == SGRDownloadWaiting && said == SGRDownloadDownloading)) {
+ static NSMutableSet<NSString *> *disagreed;
+ if (!disagreed) disagreed = [NSMutableSet set];
+ if (![disagreed containsObject:mark]) {
+ [disagreed addObject:mark];
+ SGLog(@"redesign kit: download model says %d where the identifier says %@, the model wins", *current,
+ button.accessibilityIdentifier);
+ }
+ }
+ if (state) *state = result;
+ if (progress) *progress = value;
+ return YES;
+}
+
+#pragma mark - the glyph
+
+// The ring inside the 24pt canvas, the width of the circle of a filled SF symbol at kSymbolSize.
+static const CGFloat kCanvas = 24, kRingRadius = 9.75, kRingWidth = 2, kStopSide = 7, kSymbolSize = 17;
+// How long the ring takes to catch up with a new reading: the time between two reads, so it never stops.
+static const NSTimeInterval kProgressEase = 0.5;
+// The ring closing before the downloaded glyph takes its place.
+static const NSTimeInterval kRingCloses = 0.22;
+
+static BOOL isRing(SGRDownloadState state) {
+ return state == SGRDownloadWaiting || state == SGRDownloadDownloading;
+}
+
+static UIImage *symbolFor(SGRDownloadState state) {
+ NSString *name = state == SGRDownloadDownloaded ? @"arrow.down.circle.fill"
+ : state == SGRDownloadError ? @"exclamationmark.circle" : @"arrow.down";
+ UIImageSymbolConfiguration *config = [UIImageSymbolConfiguration configurationWithPointSize:kSymbolSize
+ weight:UIImageSymbolWeightSemibold];
+ return [[UIImage systemImageNamed:name withConfiguration:config] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
+}
+
+// Downloaded is the one state that is "on", so it takes the accent colour, as shuffle does while it is on.
+static UIColor *tintFor(SGRDownloadState state) {
+ return state == SGRDownloadDownloaded ? SGRAccent() : SGRPrimary();
+}
+
+@implementation SGRDownloadGlyph {
+ UIImageView *_symbol;
+ UIView *_ring;
+ CAShapeLayer *_track, *_arc, *_stop;
+ // Bumped on every change of state, so a swap still waiting for the ring to close knows it is stale.
+ NSUInteger _generation;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ if (!(self = [super initWithFrame:frame])) return nil;
+ self.userInteractionEnabled = NO;
+ self.isAccessibilityElement = NO;
+
+ _symbol = [UIImageView new];
+ _symbol.contentMode = UIViewContentModeCenter;
+ [self addSubview:_symbol];
+
+ _ring = [UIView new];
+ _ring.hidden = YES;
+ [self addSubview:_ring];
+ _track = [CAShapeLayer layer];
+ _arc = [CAShapeLayer layer];
+ for (CAShapeLayer *layer in @[_track, _arc]) {
+ layer.fillColor = UIColor.clearColor.CGColor;
+ layer.lineWidth = kRingWidth;
+ layer.lineCap = kCALineCapRound;
+ [_ring.layer addSublayer:layer];
+ }
+ _stop = [CAShapeLayer layer];
+ [_ring.layer addSublayer:_stop];
+ [self sgr_paint];
+ return self;
+}
+
+- (void)sgr_paint {
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ _track.strokeColor = [SGRPrimary() colorWithAlphaComponent:0.25].CGColor;
+ _arc.strokeColor = SGRAccent().CGColor;
+ _stop.fillColor = SGRAccent().CGColor;
+ [CATransaction commit];
+}
+
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ CGRect bounds = self.bounds;
+ _symbol.frame = bounds;
+ _ring.bounds = CGRectMake(0, 0, kCanvas, kCanvas);
+ _ring.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
+ CGRect canvas = CGRectMake(0, 0, kCanvas, kCanvas);
+ CGPoint middle = CGPointMake(kCanvas / 2, kCanvas / 2);
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ for (CAShapeLayer *layer in @[_track, _arc, _stop]) layer.frame = canvas;
+ // From twelve o'clock, clockwise, the way a download fills.
+ UIBezierPath *circle = [UIBezierPath bezierPathWithArcCenter:middle radius:kRingRadius startAngle:-M_PI_2
+ endAngle:3 * M_PI_2 clockwise:YES];
+ _track.path = circle.CGPath;
+ _arc.path = circle.CGPath;
+ CGRect stop = CGRectMake(middle.x - kStopSide / 2, middle.y - kStopSide / 2, kStopSide, kStopSide);
+ _stop.path = [UIBezierPath bezierPathWithRoundedRect:stop cornerRadius:1.5].CGPath;
+ [CATransaction commit];
+}
+
+- (void)traitCollectionDidChange:(UITraitCollection *)previous {
+ [super traitCollectionDidChange:previous];
+ [self sgr_paint];
+}
+
+- (void)didMoveToWindow {
+ [super didMoveToWindow];
+ // Core Animation drops a repeating animation when the layer leaves the window; the turning ring is put
+ // back on the way in.
+ if (self.window && _showsState && _state == SGRDownloadWaiting) [self sgr_setProgress:-1 animated:NO];
+}
+
+// The ring: a known fraction fills it from the top; none turns a short arc round and round.
+- (void)sgr_setProgress:(CGFloat)progress animated:(BOOL)animated {
+ BOOL turning = progress < 0;
+ [CATransaction begin];
+ if (turning) {
+ [CATransaction setDisableActions:YES];
+ _arc.strokeEnd = 0.28;
+ if (![_arc animationForKey:@"sgr.spin"]) {
+ CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
+ spin.fromValue = @0;
+ spin.toValue = @(2 * M_PI);
+ spin.duration = 1;
+ spin.repeatCount = HUGE_VALF;
+ [_arc addAnimation:spin forKey:@"sgr.spin"];
+ }
+ } else {
+ BOOL wasTurning = [_arc animationForKey:@"sgr.spin"] != nil;
+ [_arc removeAnimationForKey:@"sgr.spin"];
+ if (animated && !wasTurning) {
+ [CATransaction setAnimationDuration:kProgressEase];
+ [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
+ } else {
+ [CATransaction setDisableActions:YES];
+ }
+ _arc.strokeEnd = MAX(0, MIN(1, progress));
+ }
+ [CATransaction commit];
+}
+
+- (void)showState:(SGRDownloadState)state progress:(CGFloat)progress animated:(BOOL)animated {
+ BOOL had = _showsState;
+ SGRDownloadState old = _state;
+ BOOL ring = isRing(state), wasRing = had && isRing(old);
+ animated = animated && had && self.window != nil;
+
+ if (had && state == old) {
+ if (ring) [self sgr_setProgress:state == SGRDownloadDownloading ? progress : -1 animated:animated];
+ return;
+ }
+ _state = state;
+ _showsState = YES;
+ NSUInteger generation = ++_generation;
+
+ if (!animated) {
+ _ring.hidden = !ring;
+ _symbol.hidden = ring;
+ _ring.alpha = _symbol.alpha = 1;
+ _ring.transform = _symbol.transform = CGAffineTransformIdentity;
+ if (ring) [self sgr_setProgress:state == SGRDownloadDownloading ? progress : -1 animated:NO];
+ else {
+ _symbol.image = symbolFor(state);
+ _symbol.tintColor = tintFor(state);
+ }
+ return;
+ }
+
+ // One symbol for another (not downloaded to downloaded, say, when it happened while the page was away):
+ // the symbol replaces itself in place.
+ if (!ring && !wasRing) {
+ UIImage *image = symbolFor(state);
+ if (@available(iOS 17.0, *)) {
+ if (!SGRReduceMotion()) [_symbol setSymbolImage:image withContentTransition:[NSSymbolReplaceContentTransition replaceDownUpTransition]];
+ else _symbol.image = image;
+ } else {
+ _symbol.image = image;
+ }
+ SGRAnimate(SGRMotionFade, ^{ self->_symbol.tintColor = tintFor(state); }, nil);
+ return;
+ }
+ // Waiting to downloading and back: the ring stays, only what it shows changes.
+ if (ring && wasRing) {
+ [self sgr_setProgress:state == SGRDownloadDownloading ? progress : -1 animated:YES];
+ return;
+ }
+
+ // One shape for the other: the old one shrinks away as the new one grows in with a little bounce. A
+ // download that ends closes its ring first, so the last moment of it is seen before the arrow lands.
+ UIView *outgoing = wasRing ? _ring : _symbol, *incoming = ring ? _ring : _symbol;
+ BOOL closeRing = wasRing && state == SGRDownloadDownloaded;
+ if (closeRing) [self sgr_closeRing];
+ __weak SGRDownloadGlyph *weakSelf = self;
+ void (^swap)(void) = ^{
+ SGRDownloadGlyph *glyph = weakSelf;
+ if (!glyph || glyph->_generation != generation) return;
+ BOOL still = SGRReduceMotion();
+ CGAffineTransform small = still ? CGAffineTransformIdentity : CGAffineTransformMakeScale(0.55, 0.55);
+ if (ring) [glyph sgr_setProgress:state == SGRDownloadDownloading ? progress : -1 animated:NO];
+ else {
+ glyph->_symbol.image = symbolFor(state);
+ glyph->_symbol.tintColor = tintFor(state);
+ }
+ incoming.hidden = NO;
+ incoming.alpha = 0;
+ incoming.transform = small;
+ [UIView animateWithDuration:0.16 delay:0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState
+ animations:^{
+ outgoing.alpha = 0;
+ outgoing.transform = small;
+ } completion:^(BOOL finished) {
+ if (glyph->_generation != generation) return;
+ outgoing.hidden = YES;
+ outgoing.alpha = 1;
+ outgoing.transform = CGAffineTransformIdentity;
+ }];
+ if (still) {
+ SGRAnimate(SGRMotionFade, ^{ incoming.alpha = 1; }, nil);
+ } else {
+ [UIView animateWithDuration:0.5 delay:0.08 usingSpringWithDamping:0.58 initialSpringVelocity:0
+ options:UIViewAnimationOptionAllowUserInteraction animations:^{
+ incoming.alpha = 1;
+ incoming.transform = CGAffineTransformIdentity;
+ } completion:nil];
+ }
+ };
+ if (closeRing) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kRingCloses * NSEC_PER_SEC)), dispatch_get_main_queue(), swap);
+ } else {
+ swap();
+ }
+}
+
+// The arc runs round to the top from wherever the last reading left it.
+- (void)sgr_closeRing {
+ CGFloat from = [(CAShapeLayer *)(_arc.presentationLayer ?: _arc) strokeEnd];
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ [_arc removeAnimationForKey:@"sgr.spin"];
+ _arc.strokeEnd = 1;
+ [CATransaction commit];
+ CABasicAnimation *close = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
+ close.fromValue = @(from);
+ close.toValue = @1;
+ close.duration = kRingCloses;
+ close.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
+ [_arc addAnimation:close forKey:@"sgr.close"];
+}
+
+@end
diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
index 38e392b1..fc785337 100644
--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
@@ -52,6 +52,10 @@ static BOOL setText(UILabel *label, NSString *text) {
_shuffle = [[SGRMirrorButton alloc] initWithFrame:CGRectZero];
_shuffle.fallbackGlyph = [UIImage systemImageNamed:@"shuffle"];
+ // White like the buttons beside it while off -- Spotify's off grey read as a disabled button next to the
+ // white download (issue #65) -- and the accent while on, so its state still shows.
+ _shuffle.glyphColor = SGRPrimary();
+ _shuffle.onGlyphColor = SGRAccent();
_play = [[SGRPlayCapsule alloc] initWithFrame:CGRectZero];
_play.fillColor = UIColor.whiteColor;
_trailing = [[SGRMirrorButton alloc] initWithFrame:CGRectZero];
diff --git a/tweak/Sources/Redesigned/Kit/SGRKit.h b/tweak/Sources/Redesigned/Kit/SGRKit.h
index 4911db3b..e10f52b5 100644
--- a/tweak/Sources/Redesigned/Kit/SGRKit.h
+++ b/tweak/Sources/Redesigned/Kit/SGRKit.h
@@ -8,6 +8,7 @@
// SGRGlass.h glass inside Spotify's round controls
// SGRGlyph.h bare glyph overlays and glyph buttons
// SGRActionRow.h the Play capsule and the stand-in button of a page's action row
+// SGRDownload.h Spotify's download state, read, and the glyph drawn for it
// SGRHeaderInfo.h a page header's title, creator, length, row and description, the Music app's
// SGRRestyle.h keeping Spotify's views restyled: suppress, digits, lookups, shadows, firing
// controls, taking a list cell's paint off the field
@@ -24,6 +25,7 @@
#import "SGRGlass.h"
#import "SGRGlyph.h"
#import "SGRActionRow.h"
+#import "SGRDownload.h"
#import "SGRHeaderInfo.h"
#import "SGRRestyle.h"
#import "SGRBridges.h"