Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: holding either side of the cover plays faster until your finger lifts
My-Name-Is-Jeff9e62178d71f2
diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 44bac3f9..94798a5b 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -135,3 +135,9 @@ NSString *SGLyricsGeminiLanguage(void) { return @"en"; }void SGLyricsTranslateWithGemini(NSString *trackID, NSArray<SGKaraokeLine *> *lines, NSString *languageTag,void (^done)(NSArray<NSString *> *translations, NSString *error)) { done(nil, @"harness"); }UIViewController *SGTopController(void) { return UIApplication.sharedApplication.keyWindow.rootViewController; }++// Speed and pitch: a number the harness keeps, with no audio behind it.+static double sg_speed = 1;+double SGPlayerSpeed(void) { return sg_speed; }+BOOL SGPlayerSpeedAllowed(void) { return YES; }+void SGSetPlayerSpeed(double speed) { sg_speed = speed; NSLog(@"[harness] speed %.2f", speed); }diff --git a/tweak/Sources/Native/Player/PlayerGestures.x b/tweak/Sources/Native/Player/PlayerGestures.xindex 71e35f52..622c5780 100644--- a/tweak/Sources/Native/Player/PlayerGestures.x+++ b/tweak/Sources/Native/Player/PlayerGestures.x@@ -1,10 +1,146 @@// The native player's hookup of the gestures (Shared/Gestures): the double tap goes on the player's artwork list.+// And the hold to play faster on the cover, the native look's copy of the redesign's (Redesigned/Player/+// PlayerArtwork.x).//// Tree (trees/now-playing.txt): the artwork sits in AccessibleCollectionView, a full screen list of// the queue scrolled sideways, so the recognizer goes on that and the grid is the screen. Spotify's// controls are sibling units rather than children of it, so a tap on a button never reaches it.+#import <objc/runtime.h>#import "Core/SGCore.h"#import "Shared/Gestures/Gestures.h"+#import "Shared/Haptics/Haptics.h"+#import "Shared/Player/SpeedPitch.h"++#pragma mark - hold to play faster++// Holding either side of the cover plays at kHoldSpeed until the finger lifts, and the speed set before+// comes back. The middle third is left alone, and a hold that starts to move is a swipe to the next track.+// It is a speed like the menu's, so with Pitch follows speed on (until switched off) it also plays an+// octave higher, the way a record does.+static const double kHoldSpeed = 2;+// The now playing bar's cover has a tilt view of its own, 40pt; the player's is about 354.+static const CGFloat kCoverMinWidth = 200;+static char kHoldKey;+// The badge comes in quickly and goes quicker: the finger is already off the cover.+static const NSTimeInterval kBadgeEnter = 0.2, kBadgeExit = 0.15;++@interface SGCoverHold : UILongPressGestureRecognizer+@end++@implementation SGCoverHold {+ double _before;+ UIVisualEffectView *_badge;+ UILabel *_badgeLabel;+ BOOL _badgeShown;+}++- (void)sg_held {+ UIView *cover = self.view;+ if (self.state == UIGestureRecognizerStateBegan) {+ CGFloat x = [self locationInView:cover].x, third = cover.bounds.size.width / 3;+ if ((x > third && x < 2 * third) || !SGPlayerSpeedAllowed()) {+ self.enabled = NO;+ self.enabled = YES; // cancels this hold+ return;+ }+ _before = SGPlayerSpeed();+ SGSetPlayerSpeed(kHoldSpeed);+ SGPlayFeedback(SGFeedbackGrab);+ [self showBadge:YES on:cover];+ UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"Playing at 2 times speed");+ } else if (self.state == UIGestureRecognizerStateEnded || self.state == UIGestureRecognizerStateCancelled+ || self.state == UIGestureRecognizerStateFailed) {+ if (_before > 0) SGSetPlayerSpeed(_before);+ _before = 0;+ [self showBadge:NO on:cover];+ }+}++// "2×" and a forward glyph on a capsule of the look's glass (SGGlassEffect: Liquid Glass from iOS 26, the dark+// chrome blur before) at the top of the cover while it is held. What fades is the effect, never an alpha+// over it, which UIKit draws a blur under wrongly or not at all.+- (void)showBadge:(BOOL)shown on:(UIView *)cover {+ if (shown && !_badge) {+ _badgeLabel = [UILabel new];+ UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];+ NSTextAttachment *arrows = [NSTextAttachment textAttachmentWithImage:[[UIImage systemImageNamed:@"forward.fill"+ withConfiguration:[UIImageSymbolConfiguration configurationWithFont:font]] imageWithTintColor:UIColor.whiteColor+ renderingMode:UIImageRenderingModeAlwaysOriginal]];+ NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"2× "+ attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: UIColor.whiteColor}];+ [text appendAttributedString:[NSAttributedString attributedStringWithAttachment:arrows]];+ _badgeLabel.attributedText = text;+ _badgeLabel.textAlignment = NSTextAlignmentCenter;+ _badge = [[UIVisualEffectView alloc] initWithEffect:nil];+ _badge.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ _badge.userInteractionEnabled = NO;+ _badge.frame = CGRectMake(0, 0, 92, 34);+ SGShapeGlass(_badge, 17, YES);+ _badgeLabel.frame = _badge.bounds;+ [_badge.contentView addSubview:_badgeLabel];+ }+ if (!_badge) return;+ _badgeShown = shown;+ UIVisualEffectView *badge = _badge;+ UILabel *label = _badgeLabel;+ if (shown) {+ if (badge.superview != cover) {+ badge.center = CGPointMake(CGRectGetMidX(cover.bounds), 30);+ badge.effect = nil;+ label.alpha = 0;+ badge.transform = UIAccessibilityIsReduceMotionEnabled() ? CGAffineTransformIdentity : CGAffineTransformMakeScale(0.9, 0.9);+ [cover addSubview:badge];+ }+ [UIView animateWithDuration:kBadgeEnter delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState+ animations:^{+ badge.effect = SGGlassEffect();+ label.alpha = 1;+ badge.transform = CGAffineTransformIdentity;+ } completion:nil];+ } else {+ [UIView animateWithDuration:kBadgeExit delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState+ animations:^{+ badge.effect = nil;+ label.alpha = 0;+ } completion:^(BOOL finished) {+ if (finished && !self->_badgeShown) [badge removeFromSuperview];+ }];+ }+}++@end++// The player's cover cells, whichever Spotify builds (the strings are in 9.1.78's binary); a tilt view+// elsewhere, an album's header, is left alone.+static BOOL inPlayerCover(UIView *tilt) {+ static NSArray<Class> *cells;+ if (!cells) {+ NSMutableArray<Class> *found = [NSMutableArray array];+ for (NSString *name in @[@"_TtC28NowPlaying_ContentLayersImpl16CoverArtCellImpl", @"_TtC28NowPlaying_ContentLayersImpl22LegacyCoverArtCellImpl",+ @"_TtC39ListeningParties_NowPlayingViewModeImpl34NowPlayingLiveRoomCoverArtCellImpl"]) {+ Class cell = NSClassFromString(name);+ if (cell) [found addObject:cell];+ }+ cells = found;+ }+ for (UIView *v = tilt.superview; v; v = v.superview) {+ for (Class cell in cells) if ([v isKindOfClass:cell]) return YES;+ }+ return NO;+}++static void watchHold(UIView *tilt) {+ if (objc_getAssociatedObject(tilt, &kHoldKey) || tilt.bounds.size.width < kCoverMinWidth || !inPlayerCover(tilt)) return;+ SGCoverHold *hold = [[SGCoverHold alloc] initWithTarget:nil action:nil];+ [hold addTarget:hold action:@selector(sg_held)];+ hold.minimumPressDuration = 0.35;+ [tilt addGestureRecognizer:hold];+ objc_setAssociatedObject(tilt, &kHoldKey, hold, OBJC_ASSOCIATION_ASSIGN);+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"native player: hold to play faster on the cover (%@)", NSStringFromClass(tilt.superview.class)); });+}++#pragma mark - hooks// A single tap on the cover is Spotify's way into the tilt mode, the artwork alone in 3D. That is// the half of a double tap that misses, so while the zones are on it would open on the way to every@@ -14,6 +150,10 @@if (SGFlag(SGKeyGestures, NO)) return;%orig;}+- (void)layoutSubviews {+ %orig;+ watchHold((UIView *)self);+}%end%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionViewdiff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.xindex b21ff536..60e5f135 100644--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x@@ -12,6 +12,8 @@// the transition is over a paused cover springs down.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"+#import "Shared/Haptics/Haptics.h"+#import "Shared/Player/SpeedPitch.h"#import "Player.h"static const CGFloat kPausedScale = 0.84, kPausedScaleReduceMotion = 0.92;@@ -131,6 +133,112 @@ static void scaleEveryCover(BOOL animated) {else apply();}+#pragma mark - hold to play faster++// Holding either side of the cover plays at kHoldSpeed until the finger lifts, and the speed set before+// comes back. The middle third is left alone, and a hold that starts to move is a swipe to the next track.+// It is a speed like the menu's, so with Pitch follows speed on (until switched off) it also plays an+// octave higher, the way a record does. The native look's copy is in Native/Player/PlayerGestures.x.+static const double kHoldSpeed = 2;+// The badge's way out, quicker than its way in: the finger is already off the cover.+static const NSTimeInterval kBadgeExit = 0.15;+static char kHoldKey, kBadgeGlassKey;++@interface SGRCoverHold : UILongPressGestureRecognizer+@end++@implementation SGRCoverHold {+ double _before;+ UIView *_badge;+ UILabel *_badgeLabel;+ BOOL _badgeShown;+}++- (void)sgr_held {+ UIView *cover = self.view;+ if (self.state == UIGestureRecognizerStateBegan) {+ CGFloat x = [self locationInView:cover].x, third = cover.bounds.size.width / 3;+ if ((x > third && x < 2 * third) || !SGPlayerSpeedAllowed()) {+ self.enabled = NO;+ self.enabled = YES; // cancels this hold+ return;+ }+ _before = SGPlayerSpeed();+ SGSetPlayerSpeed(kHoldSpeed);+ SGPlayFeedback(SGFeedbackGrab);+ [self showBadge:YES on:cover];+ UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"Playing at 2 times speed");+ } else if (self.state == UIGestureRecognizerStateEnded || self.state == UIGestureRecognizerStateCancelled+ || self.state == UIGestureRecognizerStateFailed) {+ if (_before > 0) SGSetPlayerSpeed(_before);+ _before = 0;+ [self showBadge:NO on:cover];+ }+}++// "2×" and a forward glyph on the Kit's glass capsule at the top of the cover while it is held. What fades+// is the glass's effect, never an alpha over it, which UIKit draws a blur under wrongly or not at all+// (PlayerMotion.x); the capsule grows in from 0.9 with the Kit's press spring.+- (void)showBadge:(BOOL)shown on:(UIView *)cover {+ if (shown && !_badge) {+ _badgeLabel = [UILabel new];+ UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];+ NSTextAttachment *arrows = [NSTextAttachment textAttachmentWithImage:[[UIImage systemImageNamed:@"forward.fill"+ withConfiguration:[UIImageSymbolConfiguration configurationWithFont:font]] imageWithTintColor:UIColor.whiteColor+ renderingMode:UIImageRenderingModeAlwaysOriginal]];+ NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"2× "+ attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: UIColor.whiteColor}];+ [text appendAttributedString:[NSAttributedString attributedStringWithAttachment:arrows]];+ _badgeLabel.attributedText = text;+ _badgeLabel.textAlignment = NSTextAlignmentCenter;+ _badge = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 92, 34)];+ _badge.userInteractionEnabled = NO;+ _badgeLabel.frame = _badge.bounds;+ _badgeLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [_badge addSubview:_badgeLabel];+ }+ if (!_badge) return;+ _badgeShown = shown;+ UIView *badge = _badge, *label = _badgeLabel;+ // Made again by the Kit if Reduce Transparency changed: then it is a solid fill, which fades by alpha.+ UIView *shape = SGRGlassCapsuleInside(badge, &kBadgeGlassKey, badge.bounds.size, NO);+ UIVisualEffectView *glass = [shape isKindOfClass:UIVisualEffectView.class] ? (UIVisualEffectView *)shape : nil;+ void (^state)(BOOL) = ^(BOOL on) {+ if (glass) glass.effect = on ? SGGlassEffect() : nil;+ else shape.alpha = on ? 1 : 0;+ label.alpha = on ? 1 : 0;+ };+ if (shown) {+ if (badge.superview != cover) {+ badge.center = CGPointMake(CGRectGetMidX(cover.bounds), 30);+ state(NO);+ badge.transform = SGRReduceMotion() ? CGAffineTransformIdentity : CGAffineTransformMakeScale(0.9, 0.9);+ [cover addSubview:badge];+ }+ // A fade alone under Reduce Motion, where the Kit's spring would be no animation at all.+ SGRAnimate(SGRReduceMotion() ? SGRMotionFade : SGRMotionPress, ^{+ state(YES);+ badge.transform = CGAffineTransformIdentity;+ }, nil);+ } else {+ [UIView animateWithDuration:kBadgeExit delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState+ animations:^{ state(NO); } completion:^(BOOL finished) {+ if (finished && !self->_badgeShown) [badge removeFromSuperview];+ }];+ }+}++@end++static void watchHold(UIView *tilt) {+ if (objc_getAssociatedObject(tilt, &kHoldKey)) return;+ SGRCoverHold *hold = [[SGRCoverHold alloc] initWithTarget:nil action:nil];+ [hold addTarget:hold action:@selector(sgr_held)];+ hold.minimumPressDuration = 0.35;+ [tilt addGestureRecognizer:hold];+ objc_setAssociatedObject(tilt, &kHoldKey, hold, OBJC_ASSOCIATION_ASSIGN);+}+%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView- (void)layoutSubviews {%orig;@@ -139,6 +247,7 @@ static void scaleEveryCover(BOOL animated) {UIView *cover = coverIn(tilt);if (!cover) return;[sg_tilts addObject:tilt];+ watchHold(tilt);// The cover fills the tilt view (01.txt:37); bounds and center, unlike a frame, hold under the scale.CGRect bounds = tilt.bounds;CGPoint middle = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));