Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: switches to hide shuffle and repeat on the redesigned player (#120)
My-Name-Is-Jefff08078c23549
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 95e5c185..565ed085 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -554,7 +554,9 @@ Redesigned:Pitch follows speed in a popover from the ⋯ (SpeedPitchMenu.x), and the backgrounds it can switchto (PlayerMenu.m), and a hold on either side of thecover plays at 2x until the finger lifts (PlayerArtwork.x), an octave higher while Pitch follows- speed is on. A Free account gets it too: Spotify's Reinvented Free player mode, whose units none of+ speed is on. Hide on the player's Shuffle and Repeat (spotifyglass.redesign.player.hideShuffle,+ .hideRepeat, read at launch) take those buttons off the controls by alpha in their slots, as the+ Music app keeps them off its own (PlayerControls.x). A Free account gets it too: Spotify's Reinvented Free player mode, whose units none ofthe hooks reach, declines while the redesign runs, so the track falls to Spotify's other Free mode,built from the units the redesign styles (PlayerFree.x, read from the binary, not yet seen on a Freeaccount). Animated artwork (PlayerMotion.x)diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex 72d80544..d698a7ab 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -158,9 +158,11 @@ UIViewController *SGPlayerSettingsPage(void) {[sections addObjectsFromArray:SGNativePlayerScreenSections()];}// Switch to video is the same chip of Spotify's player under either look.- [sections addObject:SGSection(native ? nil : @"Hide on the player", @[- SGHideRow(@"Switch to video", @"The chip over the title of a song with a music video", SGKeyHideVideoSwitch),- ])];+ SGModRow *video = SGHideRow(@"Switch to video", @"The chip over the title of a song with a music video", SGKeyHideVideoSwitch);+ // The native look's Shuffle and Repeat rows are in its Hide on the player section, with their own keys.+ NSArray<SGModRow *> *hidden = native ? @[video]+ : @[SGHideRow(@"Shuffle", nil, SGRKeyPlayerHideShuffle), SGHideRow(@"Repeat", nil, SGRKeyPlayerHideRepeat), video];+ [sections addObject:SGSection(native ? nil : @"Hide on the player", hidden)];[sections addObject:SGNotedSection(@"Lossless", @[SGOptionRow(@"Lossless files", @"Your own FLACs in place of Spotify's stream", SGKeyLossless),diff --git a/tweak/Sources/Redesigned/Kit/SGRRestyle.h b/tweak/Sources/Redesigned/Kit/SGRRestyle.hindex 96aaceb7..a650e272 100644--- a/tweak/Sources/Redesigned/Kit/SGRRestyle.h+++ b/tweak/Sources/Redesigned/Kit/SGRRestyle.h@@ -13,9 +13,11 @@// Alpha 0, no touches, hidden from accessibility, and kept so: the instance becomes a runtime subclass// of its own class (the way KVO does it, `class` still answers the original) whose setAlpha: and-// setUserInteractionEnabled: hold those values. For plain UIKit views (a UIImageView, a UILabel); a-// Swift class, or an instance already observed with KVO, gets the values once instead, re-applied on-// the next call, and a log line says so once.+// setUserInteractionEnabled: hold those values. For plain UIKit views (a UIImageView, a UILabel). One of+// Spotify's Swift classes, or an instance KVO observes, keeps its alpha (only its alpha: touches and+// accessibility are set again on each call) through an override on its class that holds only the instances+// suppressed; where neither takes, the values are set once instead, re-applied+// on the next call, and a log line says so once.void SGRSuppress(UIView *view);// Digits of one width in the label, kept through Spotify's own setText:, setAttributedText: anddiff --git a/tweak/Sources/Redesigned/Kit/SGRRestyle.m b/tweak/Sources/Redesigned/Kit/SGRRestyle.mindex 29a500c6..f61f9ee3 100644--- a/tweak/Sources/Redesigned/Kit/SGRRestyle.m+++ b/tweak/Sources/Redesigned/Kit/SGRRestyle.m@@ -4,7 +4,7 @@#import "SGRRestyle.h"#import "SGRTokens.h"-static char kPlateKey, kImageObserverKey, kLayoutObserverKey;+static char kPlateKey, kImageObserverKey, kLayoutObserverKey, kSuppressedKey;#pragma mark - instance subclasses@@ -112,14 +112,21 @@ void SGRSuppress(UIView *view) {((void (*)(struct objc_super *, SEL, BOOL))objc_msgSendSuper)(&parent, @selector(setUserInteractionEnabled:), NO);});});- if (!kept) {- static NSMutableSet<NSString *> *logged;- if (!logged) logged = [NSMutableSet set];- NSString *name = NSStringFromClass(object_getClass(view));- if (![logged containsObject:name]) {- [logged addObject:name];- SGLog(@"redesign kit: %@ cannot keep being suppressed, set once per call", name);- }+ // One of Spotify's Swift classes (an Encore button, whose state render sets its alpha back to 1) keeps it+ // through an override on the class, which only holds the instances marked here. The class `class` answers,+ // so an instance KVO observes (the player's repeat button) is held too: KVO's class passes setAlpha: on to it.+ // Only a class inside the app: a plain UILabel KVO observes answers UILabel, which must never be touched.+ // An instance marked on an earlier call is held already: callers ask on every layout pass.+ BOOL onClass = objc_getAssociatedObject(view, &kSuppressedKey) != nil;+ if (!kept && !onClass) {+ BOOL spotifys = [[NSBundle bundleForClass:view.class].bundlePath hasPrefix:NSBundle.mainBundle.bundlePath];+ onClass = spotifys && overrideOnClass(view.class, @selector(setAlpha:), ^id(IMP replaced) {+ return ^(UIView *self, CGFloat alpha) {+ ((void (*)(id, SEL, CGFloat))replaced)(self, @selector(setAlpha:), objc_getAssociatedObject(self, &kSuppressedKey) ? 0 : alpha);+ };+ });+ if (onClass) objc_setAssociatedObject(view, &kSuppressedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ logWatch(view, @selector(setAlpha:), onClass, onClass);}view.alpha = 0;view.userInteractionEnabled = NO;diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex e8fb74ca..ece93bd7 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -8,7 +8,7 @@// PlayerField.x the switch's flags and rows, the field in the background plane, the cover it reads// PlayerArtwork.x the cover's corners, shadow and paused shrink; the lyric preview as Spotify's setting has it// PlayerHeader.x glass behind the close and more buttons-// PlayerControls.x previous, play and next as bare glyphs, monospaced times+// PlayerControls.x previous, play and next as bare glyphs, shuffle and repeat hidden on request, monospaced times// PlayerFooter.x share gone, lyrics, Connect and queue as one row of three glyphs// DJPlayer.x the AI DJ's player (its own units): skip glyphs, a four glyph footer row, over the shared// play glyph, lowered row and Connect of PlayerControls.x and PlayerFooter.x@@ -122,6 +122,12 @@ BOOL SGRPlayerFollowsCover(void);void SGRPlayerSetCoverAccent(UIColor *cover);void SGRPlayerPaintCover(UIView *stack);+// Shuffle and repeat left out of the controls (PlayerControls.x), each on its own switch under Hide on the player, the+// way the Music app keeps them off its main controls. Off until switched on, read at launch. The buttons go by alpha+// and keep their slots, so previous, play and next stay where they are, centered.+#define SGRKeyPlayerHideShuffle @"spotifyglass.redesign.player.hideShuffle"+#define SGRKeyPlayerHideRepeat @"spotifyglass.redesign.player.hideRepeat"+// 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/PlayerControls.x b/tweak/Sources/Redesigned/Player/PlayerControls.xindex 07e6b552..9dbb0e8b 100644--- a/tweak/Sources/Redesigned/Player/PlayerControls.x+++ b/tweak/Sources/Redesigned/Player/PlayerControls.x@@ -1,5 +1,6 @@-// Player redesign: previous, play and next as bare glyphs, the way the Music app draws them, and the-// timestamps under the slider in digits of one width, so they stop twitching every second.+// Player redesign: previous, play and next as bare glyphs, the way the Music app draws them, shuffle and+// repeat left out on request, and the timestamps under the slider in digits of one width, so they stop+// twitching every second.//// The glyphs are drawn over Spotify's controls rather than instead of them: each button keeps its// action, its enabled state, its accessibility and the Gestures zones around it, and the glyph takes no@@ -31,7 +32,7 @@ static const NSTimeInterval kSpinnerCheck = 0.6;// one sent before the player caught up, for this long; after it the player's word is final.static const NSTimeInterval kTapTrust = 1.2;-static char kPreviousKey, kNextKey, kPlayKey, kGlyphKey, kTakeKey, kRemainingKey, kRowKey;+static char kPreviousKey, kNextKey, kPlayKey, kGlyphKey, kTakeKey, kRemainingKey, kRowKey, kShuffleKey, kRepeatKey;static __weak UIView *sg_playView;static __weak UIButton *sg_playButton;static CFTimeInterval sg_tappedUntil;@@ -95,6 +96,55 @@ static void skipGlyph(UIView *host, NSString *identifier, const void *findKey, NkeepOnTop(glyph, content);}+#pragma mark - shuffle and repeat++// Each switched on under Hide on the player (SGRKeyPlayerHideShuffle, SGRKeyPlayerHideRepeat), read at launch. By+// alpha in their slots: the row is Spotify's stack of five, and setting `hidden` in an Encore stack crashes. Kept by+// SGRSuppress, since Spotify's state render sets a button's alpha back to 1 when shuffle or repeat changes.+static BOOL sg_hideShuffle, sg_hideRepeat;+// The ordinary player's controls, apart from sg_controlsHost, which the DJ's set too.+static __weak UIView *sg_buttonsHost;+static NSString *const kShuffleID = @"Components.UI.ShuffleButton", *const kRepeatID = @"Nowplaying-RepeatButton";++static BOOL isHiddenButton(UIView *view) {+ NSString *identifier = view.accessibilityIdentifier;+ return (sg_hideShuffle && [identifier isEqualToString:kShuffleID])+ || (sg_hideRepeat && [identifier isEqualToString:kRepeatID]);+}++// Spotify also swaps in a new button a moment after the controls lay out (seen for repeat on 9.1.90: the instance+// found leaves the window 40 ms later and another arrives at alpha 1), with no layout pass after it. The new one is+// caught as it arrives. The class is an Encore button's, taken from the first one found (`class`, not a KVO class+// it may be observed through), since its name carries a build hash. It is the class of every Encore button, the+// playlist, album and artist headers' shuffle among them, so only one inside the player's controls goes; any other+// pays a window check and an identifier compare as it moves.+%group SGRPlayerButtonArrival+%hook SGRPlayerButton+- (void)didMoveToWindow {+ %orig;+ UIView *view = (UIView *)self;+ if (view.window && isHiddenButton(view) && sg_buttonsHost && [view isDescendantOfView:sg_buttonsHost]) SGRSuppress(view);+}+%end+%end++static void suppressButton(UIView *button) {+ if (!button) return;+ SGRSuppress(button);+ static BOOL hooked;+ if (hooked) return;+ hooked = YES;+ %init(SGRPlayerButtonArrival, SGRPlayerButton = button.class);+}++// Each is looked for only in its own end of the row, so a row without it (a podcast's) costs a walk of one+// element, not the unit.+static void hideShuffleAndRepeat(UIView *host, UIStackView *row) {+ sg_buttonsHost = host;+ if (sg_hideShuffle) suppressButton(SGRFindByIdentifier(row.arrangedSubviews.firstObject, kShuffleID, &kShuffleKey));+ if (sg_hideRepeat) suppressButton(SGRFindByIdentifier(row.arrangedSubviews.lastObject, kRepeatID, &kRepeatKey));+}+#pragma mark - playstatic BOOL spinnerShowing(UIButton *button) {@@ -183,10 +233,12 @@ void SGRPlayerPlayGlyphIn(UIView *host) {UIView *host = ((UIViewController *)self).viewIfLoaded;if (!host) return;// The unit lays out before its row does, and the glyphs are centered on the buttons in it.- [SGFindRemembered(host, &kRowKey, ^BOOL(UIView *v) { return SGIsRow(v); }) layoutIfNeeded];+ UIStackView *row = (UIStackView *)SGFindRemembered(host, &kRowKey, ^BOOL(UIView *v) { return SGIsRow(v); });+ [row layoutIfNeeded];skipGlyph(host, @"SPTNowPlayingPreviousTrackButton", &kPreviousKey, @"backward.fill");skipGlyph(host, @"SPTNowPlayingNextTrackButton", &kNextKey, @"forward.fill");SGRPlayerPlayGlyphIn(host);+ hideShuffleAndRepeat(host, row);}%end@@ -421,6 +473,8 @@ static void durationLaidOut(UIViewController *unit) {%ctor {if (!SGRedesignedUI()) return;%init;+ sg_hideShuffle = SGHidden(SGRKeyPlayerHideShuffle);+ sg_hideRepeat = SGHidden(SGRKeyPlayerHideRepeat);Class djDuration = SGRDJClass(@"DJMDurationElementsUnit");if (djDuration) { %init(SGRDJControlsDurationHooks, SGRDJControlsDurationUnit = djDuration); }sg_controlsWatcher = [SGRPlayerControlsWatcher new];