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

fix: the ⋯ menu's Speed and pitch row is white from its first frame (#68)

Vojtěch Škopekee97535e0e2d
diff --git a/harness/menu/README.md b/harness/menu/README.md
index 7dc4d1f4..c2d53cff 100644
--- a/harness/menu/README.md
+++ b/harness/menu/README.md
@@ -1,13 +1,27 @@
# Menu harness
Spotify's context menu sheet (`ContextMenu_InternalImpl.ContextMenuViewController`) mocked under its
-class name and presented from a now playing controller, so `PlayerMenu.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, so `SpeedPitchMenu.x`'s hook adds Speed and
+pitch the way it would on the phone. Speed and pitch themselves are stubs that log.
THEOS=$HOME/theos ./build.sh
- xcrun simctl install booted build/MenuHarness.app
- xcrun simctl launch --console-pty booted com.vojta.menuharness [footer] [nospeed]
+ xcrun simctl install <udid> build/MenuHarness.app
+ xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open]
-The menu opens at 1 s, the block at 3 s, both sliders move at 5 s and the block closes at 7 s.
-`footer` gives the mock table a header of Spotify's, so the block goes to the footer; `nospeed` has
-the player refuse speed.
+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]"'`.
+
+The plain run opens the menu at 1 s, the block at 3 s, moves both sliders at 5 s and closes the block
+at 7 s. `footer` gives the mock table a header of Spotify's, so the block goes to the footer;
+`nospeed` has the player refuse speed.
+
+- `loading` builds the sheet the way Spotify's is laid out (a header, a content container holding a
+ table sized to its content by KVO on `contentSize`, a spinner) and gives it its rows 4 s after it is
+ up, the way Spotify does once its item factories have answered. It reports the sheet while loading
+ and once the rows are in: they show under the block.
+- `stuck` never gives it rows; the mod logs `no rows of Spotify's N s after the menu appeared`.
+- `open` opens the block on a first menu, closes that menu and brings up a second one with the block
+ already open, as it stays for the session.
+
+For the first second the block is on screen, every frame is checked for anything it draws in the
+system tint (`tint check: 0 of the block's first N frames ...`).
diff --git a/harness/menu/build.sh b/harness/menu/build.sh
index bc2b0c42..ca913210 100755
--- a/harness/menu/build.sh
+++ b/harness/menu/build.sh
@@ -29,6 +29,12 @@ cat > "$OUT/MenuHarness.app/Info.plist" <<'PLIST'
<key>UILaunchScreen</key><dict/>
<key>UIApplicationSceneManifest</key><dict>
<key>UIApplicationSupportsMultipleScenes</key><false/>
+ <key>UISceneConfigurations</key><dict>
+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>
+ <key>UISceneConfigurationName</key><string>Default</string>
+ <key>UISceneDelegateClassName</key><string>SGHarnessScene</string>
+ </dict></array>
+ </dict>
</dict>
</dict></plist>
PLIST
diff --git a/harness/menu/main.m b/harness/menu/main.m
index 0b720a01..5048ad99 100644
--- a/harness/menu/main.m
+++ b/harness/menu/main.m
@@ -1,17 +1,23 @@
// Spotify's context menu sheet mocked under its class name, presented from a now playing controller,
-// so PlayerMenu.x's hook adds Speed and pitch the way it would on the phone. The script opens the menu at
-// 1 s, opens the block at 3 s, moves both sliders at 5 s and closes the block at 7 s; screenshot between.
+// so SpeedPitchMenu.x's hook adds Speed and pitch the way it would on the phone.
//
-// THEOS=$HOME/theos ./build.sh && xcrun simctl install booted build/MenuHarness.app
-// xcrun simctl launch --console-pty booted com.vojta.menuharness [footer] [nospeed]
+// 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]
+//
+// The plain run opens the menu at 1 s, opens the block at 3 s, moves both sliders at 5 s and closes the
+// block at 7 s. `loading` builds the sheet the way Spotify's is (the ivars of ContextMenuViewController in
+// 9.1.78: a header, a content container holding a ContextMenuTableView whose height follows its
+// contentSize by KVO, a loading spinner) and hands it its rows only 4 s after it is up, as Spotify does
+// once its item factories have answered; `stuck` never hands them over. `open` opens the block on a first
+// menu, closes it, and brings up a second one with the block open, as it stays for the session. Every frame of the first second the block is on screen
+// is checked for a colour of the system tint on anything it draws, and what the sheet shows is reported.
#import <UIKit/UIKit.h>
-#pragma mark - what PlayerMenu.x calls
+#pragma mark - what SpeedPitchMenu.x calls
static double sg_speed = 1;
static float sg_pitch;
static BOOL sg_speedAllowed = YES;
-UIColor *SGRAccentColor(void) { return nil; }
void SGPlayFeedback(NSInteger feedback) { NSLog(@"[harness] feedback %ld", (long)feedback); }
void SGPrepareFeedback(NSInteger feedback) {}
double SGPlayerSpeed(void) { return sg_speed; }
@@ -21,49 +27,130 @@ float SGPlayerPitch(void) { return sg_pitch; }
void SGSetPlayerPitch(float semitones) { sg_pitch = semitones; NSLog(@"[harness] pitch %.0f", semitones); }
BOOL SGPlayerPitchAvailable(void) { return YES; }
+static BOOL argument(NSString *name) {
+ return [NSProcessInfo.processInfo.arguments containsObject:name];
+}
+
+static NSArray<NSArray<NSString *> *> *spotifyRows(void) {
+ return @[@[@"plus.circle", @"Add to playlist"], @[@"music.note.list", @"Add to queue"], @[@"person", @"Go to artist"],
+ @[@"square.stack", @"Go to album"], @[@"square.and.arrow.up", @"Share"], @[@"moon", @"Sleep timer"],
+ @[@"dot.radiowaves.left.and.right", @"Go to song radio"], @[@"info.circle", @"View credits"]];
+}
+
#pragma mark - Spotify's sheet
+// ContextMenu_InternalImpl.(anon).ContextMenuTableView: sized to its content, its intrinsic size is its
+// contentSize (it overrides intrinsicContentSize, layoutSubviews and reloadData in 9.1.78).
+@interface SGHarnessMenuTable : UITableView
+@end
+
+@implementation SGHarnessMenuTable
+- (CGSize)intrinsicContentSize {
+ return CGSizeMake(UIViewNoIntrinsicMetric, self.contentSize.height);
+}
+- (void)reloadData {
+ [super reloadData];
+ [self invalidateIntrinsicContentSize];
+}
+@end
+
@interface _TtC24ContextMenu_InternalImpl25ContextMenuViewController : UIViewController <UITableViewDataSource>
@property (nonatomic, strong) UITableView *table;
+@property (nonatomic, strong) UIActivityIndicatorView *spinner;
+@property (nonatomic, strong) NSLayoutConstraint *contentHeight;
+@property (nonatomic) BOOL loaded;
@end
@implementation _TtC24ContextMenu_InternalImpl25ContextMenuViewController
-- (NSArray<NSArray<NSString *> *> *)rows {
- return @[@[@"plus.circle", @"Add to playlist"], @[@"music.note.list", @"Add to queue"], @[@"person", @"Go to artist"],
- @[@"square.stack", @"Go to album"], @[@"square.and.arrow.up", @"Share"], @[@"moon", @"Sleep timer"],
- @[@"dot.radiowaves.left.and.right", @"Go to song radio"], @[@"info.circle", @"View credits"]];
-}
-
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.07 alpha:1];
- self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
- self.table.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ BOOL loading = argument(@"loading") || argument(@"stuck");
+ self.loaded = !loading;
+ self.table = [[(loading ? SGHarnessMenuTable.class : UITableView.class) alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.table.backgroundColor = UIColor.clearColor;
self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
self.table.rowHeight = 56;
self.table.dataSource = self;
[self.table registerClass:UITableViewCell.class forCellReuseIdentifier:@"row"];
- if ([NSProcessInfo.processInfo.arguments containsObject:@"footer"]) {
+ if (argument(@"footer")) {
UILabel *heading = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
heading.text = @" Spotify's heading";
heading.textColor = UIColor.whiteColor;
self.table.tableHeaderView = heading;
}
- [self.view addSubview:self.table];
+ if (!loading) {
+ self.table.frame = self.view.bounds;
+ self.table.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ [self.view addSubview:self.table];
+ return;
+ }
+
+ // Spotify's layout: its own header (the track), a divider, then the content container with the table
+ // in it, the spinner over the container while the rows are not in.
+ UILabel *header = [UILabel new];
+ header.text = @" Blinding Lights · The Weeknd";
+ header.textColor = UIColor.whiteColor;
+ UIView *container = [UIView new];
+ self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];
+ self.spinner.color = UIColor.whiteColor;
+ for (UIView *view in @[header, container, self.table, self.spinner]) view.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.view addSubview:header];
+ [self.view addSubview:container];
+ [container addSubview:self.table];
+ [container addSubview:self.spinner];
+ self.contentHeight = [self.table.heightAnchor constraintEqualToConstant:0];
+ self.contentHeight.priority = UILayoutPriorityDefaultHigh;
+ [NSLayoutConstraint activateConstraints:@[
+ [header.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:16],
+ [header.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
+ [header.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
+ [header.heightAnchor constraintEqualToConstant:56],
+ [container.topAnchor constraintEqualToAnchor:header.bottomAnchor],
+ [container.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
+ [container.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
+ [container.bottomAnchor constraintLessThanOrEqualToAnchor:self.view.bottomAnchor],
+ [container.heightAnchor constraintGreaterThanOrEqualToConstant:120],
+ [self.table.topAnchor constraintEqualToAnchor:container.topAnchor],
+ [self.table.leadingAnchor constraintEqualToAnchor:container.leadingAnchor],
+ [self.table.trailingAnchor constraintEqualToAnchor:container.trailingAnchor],
+ [self.table.bottomAnchor constraintLessThanOrEqualToAnchor:container.bottomAnchor],
+ self.contentHeight,
+ [self.spinner.centerXAnchor constraintEqualToAnchor:container.centerXAnchor],
+ [self.spinner.centerYAnchor constraintEqualToAnchor:container.centerYAnchor],
+ ]];
+ [self.spinner startAnimating];
+ // ContextMenuTableViewCoordinator.tableViewContentSizeObservation
+ [self.table addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:NULL];
+}
+
+- (void)dealloc {
+ if (self.spinner) [self.table removeObserver:self forKeyPath:@"contentSize"];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
+ self.contentHeight.constant = self.table.contentSize.height;
+}
+
+// What the model publisher does once the item factories have answered.
+- (void)takeRows {
+ self.loaded = YES;
+ [self.spinner stopAnimating];
+ self.spinner.hidden = YES;
+ [self.table reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.rows.count;
+ return self.loaded ? spotifyRows().count : 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"row" forIndexPath:indexPath];
UIListContentConfiguration *content = cell.defaultContentConfiguration;
- content.text = self.rows[indexPath.row][1];
+ content.text = spotifyRows()[indexPath.row][1];
content.textProperties.color = UIColor.whiteColor;
- content.image = [UIImage systemImageNamed:self.rows[indexPath.row][0]];
+ content.image = [UIImage systemImageNamed:spotifyRows()[indexPath.row][0]];
content.imageProperties.tintColor = [UIColor colorWithWhite:0.7 alpha:1];
cell.contentConfiguration = content;
cell.backgroundColor = UIColor.clearColor;
@@ -92,10 +179,6 @@ BOOL SGPlayerPitchAvailable(void) { return YES; }
}
@end
-@interface SGRHarnessDelegate : UIResponder <UIApplicationDelegate>
-@property (nonatomic, strong) UIWindow *window;
-@end
-
static UIView *findBlock(UIView *root) {
if ([NSStringFromClass(root.class) isEqualToString:@"SGSpeedPitchView"]) return root;
for (UIView *child in root.subviews) {
@@ -112,33 +195,146 @@ static NSArray<UISlider *> *sliders(UIView *root) {
return found;
}
-@implementation SGRHarnessDelegate
+#pragma mark - the tint check
+
+// A colour is the system tint's when it resolves, in the view's own traits, to the system blue.
+static BOOL isTint(UIColor *color, UIView *view) {
+ if (!color) return NO;
+ UIColor *resolved = [color resolvedColorWithTraitCollection:view.traitCollection];
+ UIColor *blue = [UIColor.systemBlueColor resolvedColorWithTraitCollection:view.traitCollection];
+ CGFloat r, g, b, a, br, bg, bb, ba;
+ if (![resolved getRed:&r green:&g blue:&b alpha:&a] || ![blue getRed:&br green:&bg blue:&bb alpha:&ba]) return NO;
+ return a > 0.05 && fabs(r - br) < 0.08 && fabs(g - bg) < 0.08 && fabs(b - bb) < 0.08;
+}
+
+// Everything the block draws in a colour of its own: labels' text, buttons' titles, and whatever takes the
+// tint (templated glyphs, sliders' thumbs and tracks).
+static void tintedViews(UIView *view, NSMutableArray<NSString *> *out) {
+ if (view.isHidden || view.alpha < 0.01) return;
+ NSString *name = NSStringFromClass(view.class);
+ if ([view isKindOfClass:UILabel.class] && isTint(((UILabel *)view).textColor, view)) [out addObject:[name stringByAppendingFormat:@" text \"%@\"", ((UILabel *)view).text]];
+ if ([view isKindOfClass:UIImageView.class]) {
+ UIImage *image = ((UIImageView *)view).image;
+ // Drawn in the tint when templated, or left automatic on a symbol; a bitmap left automatic keeps
+ // its own colours (the sliders' end images).
+ BOOL templated = image.renderingMode == UIImageRenderingModeAlwaysTemplate
+ || (image.renderingMode == UIImageRenderingModeAutomatic && image.isSymbolImage);
+ if (templated && isTint(view.tintColor, view)) [out addObject:[name stringByAppendingString:@" glyph"]];
+ }
+ if ([view isKindOfClass:UIButton.class] && isTint([(UIButton *)view titleColorForState:((UIButton *)view).state], view)) [out addObject:[name stringByAppendingString:@" title"]];
+ if ([view isKindOfClass:UISlider.class]) {
+ UISlider *slider = (UISlider *)view;
+ if (isTint(slider.minimumTrackTintColor ?: slider.tintColor, view)) [out addObject:@"UISlider track"];
+ }
+ if (isTint(view.backgroundColor, view)) [out addObject:[name stringByAppendingString:@" background"]];
+ for (UIView *child in view.subviews) tintedViews(child, out);
+}
-- (void)after:(double)seconds do:(void (^)(void))block {
+@interface SGHarnessFrameWatch : NSObject
+@property (nonatomic, weak) UIView *root;
+@property (nonatomic) NSInteger frames, tinted;
+@property (nonatomic) CFTimeInterval firstSeen;
+@end
+
+@implementation SGHarnessFrameWatch
+- (void)tick:(CADisplayLink *)link {
+ UIView *block = findBlock(self.root);
+ if (!block.window) return;
+ if (!self.firstSeen) self.firstSeen = link.timestamp;
+ self.frames++;
+ NSMutableArray<NSString *> *found = [NSMutableArray array];
+ tintedViews(block, found);
+ if (found.count) {
+ self.tinted++;
+ NSLog(@"[harness] %p frame %ld: system tint on %@", self, (long)self.frames, [found componentsJoinedByString:@", "]);
+ }
+ if (link.timestamp - self.firstSeen > 1) {
+ [link invalidate];
+ NSLog(@"[harness] %p tint check: %ld of the block's first %ld frames drew something in the system tint", self, (long)self.tinted, (long)self.frames);
+ }
+}
+@end
+
+static void report(_TtC24ContextMenu_InternalImpl25ContextMenuViewController *menu, NSString *when) {
+ UITableView *table = menu.table;
+ NSInteger cells = 0;
+ for (UITableViewCell *cell in table.visibleCells) cells += CGRectIntersectsRect([cell convertRect:cell.bounds toView:menu.view], menu.view.bounds) ? 1 : 0;
+ UIView *block = findBlock(menu.view);
+ NSLog(@"[harness] %@: table %@ content %.0f, %ld of %ld rows on screen, spinner %@, block %@ in the %@",
+ when, NSStringFromCGRect(table.frame), table.contentSize.height, (long)cells, (long)[table numberOfRowsInSection:0],
+ menu.spinner ? (menu.spinner.isAnimating ? @"spinning" : @"stopped") : @"none",
+ block ? NSStringFromCGRect([block convertRect:block.bounds toView:menu.view]) : @"missing",
+ table.tableHeaderView == block ? @"header" : table.tableFooterView == block ? @"footer" : @"nowhere");
+}
+
+#pragma mark - the run
+
+@interface SGHarnessApp : UIResponder <UIApplicationDelegate>
+@end
+
+@implementation SGHarnessApp
+@end
+
+@interface SGHarnessScene : UIResponder <UIWindowSceneDelegate>
+@property (nonatomic, strong) UIWindow *window;
+@end
+
+@implementation SGHarnessScene
+
+static void after(double seconds, dispatch_block_t block) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
}
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {
- sg_speedAllowed = ![NSProcessInfo.processInfo.arguments containsObject:@"nospeed"];
- self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
+static void tapRow(UIViewController *menu) {
+ UIControl *row = (UIControl *)findBlock(menu.view).subviews.firstObject;
+ [row sendActionsForControlEvents:UIControlEventTouchUpInside];
+}
+
+- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)options {
+ sg_speedAllowed = !argument(@"nospeed");
+ self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
NowPlayingHarnessViewController *player = [NowPlayingHarnessViewController new];
self.window.rootViewController = player;
[self.window makeKeyAndVisible];
+ static SGHarnessFrameWatch *watch;
__block _TtC24ContextMenu_InternalImpl25ContextMenuViewController *menu;
- [self after:1 do:^{
+ BOOL loading = argument(@"loading"), stuck = argument(@"stuck");
+ void (^present)(void) = ^{
menu = [_TtC24ContextMenu_InternalImpl25ContextMenuViewController new];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:menu];
navigation.navigationBarHidden = YES;
navigation.sheetPresentationController.detents = @[UISheetPresentationControllerDetent.mediumDetent, UISheetPresentationControllerDetent.largeDetent];
+ watch = [SGHarnessFrameWatch new];
+ watch.root = navigation.view;
+ [[CADisplayLink displayLinkWithTarget:watch selector:@selector(tick:)] addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
[player presentViewController:navigation animated:YES completion:nil];
- }];
- [self after:3 do:^{
- UIControl *row = (UIControl *)findBlock(menu.view).subviews.firstObject;
+ };
+ if (argument(@"open")) {
+ // The block keeps whether it was open for the session: open it on a first menu, close that menu,
+ // and watch a second one come up with the block already open.
+ after(1, present);
+ after(3, ^{ tapRow(menu); });
+ after(4.5, ^{ [player dismissViewControllerAnimated:YES completion:nil]; });
+ after(6, present);
+ after(8, ^{ report(menu, @"reopened"); });
+ return;
+ }
+ after(1, present);
+ if (loading || stuck) {
+ after(3, ^{ report(menu, @"loading"); });
+ if (loading) after(5, ^{ [menu takeRows]; });
+ after(6.5, ^{ report(menu, loading ? @"rows in" : @"still loading"); });
+ if (stuck) return;
+ after(7, ^{ tapRow(menu); });
+ after(8.5, ^{ report(menu, @"block toggled"); });
+ return;
+ }
+ after(3, ^{
NSLog(@"[harness] block %@", findBlock(menu.view));
- [row sendActionsForControlEvents:UIControlEventTouchUpInside];
- }];
- [self after:5 do:^{
+ tapRow(menu);
+ });
+ after(5, ^{
NSArray<UISlider *> *found = sliders(findBlock(menu.view));
found[0].value = 1.27;
[found[0] sendActionsForControlEvents:UIControlEventValueChanged];
@@ -146,12 +342,8 @@ static NSArray<UISlider *> *sliders(UIView *root) {
found[1].value = -3.2;
[found[1] sendActionsForControlEvents:UIControlEventValueChanged];
[found[1] sendActionsForControlEvents:UIControlEventTouchUpInside];
- }];
- [self after:7 do:^{
- UIControl *row = (UIControl *)findBlock(menu.view).subviews.firstObject;
- [row sendActionsForControlEvents:UIControlEventTouchUpInside];
- }];
- return YES;
+ });
+ after(7, ^{ tapRow(menu); });
}
@end
@@ -163,6 +355,6 @@ __attribute__((constructor(101))) static void sgr_harnessDefaults(void) {
int main(int argc, char *argv[]) {
@autoreleasepool {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGRHarnessDelegate.class));
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGHarnessApp.class));
}
}
diff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
index 691422ab..b601c8ae 100644
--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x
+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
@@ -79,7 +79,7 @@ static const NSTimeInterval kSpeedInterval = 0.05;
static NSTimeInterval sg_moreTappedAt;
static BOOL sg_open;
-static char kBlockKey, kDecidedKey, kWatchedKey;
+static char kBlockKey, kDecidedKey, kWatchedKey, kShownAtKey, kRowsInKey;
#pragma mark - the block
@@ -105,6 +105,11 @@ static UIImage *symbol(NSString *name, CGFloat size, UIImageSymbolWeight weight)
return [UIImage systemImageNamed:name withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:size weight:weight]];
}
+// A glyph with its colour drawn in, so it never passes through a tint on its way to the screen.
+static UIImage *paintedSymbol(NSString *name, CGFloat size, UIImageSymbolWeight weight, UIColor *color) {
+ return [symbol(name, size, weight) imageWithTintColor:color renderingMode:UIImageRenderingModeAlwaysOriginal];
+}
+
static UILabel *makeLabel(UIFont *font, UIColor *color) {
UILabel *label = [UILabel new];
label.font = font;
@@ -117,6 +122,9 @@ static UILabel *makeLabel(UIFont *font, UIColor *color) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.titleLabel.font = monospacedDigits(font(UIFontTextStyleSubheadline, UIFontWeightSemibold, UIContentSizeCategoryExtraLarge));
button.tintColor = primary();
+ [button setTitleColor:primary() forState:UIControlStateNormal];
+ [button setTitleColor:[primary() colorWithAlphaComponent:0.4] forState:UIControlStateHighlighted];
+ [button setTitleColor:primary() forState:UIControlStateDisabled];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
button.accessibilityHint = @"Resets it";
[button addTarget:self action:reset forControlEvents:UIControlEventTouchUpInside];
@@ -125,7 +133,7 @@ static UILabel *makeLabel(UIFont *font, UIColor *color) {
// A glyph centred in a box of one size, so both sliders' tracks start and end at the same x.
static UIImage *endImage(NSString *name, CGFloat size) {
- UIImage *glyph = [symbol(name, size, UIImageSymbolWeightMedium) imageWithTintColor:secondary() renderingMode:UIImageRenderingModeAlwaysOriginal];
+ UIImage *glyph = paintedSymbol(name, size, UIImageSymbolWeightMedium, secondary());
CGSize box = CGSizeMake(24, 24);
return [[[UIGraphicsImageRenderer alloc] initWithSize:box] imageWithActions:^(UIGraphicsImageRendererContext *context) {
[glyph drawAtPoint:CGPointMake((box.width - glyph.size.width) / 2, (box.height - glyph.size.height) / 2)];
@@ -169,6 +177,11 @@ static void placeTick(UISlider *slider) {
if (!(self = [super initWithFrame:frame])) return nil;
self.clipsToBounds = YES;
self.backgroundColor = UIColor.clearColor;
+ // Nothing here draws in the tint: every colour is set on the view that draws it, and the glyphs have
+ // theirs painted in rather than tinted. The row came up in the system blue for a moment as the sheet
+ // appeared on the phone (issue #68), which is the tint a view inherits when nothing up the sheet sets
+ // one. The block's own tint is white as well, for whatever UIKit draws in it (the sliders' parts).
+ self.tintColor = primary();
_row = [UIControl new];
[_row addTarget:self action:@selector(toggle) forControlEvents:UIControlEventTouchUpInside];
@@ -178,15 +191,13 @@ static void placeTick(UISlider *slider) {
_row.accessibilityTraits = UIAccessibilityTraitButton;
[self addSubview:_row];
- _icon = [[UIImageView alloc] initWithImage:symbol(@"slider.horizontal.3", 20, UIImageSymbolWeightRegular)];
- _icon.tintColor = secondary();
+ _icon = [[UIImageView alloc] initWithImage:paintedSymbol(@"slider.horizontal.3", 20, UIImageSymbolWeightRegular, secondary())];
_icon.contentMode = UIViewContentModeCenter;
_title = makeLabel(font(UIFontTextStyleBody, UIFontWeightRegular, UIContentSizeCategoryExtraLarge), primary());
_title.text = @"Speed and pitch";
_summary = makeLabel(monospacedDigits(font(UIFontTextStyleSubheadline, UIFontWeightRegular, UIContentSizeCategoryExtraLarge)), secondary());
_summary.textAlignment = NSTextAlignmentRight;
- _chevron = [[UIImageView alloc] initWithImage:symbol(@"chevron.down", 13, UIImageSymbolWeightSemibold)];
- _chevron.tintColor = secondary();
+ _chevron = [[UIImageView alloc] initWithImage:paintedSymbol(@"chevron.down", 13, UIImageSymbolWeightSemibold, secondary())];
_chevron.contentMode = UIViewContentModeCenter;
for (UIView *view in @[_icon, _title, _summary, _chevron]) {
view.userInteractionEnabled = NO;
@@ -280,8 +291,6 @@ static NSString *pitchText(float pitch) {
}];
_speedValue.enabled = speedAllowed && _shownSpeed != 1;
_pitchValue.enabled = pitchAvailable && _shownPitch != 0;
- [_speedValue setTitleColor:primary() forState:UIControlStateDisabled];
- [_pitchValue setTitleColor:primary() forState:UIControlStateDisabled];
_speed.accessibilityValue = speedAllowed ? speedText(_shownSpeed) : @"Unavailable";
_pitch.accessibilityValue = _shownPitch == 0 ? @"Original pitch" : [NSString stringWithFormat:@"%.0f semitones %@", fabsf(_shownPitch), _shownPitch > 0 ? @"up" : @"down"];
@@ -466,6 +475,63 @@ static BOOL isPlayerMenu(UIViewController *menu) {
return ours;
}
+#pragma mark - Spotify's rows
+
+// The sheet keeps its spinner up until Spotify's rows are in, and they are in when every item factory
+// has answered or run out of time: ContextMenuItemFactory holds a timer, and the timeout is the remote
+// config's ios-feature-contextmenu-platform.timeout (SPTContextMenu_InternalImplProperties reads it
+// between 1 and 60 s, 10 when the server says nothing). The block takes no part in that: it goes into
+// the table's header once and stays, and a sheet that gets its rows seconds later shows them under it
+// (harness/menu `loading`). So a menu that waits is timed from here, to tell a wait on Spotify's
+// factories from a main thread kept busy: each check says how late it ran.
+static NSInteger rowCount(UITableView *table) {
+ NSInteger rows = 0;
+ for (NSInteger section = 0; section < table.numberOfSections; section++) rows += [table numberOfRowsInSection:section];
+ return rows;
+}
+
+static BOOL spinning(UIView *view, int depth) {
+ if ([view isKindOfClass:UIActivityIndicatorView.class]) return ((UIActivityIndicatorView *)view).isAnimating && !view.isHidden && view.alpha > 0.01;
+ if (depth > 6) return NO;
+ for (UIView *child in view.subviews) {
+ if (spinning(child, depth + 1)) return YES;
+ }
+ return NO;
+}
+
+// Once, when the rows are first seen, and said only when they were late.
+static void noteRows(UIViewController *menu, UITableView *table) {
+ NSNumber *shownAt = objc_getAssociatedObject(menu, &kShownAtKey);
+ if (!shownAt || objc_getAssociatedObject(menu, &kRowsInKey) || !table || rowCount(table) == 0) return;
+ objc_setAssociatedObject(menu, &kRowsInKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ NSTimeInterval after = CACurrentMediaTime() - shownAt.doubleValue;
+ if (after > 0.5) SGLog(@"speed and pitch: Spotify's rows came in %.1f s after the menu appeared", after);
+}
+
+static void watchRows(UIViewController *menu) {
+ if (objc_getAssociatedObject(menu, &kShownAtKey)) return;
+ objc_setAssociatedObject(menu, &kShownAtKey, @(CACurrentMediaTime()), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ UITableView *table = findTable(menu.view, 0);
+ if (table && rowCount(table)) {
+ objc_setAssociatedObject(menu, &kRowsInKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return;
+ }
+ __weak UIViewController *weakMenu = menu;
+ for (NSNumber *wait in @[@2, @6, @15, @40]) {
+ CFTimeInterval due = CACurrentMediaTime() + wait.doubleValue;
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(wait.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ UIViewController *shown = weakMenu;
+ if (!shown.viewIfLoaded.window || objc_getAssociatedObject(shown, &kRowsInKey)) return;
+ UITableView *rows = findTable(shown.view, 0);
+ noteRows(shown, rows);
+ if (objc_getAssociatedObject(shown, &kRowsInKey)) return;
+ SGLog(@"speed and pitch: no rows of Spotify's %@ s after the menu appeared (this check ran %.2f s late), spinner %@, table %.0fx%.0f holding %.0f",
+ wait, CACurrentMediaTime() - due, spinning(shown.view, 0) ? @"spinning" : @"not spinning",
+ rows.bounds.size.width, rows.bounds.size.height, rows.contentSize.height);
+ });
+ }
+}
+
static void install(UIViewController *menu) {
UIView *root = menu.viewIfLoaded;
if (!root || !isPlayerMenu(menu)) return;
@@ -504,8 +570,14 @@ static void install(UIViewController *menu) {
[table invalidateIntrinsicContentSize];
return;
}
+ noteRows(menu, table);
// Spotify replaced the view, or the table changed width: put it back at the table's width.
UIView *placed = block.inFooter ? table.tableFooterView : table.tableHeaderView;
+ if (placed != block) {
+ static int logged;
+ if (logged++ < 3) SGLog(@"speed and pitch: the table's %@ became %@, speed and pitch put back", block.inFooter ? @"footer" : @"header",
+ placed ? NSStringFromClass(placed.class) : @"nothing");
+ }
if (placed != block || fabs(block.frame.size.width - width) > 0.5) {
block.frame = CGRectMake(0, block.frame.origin.y, width, [SGSpeedPitchView heightOpen:sg_open]);
if (block.inFooter) table.tableFooterView = block;
@@ -524,6 +596,7 @@ static void install(UIViewController *menu) {
%orig;
SGSpeedPitchView *block = objc_getAssociatedObject(self, &kBlockKey);
[block refresh];
+ if (block) watchRows((UIViewController *)self);
}
%end