Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: Speed and pitch stays out of the sleep timer and other sheets the player opens
My-Name-Is-Jeffdde2ff513544
diff --git a/harness/menu/README.md b/harness/menu/README.mdindex ab639a50..99b976a5 100644--- a/harness/menu/README.md+++ b/harness/menu/README.md@@ -1,12 +1,13 @@# Menu harnessSpotify's context menu sheet (`ContextMenu_InternalImpl.ContextMenuViewController`) mocked under its-class name and presented from a now playing controller, so `SpeedPitchMenu.x`'s hook adds Speed and-pitch the way it would on the phone. Speed and pitch themselves are stubs that log.+class name and presented from a now playing controller on a tap of the player's more button (a mock+`NowPlaying_ModesImpl.HeaderElementsUnit` holding a button with the identifier `Context menu`), so+`SpeedPitchMenu.x`'s hooks find the button and add Speed and pitch the way they would on the phone. Speed and pitch themselves are stubs that log.THEOS=$HOME/theos ./build.shxcrun simctl install <udid> build/MenuHarness.app- xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated]+ xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated] [sleep] [notap]It has a scene delegate, so it runs on the iOS 27 simulator as well as 26. The mod's own lines(`SGLog`) go to the unified log: `xcrun simctl spawn <udid> log stream --predicate 'eventMessage CONTAINS "[spotifyglass]"'`.@@ -30,5 +31,9 @@ the Pitch and the row read "−3 st".closed and again with it open, and reports where its row sits each time, `PASS` when the row is insidethe block and the switch shows what was set.+- `sleep` opens the ⋯ card, checks it has the block, then pushes a second sheet into it with no tap, as+ the card's Sleep timer row does: `PASS` when that sheet has no block.+- `notap` presents a sheet from the player with no tap on the more button: `PASS` when it has no block.+For the first second the block is on screen, every frame is checked for anything it draws in thesystem tint (`tint check: 0 of the block's first N frames ...`).diff --git a/harness/menu/main.m b/harness/menu/main.mindex 2add6ac8..c435ffff 100644--- a/harness/menu/main.m+++ b/harness/menu/main.m@@ -1,8 +1,10 @@-// Spotify's context menu sheet mocked under its class name, presented from a now playing controller,-// so SpeedPitchMenu.x's hook adds Speed and pitch the way it would on the phone.+// Spotify's context menu sheet mocked under its class name, presented from a now playing controller on a tap+// of the player's more button, so SpeedPitchMenu.x's hook adds Speed and pitch the way it would on the phone.+// `sleep` opens a second sheet from the first, as the ⋯ card's Sleep timer does, and `notap` one with no tap:+// neither may get the block.//// THEOS=$HOME/theos ./build.sh && xcrun simctl install <udid> build/MenuHarness.app-// xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated]+// xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open] [animated] [sleep] [notap]//// The plain run opens the menu at 1 s, opens the block at 3 s, moves the sliders at 5 s, checks what the// block says at 6 s (PASS or FAIL lines), closes the block at 7 s and checks its row at 8 s. `loading` builds the sheet the way Spotify's is (the ivars of ContextMenuViewController in@@ -190,13 +192,36 @@ static NSArray<NSArray<NSString *> *> *spotifyRows(void) {#pragma mark - the player+// The player's header row (NowPlaying_ModesImpl.HeaderElementsUnit), its more button an Encore button with+// the identifier "Context menu" (trees/lyrics.txt:183), which SpeedPitchMenu.x finds and watches.+@interface _TtC20NowPlaying_ModesImpl18HeaderElementsUnit : UIViewController+@property (nonatomic, strong) UIButton *more;+@end++@implementation _TtC20NowPlaying_ModesImpl18HeaderElementsUnit+- (void)viewDidLoad {+ [super viewDidLoad];+ self.more = [UIButton buttonWithType:UIButtonTypeSystem];+ [self.more setImage:[UIImage systemImageNamed:@"ellipsis"] forState:UIControlStateNormal];+ self.more.frame = CGRectMake(330, 0, 48, 48);+ self.more.accessibilityIdentifier = @"Context menu";+ [self.view addSubview:self.more];+}+@end+@interface NowPlayingHarnessViewController : UIViewController+@property (nonatomic, strong) _TtC20NowPlaying_ModesImpl18HeaderElementsUnit *header;@end@implementation NowPlayingHarnessViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor colorWithRed:0.25 green:0.1 blue:0.2 alpha:1];+ self.header = [_TtC20NowPlaying_ModesImpl18HeaderElementsUnit new];+ [self addChildViewController:self.header];+ self.header.view.frame = CGRectMake(0, 60, 402, 48);+ [self.view addSubview:self.header.view];+ [self.header didMoveToParentViewController:self];}@end@@ -321,7 +346,9 @@ static void tapRow(UIViewController *menu) {static SGHarnessFrameWatch *watch;__block _TtC24ContextMenu_InternalImpl25ContextMenuViewController *menu;BOOL loading = argument(@"loading"), stuck = argument(@"stuck");+ // Spotify's ⋯ card, put up by a tap on the player's more button: the tap first, as a finger lifting off it.void (^present)(void) = ^{+ [player.header.more sendActionsForControlEvents:UIControlEventTouchUpInside];menu = [_TtC24ContextMenu_InternalImpl25ContextMenuViewController new];UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:menu];navigation.navigationBarHidden = YES;@@ -331,6 +358,35 @@ static void tapRow(UIViewController *menu) {[[CADisplayLink displayLinkWithTarget:watch selector:@selector(tick:)] addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];[player presentViewController:navigation animated:YES completion:nil];};+ if (argument(@"sleep") || argument(@"notap")) {+ // `sleep`: the ⋯ card's Sleep timer row opens a context menu sheet of its own in the card, with no tap+ // on the more button; it must stay Spotify's. `notap`: a sheet the player puts up with no tap at all.+ BOOL sleep = argument(@"sleep");+ after(1, ^{+ if (sleep) {+ present();+ return;+ }+ menu = [_TtC24ContextMenu_InternalImpl25ContextMenuViewController new];+ [player presentViewController:[[UINavigationController alloc] initWithRootViewController:menu] animated:YES completion:nil];+ });+ if (!sleep) {+ after(3, ^{ check(!findBlock(menu.view), @"a sheet the player put up with no tap on ⋯ has no Speed and pitch"); });+ return;+ }+ __block UIViewController *card;+ after(3, ^{+ card = menu;+ check(findBlock(card.view) != nil, @"the ⋯ card has Speed and pitch");+ menu = [_TtC24ContextMenu_InternalImpl25ContextMenuViewController new];+ [card.navigationController pushViewController:menu animated:YES];+ });+ after(5, ^{+ check(menu.view.window && menu.navigationController.presentingViewController == player, @"the sleep timer sheet is up, presented from the player");+ check(!findBlock(menu.view), @"the sleep timer sheet has no Speed and pitch");+ });+ return;+ }if (argument(@"animated")) {void (^where)(NSString *) = ^(NSString *when) {UIView *block = findBlock(menu.view);diff --git a/tweak/Sources/Redesigned/Player/PlayerHeader.x b/tweak/Sources/Redesigned/Player/PlayerHeader.xindex ca24a2f7..9d8c6e5b 100644--- a/tweak/Sources/Redesigned/Player/PlayerHeader.x+++ b/tweak/Sources/Redesigned/Player/PlayerHeader.x@@ -18,7 +18,6 @@// between them.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"-#import "Shared/Player/SpeedPitch.h"#import "Player.h"static char kGlassKey, kCloseKey, kMoreKey;@@ -40,7 +39,6 @@ static void glassInside(UIViewController *unit, NSArray<NSString *> *identifiers}SGRGlassInside(button, &kGlassKey, SGRGlassCircleSize);if ([identifiers[i] isEqualToString:@"Context menu"]) {- SGPlayerMenuWatchMoreButton(button);SGRPlayerMenuWatch(button);}found++;diff --git a/tweak/Sources/Shared/Player/SpeedPitch.h b/tweak/Sources/Shared/Player/SpeedPitch.hindex 278b628a..d5304fdc 100644--- a/tweak/Sources/Shared/Player/SpeedPitch.h+++ b/tweak/Sources/Shared/Player/SpeedPitch.h@@ -13,12 +13,8 @@#import <UIKit/UIKit.h>#import <AudioToolbox/AudioToolbox.h>-// Marks a menu opened soon after a tap on `button`, the player's more button, as the player's, so it gets-// Speed and pitch (watching it twice does nothing). The redesign's PlayerHeader.x hands its button over;-// a menu presented from a now playing controller is taken for the player's without it, which is how the-// native look's player gets the block.-void SGPlayerMenuWatchMoreButton(UIView *button);-// Whether a context menu sheet is the player's, by the same test; decided once per menu.+// Whether a context menu sheet is the player's ⋯ card: the first to come up within a few seconds of a tap on+// the player's more button (SpeedPitchMenu.x watches it under either look); decided once per menu.BOOL SGPlayerMenuIsPlayers(UIViewController *menu);// Whether the sheet is shown as the system menu instead, unseen under it (Redesigned/ContextMenu), whose own// items then stand in for the block, which stays out of it. Defined by the redesign; NO under the native lookdiff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.xindex 25c334a5..8e5d1ae7 100644--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x@@ -10,11 +10,12 @@// follow.//// Only the menu the player's more button opens gets it: the button (id=Context menu,-// trees/lyrics.txt:183, an Encore Tertiary button) is watched from the redesign's PlayerHeader.x, and a-// menu shown within a few seconds of its tap, or presented from a now playing controller, is the-// player's. Under the native look nothing hands the button over, so the block rides on the second test-// alone, the presenter being Spotify's own now playing controller. The first time, the menu's structure-// is logged, since no recorded tree shows it yet.+// trees/lyrics.txt:183, an Encore Tertiary button in NowPlaying_ModesImpl.HeaderElementsUnit) is watched+// from here under either look, and the first menu that comes up within a few seconds of its tap is the+// player's. The presenter is not a test: every sheet the player puts up comes from its+// NowPlayingOverlayContainer, the ⋯ card's own pages too (its Sleep timer is a context menu sheet of its own,+// which took the block as well, "tapped 0" in the log). The first time, the menu's structure is logged,+// since no recorded tree shows it yet.//// The block is drawn from its own measures and type (below), not from the redesign's Kit, so it sits on// Spotify's sheet under either look.@@ -522,7 +523,7 @@ static NSString *pitchText(float pitch) {}@end-void SGPlayerMenuWatchMoreButton(UIView *button) {+static void watchMoreButton(UIView *button) {if (!button || objc_getAssociatedObject(button, &kWatchedKey)) return;static SGMoreTapWatcher *watcher;if (!watcher) watcher = [SGMoreTapWatcher new];@@ -541,16 +542,6 @@ void SGPlayerMenuWatchMoreButton(UIView *button) {#pragma mark - the menu-// The presenter or one of its parents is a now playing controller. Only the chain up is looked at: the-// root's children include the now playing bar's, which every menu would match.-static BOOL presentedFromPlayer(UIViewController *menu) {- UIViewController *presenter = menu.navigationController.presentingViewController ?: menu.presentingViewController;- for (UIViewController *vc = presenter; vc; vc = vc.parentViewController) {- if ([NSStringFromClass(vc.class) containsString:@"NowPlaying"]) return YES;- }- return NO;-}-static void logStructure(UIView *view, int depth, NSMutableString *out) {if (depth > 6 || out.length > 3000) return;[out appendFormat:@"\n%*s%@ %@", depth * 2, "", NSStringFromClass(view.class), NSStringFromCGRect(view.frame)];@@ -576,13 +567,12 @@ static UITableView *findTable(UIView *root, int depth) {static BOOL isPlayerMenu(UIViewController *menu) {NSNumber *decided = objc_getAssociatedObject(menu, &kDecidedKey);if (decided) return decided.boolValue;- BOOL tapped = sg_moreTappedAt && CACurrentMediaTime() - sg_moreTappedAt < kMenuAfterTap;- BOOL fromPlayer = presentedFromPlayer(menu);- BOOL ours = tapped || fromPlayer;- if (tapped) sg_moreTappedAt = 0;+ // The tap is used up by the menu it opened, so a sheet that menu opens in turn is not taken for it.+ BOOL ours = sg_moreTappedAt && CACurrentMediaTime() - sg_moreTappedAt < kMenuAfterTap;+ if (ours) sg_moreTappedAt = 0;objc_setAssociatedObject(menu, &kDecidedKey, @(ours), OBJC_ASSOCIATION_RETAIN_NONATOMIC);UIViewController *presenter = menu.navigationController.presentingViewController ?: menu.presentingViewController;- SGLog(@"speed and pitch: a context menu, %@ (tapped %d, presented by %@)", ours ? @"the player's" : @"not the player's", tapped,+ SGLog(@"speed and pitch: a context menu, %@ (tapped %d, presented by %@)", ours ? @"the player's" : @"not the player's", ours,presenter ? NSStringFromClass(presenter.class) : @"nothing");return ours;}@@ -704,6 +694,22 @@ static void install(UIViewController *menu) {}}+// The player's header row: its more button found by its identifier and watched, under either look.+%hook _TtC20NowPlaying_ModesImpl18HeaderElementsUnit+- (void)viewDidLayoutSubviews {+ %orig;+ UIView *row = ((UIViewController *)self).viewIfLoaded;+ static __weak UIView *watched;+ if (watched && [watched isDescendantOfView:row]) return;+ __block UIView *more = nil;+ SGForEachView(row, ^(UIView *view) {+ if (!more && [view.accessibilityIdentifier isEqualToString:@"Context menu"]) more = view;+ });+ watchMoreButton(more);+ if (more) watched = more;+}+%end+%hook _TtC24ContextMenu_InternalImpl25ContextMenuViewController- (void)viewDidLayoutSubviews {%orig;@@ -720,5 +726,5 @@ static void install(UIViewController *menu) {%ctor {%init;- SGRequireClasses(@[@"_TtC24ContextMenu_InternalImpl25ContextMenuViewController"]);+ SGRequireClasses(@[@"_TtC24ContextMenu_InternalImpl25ContextMenuViewController", @"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit"]);}