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 player's lyrics turn with the phone onto a landscape screen
My-Name-Is-Jeffe1c821a11e52
diff --git a/harness/player/README.md b/harness/player/README.mdindex 01a92987..223f8e13 100644--- a/harness/player/README.md+++ b/harness/player/README.md@@ -32,6 +32,11 @@ come late, out of order, or not at all.Kit's last look), two skips come in a row with the older picture answering last, and one track playsoffline. Each step checks by colour that the Kit and the field show that track's picture, and the logends with `artwork checks: n of 4 right -- PASS` or `FAIL`. Before the fix it read 1 of 4.+- `landscape` turns the lyrics sideways at 3 s, puts a line's meanings over them (the real+ `MeaningSheet.m`) at 4 s and takes them away at 9, then pauses at 14.5 and resumes at 15.5. Each step+ logs whether the controls are up and whether a touch on the lines lands on the lines or on the shield+ that brings the controls back, with `ok` or `WRONG`. At 6 s it logs the sheet's frame: a card inside+ the safe area with a grabber, where the sheet before it covered the whole screen.`HARNESS_VOLUME=0` leaves out the volume row that the phone has and the tree does not.diff --git a/harness/player/build.sh b/harness/player/build.shindex d0fc661f..b7f6ba4f 100755--- a/harness/player/build.sh+++ b/harness/player/build.sh@@ -6,7 +6,7 @@ OUT=${OUT:-$(dirname "$0")/build}rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/PlayerHarness.app"for f in Redesigned/Player/PlayerLyrics.x Redesigned/Player/PlayerArtwork.x Redesigned/Player/PlayerFooter.x \- Redesigned/Player/PlayerScroll.x Redesigned/Player/PlayerField.x Redesigned/Player/PlayerMotion.x Redesigned/Kit/SGRBridges.x; do+ Redesigned/Player/PlayerScroll.x Redesigned/Player/PlayerField.x Redesigned/Player/PlayerMotion.x Redesigned/Player/PlayerLandscape.x Redesigned/Kit/SGRBridges.x; doname=$(basename "$f" .x)"$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$name.m"done@@ -22,7 +22,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \"$SRC"/Redesigned/Kit/SGRedesign.m \- "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \-o "$OUT/PlayerHarness.app/PlayerHarness"diff --git a/harness/player/main.m b/harness/player/main.mindex 283a247d..fdb9db92 100644--- a/harness/player/main.m+++ b/harness/player/main.m@@ -9,6 +9,8 @@// scroll the list moved up and down in code; the log says whether it stayed at its top// artwork issue #58: tracks change while the covers on screen and the picture server lag behind,// checked by colour at the end of each step; the log says PASS or FAIL+// landscape the landscape lyrics at 3 s, a line's meanings over them, a pause and a resume; each+// step logs whether the controls are up and what a touch on the lines lands on// HARNESS_VOLUME=0 leaves out the volume row the phone has (trees/clean/player/01.txt has none).#import <UIKit/UIKit.h>#import <objc/runtime.h>@@ -16,6 +18,7 @@#import "Redesigned/Player/Player.h"#import "Redesigned/Kit/SGRBridges.h"#import "Redesigned/Kit/SGRField.h"+#import "Redesigned/Lyrics/MeaningSheet.h"void SGRHarnessPlayFrom(NSInteger ms);void SGRHarnessSetTrack(NSString *uri, NSString *imageURI, BOOL paused);@@ -486,6 +489,7 @@ static void loadLyrics(void) {if ([scenario() isEqualToString:@"artwork"]) [self runArtworkChecks];else if ([scenario() isEqualToString:@"look"]) [self runLook];else if ([scenario() isEqualToString:@"scroll"]) [self runScrollChecks];+ else if ([scenario() isEqualToString:@"landscape"]) [self runLandscape];// Opened, closed and opened again, so a screenshot can be taken of each state and of the move itself.else for (NSNumber *at in @[@2, @6, @10]) {dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(at.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{@@ -542,6 +546,58 @@ static void after(NSTimeInterval seconds, dispatch_block_t block) {[_bar viewDidLayoutSubviews];}+#pragma mark - landscape++static UIViewController *landscapeScreen(void) {+ for (UIWindow *window in UIApplication.sharedApplication.connectedScenes.anyObject ? ((UIWindowScene *)UIApplication.sharedApplication.connectedScenes.anyObject).windows : @[]) {+ if (!window.hidden && [NSStringFromClass(window.rootViewController.class) isEqualToString:@"SGRLandscapeLyricsController"]) return window.rootViewController;+ }+ return nil;+}++// What a touch on the lines lands on, and whether the controls are up.+static void logLandscape(NSString *step, NSString *want) {+ UIViewController *screen = landscapeScreen();+ UIView *view = screen.view, *shield = [screen valueForKey:@"shield"];+ CGPoint onLine = CGPointMake(view.bounds.size.width * 0.7, view.bounds.size.height * 0.5);+ UIView *hit = [view hitTest:onLine withEvent:nil];+ CGFloat controls = [[screen valueForKey:@"controls"] alpha];+ NSString *got = hit == shield ? @"shield" : @"lines";+ NSLog(@"[harness] landscape %@: controls %.0f, a touch on the lines lands on %@ (%@) -- want %@: %@", step, controls,+ got, NSStringFromClass(hit.class), want, [got isEqualToString:want] ? @"ok" : @"WRONG");+}++// The landscape lyrics as a turned phone shows them: a line's meanings over them as a card on the bottom+// edge, the controls staying up behind the sheet and fading once it is gone, the shield taking the touch+// that brings them back, and a pause and a resume from elsewhere starting the clock again.+- (void)runLandscape {+ after(3, ^{ SGRPlayerShowLandscape(YES); });+ after(4, ^{+ SGLyricsMeaning *meaning = [SGLyricsMeaning new];+ meaning.author = SGLyricsMeaningByArtist;+ meaning.body = @"A line of the harness's song, explained at the length Genius explains one, so the card has a body to show and to wrap.";+ meaning.url = @"https://genius.com";+ SGRShowMeanings(@"Harness line", @[meaning]);+ });+ after(6, ^{+ UIViewController *sheet = landscapeScreen().presentedViewController;+ UIView *window = sheet.view.window;+ NSLog(@"[harness] landscape meanings: %@ %@ in a window %@, height class %ld, edge attached %d",+ NSStringFromClass(sheet.class), NSStringFromCGRect([sheet.view convertRect:sheet.view.bounds toView:window]),+ NSStringFromCGSize(window.bounds.size), (long)sheet.traitCollection.verticalSizeClass,+ sheet.sheetPresentationController.prefersEdgeAttachedInCompactHeight);+ });+ after(8.5, ^{ logLandscape(@"with the sheet up past the rest", @"lines"); });+ after(9, ^{ [landscapeScreen() dismissViewControllerAnimated:YES completion:nil]; });+ after(14, ^{ logLandscape(@"rested after the sheet went", @"shield"); });+ after(14.5, ^{ SGRHarnessSetTrack(@"spotify:track:harnessA", imageURI(@"aaaa"), YES); });+ after(15, ^{ logLandscape(@"paused", @"lines"); });+ after(15.5, ^{ SGRHarnessSetTrack(@"spotify:track:harnessA", imageURI(@"aaaa"), NO); });+ after(17, ^{ logLandscape(@"just resumed", @"lines"); });+ after(21, ^{ logLandscape(@"rested after the resume", @"shield"); });+ after(22, ^{ SGRPlayerShowLandscape(NO); });+}+- (void)check:(NSString *)step want:(NSString *)want {NSString *uri = nil;UIImage *artwork = SGRNowPlayingArtwork(&uri, NULL);diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 166579d9..44bac3f9 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -121,8 +121,17 @@ void SGKaraokeSeek(NSInteger ms) {}void SGRHarnessPlayFrom(NSInteger ms) { SGKaraokeSeek(ms); }-// Line meanings: Genius is not asked in the harness.+// Line meanings: Genius is not asked in the harness. The sheet itself is the real one (MeaningSheet.m).#import "Shared/LyricsMeanings/Meanings.h"+@implementation SGLyricsMeaning+@endvoid SGLyricsMeaningsFor(NSString *trackID, NSArray<SGKaraokeLine *> *lines,void (^done)(NSDictionary<NSNumber *, NSArray<SGLyricsMeaning *> *> *byLine)) {}-void SGRShowMeanings(NSString *lineText, NSArray<SGLyricsMeaning *> *meanings) {}++// Gemini translation and the settings framework's top controller: not part of the harness.+#import "Shared/LyricsTranslation/LyricsTranslation.h"+BOOL SGGeminiKeySet(void) { return NO; }+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; }diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex 04e74f90..b8579c2f 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -81,6 +81,7 @@ static UIViewController *lyricsPage(void) {if (redesigned) {[sections addObject:SGSection(@"Display", @[SGLyricsWordTimingRow(), SGRLyricsTextSizesRow(), SGLyricsTranslationLanguageRow(), SGLyricsMeaningsRow(),SGSwitchRow(@"Hide the controls", @"A few seconds after the last touch, the lyrics take the whole player", SGRKeyLyricsAutoHide),+ SGSwitchRow(@"Landscape lyrics", @"Turn the phone with the lyrics open", SGRKeyLyricsLandscape),SGGeminiKeyRow()])];}[sections addObject:SGSection(nil, more)];diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex a515f37b..e2584773 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -71,6 +71,11 @@ void SGRPlayerLyricsChanged(void);// whole player (PlayerLyrics.x). On until switched off; a scroll through the lines hides them either way.#define SGRKeyLyricsAutoHide @"spotifyglass.redesign.lyrics.autoHide"+// 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"+void SGRPlayerShowLandscape(BOOL show);+// The animated artwork follows the lyrics: blurred behind them (PlayerMotion.x).void SGRPlayerMotionLyricsChanged(void);diff --git a/tweak/Sources/Redesigned/Player/PlayerLandscape.x b/tweak/Sources/Redesigned/Player/PlayerLandscape.xnew file mode 100644index 00000000..cb7e21db--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerLandscape.x@@ -0,0 +1,385 @@+// Player redesign: the lyrics turn sideways with the phone onto a landscape screen of their own. The cover+// is on the left with the title, the artist and the controls under it, and the lines are on the right.+// The controls fade after a few seconds without a touch and come back at a tap, as in the player: the+// tap that brings them back lands on a clear shield over the screen, so it never seeks. The button beside+// the title turns the screen back to portrait, as VoiceOver's escape does, for a phone held flat or on its+// side; the screen stays shut then until the phone has stood upright again.+//+// Spotify's iPhone Info.plist allows portrait only, and UIKit asks the app delegate's+// -application:supportedInterfaceOrientationsForWindow: in its place where there is one. So the delegate+// answers landscape for this screen's own window and portrait for every other, and the scene is asked to+// turn while the window is up. Spotify's own windows never turn.+#import <objc/runtime.h>+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Redesigned/Lyrics/SGRKaraokeView.h"+#import "Shared/Lyrics/Lyrics.h"+#import "Shared/Player/PlayerState.h"+#import "Player.h"++static const CGFloat kSide = 32, kCoverGap = 16, kControlSide = 44, kColumnShare = 0.38;+static const NSTimeInterval kLandscapeRest = 4;++static UIWindow *sg_window;+// Shut from the screen: turning the phone again does not reopen it until it has stood upright.+static BOOL sg_shut;++#pragma mark - the screen++@interface SGRLandscapeLyricsController : UIViewController <SGPlayerStateObserver>+@end++@implementation SGRLandscapeLyricsController {+ SGRArtworkField *_field;+ UIImageView *_cover;+ UILabel *_title, *_artist;+ UIStackView *_controls;+ UIButton *_play, *_close;+ UIView *_stage; // the lines' own view: the karaoke view dims every sibling it has+ SGRKaraokeView *_lyrics;+ NSTimer *_rest;+ UITapGestureRecognizer *_hide; // only while the controls are up+ UIView *_shield; // only while they are not: the touch that brings them back+}++// Portrait once the screen is on its way out, or the scene could not turn back while it fades.+- (UIInterfaceOrientationMask)supportedInterfaceOrientations {+ return sg_window.rootViewController == self ? UIInterfaceOrientationMaskLandscape : UIInterfaceOrientationMaskPortrait;+}++- (BOOL)prefersStatusBarHidden {+ return YES;+}++- (BOOL)prefersHomeIndicatorAutoHidden {+ return YES;+}++// A glyph in a 44pt square, so the touch is as large as the default control whatever the glyph's size.+static UIButton *controlButton(NSString *symbol, CGFloat size, NSString *label, SEL action, id target) {+ UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];+ [button setImage:[UIImage systemImageNamed:symbol withConfiguration:+ [UIImageSymbolConfiguration configurationWithPointSize:size weight:UIImageSymbolWeightBold]] forState:UIControlStateNormal];+ button.tintColor = UIColor.whiteColor;+ button.accessibilityLabel = label;+ [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];+ [button.widthAnchor constraintEqualToConstant:kControlSide].active = YES;+ [button.heightAnchor constraintEqualToConstant:kControlSide].active = YES;+ return button;+}++// The title and the artist at the phone's text size, capped where the column still holds a cover.+- (void)applyFonts {+ _title.font = SGRFont(UIFontTextStyleTitle3, UIFontWeightBold, UIContentSizeCategoryExtraExtraExtraLarge);+ _artist.font = SGRFont(UIFontTextStyleCallout, UIFontWeightRegular, UIContentSizeCategoryExtraExtraExtraLarge);+}++- (void)traitCollectionDidChange:(UITraitCollection *)previous {+ [super traitCollectionDidChange:previous];+ [self applyFonts];+ [self.view setNeedsLayout];+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.view.backgroundColor = UIColor.blackColor;++ // The player's own field behind the screen, so the colours carry over from the portrait player.+ _field = [[SGRArtworkField alloc] initWithFrame:self.view.bounds];+ _field.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ _field.showsBackdrop = YES;+ _field.fluid = YES;+ NSString *identity = nil;+ UIImage *art = SGRNowPlayingArtwork(NULL, &identity);+ if (art) [_field setArtwork:art identity:identity animated:NO];+ [self.view addSubview:_field];++ _cover = [UIImageView new];+ _cover.contentMode = UIViewContentModeScaleAspectFill;+ _cover.clipsToBounds = YES;+ _cover.layer.cornerRadius = SGRRadiusArtwork;+ _cover.layer.cornerCurve = kCACornerCurveContinuous;+ _cover.image = art;+ [self.view addSubview:_cover];++ _title = [UILabel new];+ _title.textColor = UIColor.whiteColor;+ _artist = [UILabel new];+ _artist.textColor = [UIColor colorWithWhite:1 alpha:0.6];+ [self applyFonts];+ [self.view addSubview:_title];+ [self.view addSubview:_artist];+ // Where the Music app keeps a song's ⋯: the way back to the player, for a phone that is not turned back.+ _close = controlButton(@"arrow.down.right.and.arrow.up.left", 17, @"Exit full screen", @selector(turnBack), self);+ [self.view addSubview:_close];++ _play = controlButton(@"pause.fill", 30, @"Pause", @selector(togglePlay), self);+ _controls = [[UIStackView alloc] initWithArrangedSubviews:@[+ controlButton(@"backward.fill", 24, @"Previous track", @selector(previous), self), _play,+ controlButton(@"forward.fill", 24, @"Next track", @selector(next), self),+ ]];+ _controls.distribution = UIStackViewDistributionEqualSpacing;+ _controls.alignment = UIStackViewAlignmentCenter;+ [self.view addSubview:_controls];++ _stage = [UIView new];+ [self.view addSubview:_stage];+ _lyrics = [[SGRKaraokeView alloc] initWithFrame:CGRectZero];+ _lyrics.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [_stage addSubview:_lyrics];+ __weak SGRLandscapeLyricsController *weakSelf = self;+ _lyrics.browsingBegan = ^{ [weakSelf rest]; };++ _hide = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rest)];+ [self.view addGestureRecognizer:_hide];+ _shield = [[UIView alloc] initWithFrame:self.view.bounds];+ _shield.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ _shield.accessibilityElementsHidden = YES;+ [_shield addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(wake)]];+ [_shield addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(wake)]];+ SGAddPlayerStateObserver(self);+ [self playerStateDidChange:SGPlayerState()];+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(artworkChanged)+ name:SGRNowPlayingArtworkDidChangeNotification object:nil];+ // The shield is hidden from VoiceOver, so turning it on brings the controls back and keeps them.+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(wake)+ name:UIAccessibilityVoiceOverStatusDidChangeNotification object:nil];+}++- (void)dealloc {+ [NSNotificationCenter.defaultCenter removeObserver:self];+ [_rest invalidate];+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ CGRect safe = UIEdgeInsetsInsetRect(self.view.bounds, self.view.safeAreaInsets);+ CGFloat column = round(safe.size.width * kColumnShare);+ CGFloat left = CGRectGetMinX(safe) + kSide;+ CGFloat titleHeight = ceil(_title.font.lineHeight), artistHeight = ceil(_artist.font.lineHeight);+ CGFloat textHeight = MAX(titleHeight + artistHeight, kControlSide), controlsHeight = kControlSide;+ CGFloat side = MIN(column - kSide, safe.size.height - 2 * kSide - textHeight - controlsHeight - 2 * kCoverGap);+ CGFloat top = CGRectGetMidY(safe) - (side + kCoverGap + textHeight + kCoverGap + controlsHeight) / 2;+ _cover.frame = CGRectMake(left, top, side, side);+ // The close button at the text's trailing end, its glyph (about 20pt in the 44pt square) at the cover's edge.+ CGFloat textTop = CGRectGetMaxY(_cover.frame) + kCoverGap;+ _close.frame = CGRectMake(left + side - kControlSide + 12, textTop + (textHeight - kControlSide) / 2, kControlSide, kControlSide);+ _title.frame = CGRectMake(left, textTop + (textHeight - titleHeight - artistHeight) / 2, side - kControlSide, titleHeight);+ _artist.frame = CGRectMake(left, CGRectGetMaxY(_title.frame), side - kControlSide, artistHeight);+ _controls.frame = CGRectMake(left + side * 0.1, textTop + textHeight + kCoverGap, side * 0.8, controlsHeight);+ CGFloat linesLeft = left + side + kSide;+ _stage.frame = CGRectMake(linesLeft, CGRectGetMinY(safe), CGRectGetMaxX(safe) - linesLeft, safe.size.height);+ _lyrics.frame = _stage.bounds;+}++- (void)viewDidAppear:(BOOL)animated {+ [super viewDidAppear:animated];+ [self restartRest];+}++// The window comes up clear and fades in as the scene turns, so the screen is never seen laid out upright.+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];+ UIWindow *window = self.view.window;+ if (!window || window != sg_window || size.width <= size.height) return;+ [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {+ window.alpha = 1;+ } completion:nil];+}++- (void)artworkChanged {+ NSString *identity = nil;+ UIImage *art = SGRNowPlayingArtwork(NULL, &identity);+ if (!art) return;+ // On the field's clock, so the cover and the colours behind it change as one.+ UIImageView *cover = _cover;+ [UIView transitionWithView:cover duration:SGRCrossfade options:UIViewAnimationOptionTransitionCrossDissolve+ animations:^{ cover.image = art; } completion:nil];+ [_field setArtwork:art identity:identity animated:YES];+}++- (void)playerStateDidChange:(SPTPlayerState *)state {+ if (!state) return;+ _title.text = state.track.trackTitle;+ _artist.text = state.track.artistName;+ [_play setImage:[UIImage systemImageNamed:state.isPaused ? @"play.fill" : @"pause.fill" withConfiguration:+ [UIImageSymbolConfiguration configurationWithPointSize:30 weight:UIImageSymbolWeightBold]] forState:UIControlStateNormal];+ _play.accessibilityLabel = state.isPaused ? @"Play" : @"Pause";+ _field.motionHeld = state.isPaused;+ // A pause brings the controls back and keeps them; playing again, from here or anywhere, starts the+ // clock. The tap on the play button cannot: the state saying so arrives a beat after it.+ if (state.isPaused) [self setControlsShown:YES];+ else if (!_rest && !_shield.superview) [self restartRest];+}++#pragma mark - controls++- (id<SPTPlayer>)player {+ id player = SGKaraokePlayer();+ return [player conformsToProtocol:@protocol(SPTPlayer)] || [player respondsToSelector:@selector(pause:)] ? player : nil;+}++- (void)togglePlay {+ id<SPTPlayer> player = self.player;+ if (SGPlayerState().isPaused) [player resume:nil];+ else [player pause:nil];+ [self restartRest];+}++- (void)previous {+ [self.player skipToPreviousTrackWithOptions:nil];+ [self restartRest];+}++- (void)next {+ [self.player skipToNextTrackWithOptions:nil];+ [self restartRest];+}++- (void)turnBack {+ sg_shut = YES;+ SGRPlayerShowLandscape(NO);+}++// VoiceOver's two-finger scrub.+- (BOOL)accessibilityPerformEscape {+ [self turnBack];+ return YES;+}++// The lines on their own, unless VoiceOver needs the controls to be there.+- (void)rest {+ if (!UIAccessibilityIsVoiceOverRunning()) [self setControlsShown:NO];+}++- (void)wake {+ [self setControlsShown:YES];+}++- (void)setControlsShown:(BOOL)shown {+ [_rest invalidate];+ _rest = nil;+ _hide.enabled = shown;+ if (shown) [_shield removeFromSuperview];+ else if (!_shield.superview) {+ _shield.frame = self.view.bounds;+ [self.view addSubview:_shield];+ }+ SGRAnimate(SGRMotionFade, ^{+ for (UIView *view in @[self->_controls, self->_close, self->_title, self->_artist]) view.alpha = shown ? 1 : 0;+ self->_lyrics.extrasHidden = !shown;+ }, nil);+ if (shown) [self restartRest];+}++- (void)restartRest {+ [_rest invalidate];+ _rest = nil;+ if (!SGEnabled(SGRKeyLyricsAutoHide) || SGPlayerState().isPaused || UIAccessibilityIsVoiceOverRunning()) return;+ __weak SGRLandscapeLyricsController *weakSelf = self;+ _rest = [NSTimer scheduledTimerWithTimeInterval:kLandscapeRest repeats:NO block:^(NSTimer *timer) {+ // A sheet over the lines (a line's meanings) keeps them up, and the clock runs again behind it.+ SGRLandscapeLyricsController *strongSelf = weakSelf;+ if (strongSelf.presentedViewController) [strongSelf restartRest];+ else [strongSelf rest];+ }];+}++@end++#pragma mark - turning++static UIInterfaceOrientationMask (*sg_origOrientations)(id, SEL, UIApplication *, UIWindow *);++static UIInterfaceOrientationMask orientationsFor(id self, SEL _cmd, UIApplication *application, UIWindow *window) {+ if (window && window == sg_window) return UIInterfaceOrientationMaskLandscape;+ return sg_origOrientations ? sg_origOrientations(self, _cmd, application, window) : UIInterfaceOrientationMaskPortrait;+}++// The delegate's own answer stays for every window but the landscape one; one that has none answers+// portrait, which is what the Info.plist said.+static void answerForOrientations(void) {+ static BOOL done;+ id delegate = UIApplication.sharedApplication.delegate;+ if (done || !delegate) return;+ done = YES;+ SEL selector = @selector(application:supportedInterfaceOrientationsForWindow:);+ Method method = class_getInstanceMethod([delegate class], selector);+ if (method) sg_origOrientations = (void *)method_setImplementation(method, (IMP)orientationsFor);+ else class_addMethod([delegate class], selector, (IMP)orientationsFor, "Q@:@@");+ SGLog(@"redesign player: landscape lyrics answer for %@ (%@)", NSStringFromClass([delegate class]), method ? @"its own answer kept" : @"portrait otherwise");+}++// A landscape window still clear when no turn is coming to fade it in.+static void reveal(UIWindow *window) {+ if (window && window == sg_window && window.alpha < 1) SGRAnimate(SGRMotionFade, ^{ window.alpha = 1; }, nil);+}++static void requestOrientations(UIWindowScene *scene, UIInterfaceOrientationMask mask) {+ __weak UIWindow *window = sg_window;+ if (@available(iOS 16.0, *)) {+ UIWindowSceneGeometryPreferencesIOS *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:mask];+ [scene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError *error) {+ SGLog(@"redesign player: the scene did not turn: %@", error.localizedDescription);+ dispatch_async(dispatch_get_main_queue(), ^{ reveal(window); });+ }];+ }+}++void SGRPlayerShowLandscape(BOOL show) {+ UIWindowScene *scene = (UIWindowScene *)UIApplication.sharedApplication.connectedScenes.anyObject;+ if (![scene isKindOfClass:UIWindowScene.class]) return;+ if (show && !sg_window) {+ answerForOrientations();+ sg_window = [[UIWindow alloc] initWithWindowScene:scene];+ sg_window.windowLevel = UIWindowLevelNormal + 1;+ // The window is the mod's own, so what it presents (Sing's alerts, a line's meanings) is dark too.+ sg_window.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ sg_window.alpha = 0;+ sg_window.rootViewController = [SGRLandscapeLyricsController new];+ [sg_window makeKeyAndVisible];+ requestOrientations(scene, UIInterfaceOrientationMaskLandscape);+ if (UIInterfaceOrientationIsLandscape(scene.interfaceOrientation)) reveal(sg_window);+ SGLog(@"redesign player: the lyrics turn sideways");+ } else if (!show && sg_window) {+ UIWindow *window = sg_window;+ sg_window = nil;+ window.userInteractionEnabled = NO;+ // A sheet up over the lines (a line's meanings) goes with them, or it would be left on a hidden window.+ [window.rootViewController dismissViewControllerAnimated:NO completion:nil];+ if (@available(iOS 16.0, *)) [window.rootViewController setNeedsUpdateOfSupportedInterfaceOrientations];+ requestOrientations(scene, UIInterfaceOrientationMaskPortrait);+ // Faded out as the scene turns back; the player is key again once it is gone, unless the lines came+ // back meanwhile.+ SGRAnimate(SGRMotionFade, ^{ window.alpha = 0; }, ^(BOOL finished) {+ window.hidden = YES;+ if (sg_window) return;+ for (UIWindow *other in scene.windows) {+ if (other != window && !other.hidden && other.windowLevel == UIWindowLevelNormal) {+ [other makeKeyWindow];+ break;+ }+ }+ });+ SGLog(@"redesign player: the lyrics turn back");+ }+}++static void orientationChanged(void) {+ UIDeviceOrientation orientation = UIDevice.currentDevice.orientation;+ if (UIDeviceOrientationIsLandscape(orientation)) {+ if (!sg_shut && SGEnabled(SGRKeyLyricsLandscape) && SGRPlayerLyricsOpen()) SGRPlayerShowLandscape(YES);+ } else if (orientation == UIDeviceOrientationPortrait) {+ sg_shut = NO;+ SGRPlayerShowLandscape(NO);+ }+}++%ctor {+ if (!SGRedesignedUI()) return;+ dispatch_async(dispatch_get_main_queue(), ^{+ [UIDevice.currentDevice beginGeneratingDeviceOrientationNotifications];+ [NSNotificationCenter.defaultCenter addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil+ usingBlock:^(NSNotification *note) { orientationChanged(); }];+ });+}diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex 396c0009..4e838f0a 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -84,6 +84,7 @@ static UIView *sg_shield; // over the player while alone: the_thumb = [[UIView alloc] initWithFrame:CGRectZero];// A tap on the cover beside the lines brings the full player back.[_thumb addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sgr_thumbTapped)]];+ _thumb.isAccessibilityElement = YES;_thumb.accessibilityLabel = @"Show the player";_thumb.accessibilityTraits = UIAccessibilityTraitButton;_cover = [[UIImageView alloc] initWithFrame:CGRectZero];@@ -106,8 +107,8 @@ static UIView *sg_shield; // over the player while alone: the- (UIImageView *)cover { return _cover; }- (UIView *)stage { return _stage; }-// The lines seek when they are tapped and the thumbnail takes no touches, so everywhere else the-// overlay would only swallow them: a view that takes touches does, even with nothing on it.+// The lines seek when they are tapped and the thumbnail brings the player back, so everywhere else the+// overlay would only swallow touches: a view that takes them does, even with nothing on it.//// What it hands them to instead is the title row. Translated to the top of the player it is drawn well// outside the stack view it is arranged in, and UIKit stops looking at a view whose bounds the touch is@@ -399,7 +400,9 @@ static void setAlone(BOOL alone, BOOL animated) {UIView *host = sg_host;if (alone == sg_alone || !host || (alone && !sg_open)) return;SGRLyricsLayout l = layoutIn(host);- if (!l.ok) return;+ // Going alone needs somewhere to put the lines. Coming back never waits for it: the controls and the+ // touches under the shield are given back even when the player can no longer be measured.+ if (alone && !l.ok) return;sg_alone = alone;if (alone) {[sg_rest invalidate];@@ -410,8 +413,10 @@ static void setAlone(BOOL alone, BOOL animated) {NSArray<UIView *> *controls = controlViews();void (^apply)(void) = ^{if (overlay.superview) {- place(overlay, host, l);- overlay.thumb.transform = thumbTransform(l);+ if (l.ok) {+ place(overlay, host, l);+ overlay.thumb.transform = thumbTransform(l);+ }overlay.thumb.alpha = alone ? 0 : 1;overlay.lyrics.extrasHidden = alone;}@@ -462,7 +467,10 @@ static void setOpen(BOOL open, BOOL animated) {overlay.cover.image = SGRNowPlayingArtwork(NULL, NULL);overlay.stage.alpha = 0;overlay.stage.transform = CGAffineTransformMakeScale(kLyricsEnterScale, kLyricsEnterScale);- overlay.lyrics.browsingBegan = ^{ setAlone(YES, YES); };+ // Not under VoiceOver, whose user could not reach the shield, nor under a sheet.+ overlay.lyrics.browsingBegan = ^{+ if (!UIAccessibilityIsVoiceOverRunning() && !sg_player.presentedViewController) setAlone(YES, YES);+ };// Spotify's cover goes the moment the redesign's own takes its place: the same picture at the// same size with the same corners, so there is nothing to see in the swap. Coming back it waits// for the thumbnail to land on it, or the two would be on screen at once, one of them half size.@@ -503,6 +511,8 @@ static void setOpen(BOOL open, BOOL animated) {else {[sg_rest invalidate];sg_rest = nil;+ // The landscape screen shows these lines, so it goes with them (a track without lyrics came on).+ SGRPlayerShowLandscape(NO);}SGLog(@"redesign player: lyrics %@, thumbnail %.0fx%.0f at %.0f,%.0f, title row up %.0f and right %.0f, lines %.0fx%.0f",open ? @"up" : @"away", l.thumb.size.width, l.thumb.size.height, l.thumb.origin.x, l.thumb.origin.y,@@ -654,6 +664,11 @@ static SGRPlayerLyricsWatcher *sg_watcher;[NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {restartRest();}];+ // VoiceOver keeps the controls up, and the shield is hidden from it: turned on, it brings them back.+ [NSNotificationCenter.defaultCenter addObserverForName:UIAccessibilityVoiceOverStatusDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {+ setAlone(NO, YES);+ restartRest();+ }];[NSNotificationCenter.defaultCenter addObserverForName:SGRNowPlayingArtworkDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {if (!sg_open) return;SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(sg_host, &kOverlayKey);