Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
chore: the redesigned Player page supplies a base for its background preview
My-Name-Is-Jeff158516610747
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 4423b19b..7ceb753f 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -291,7 +291,7 @@ Redesigned:UITabBarController, so UIKit's tabBarMinimizeBehavior and bottomAccessory cannot do it. Laid out onthe Mac against harness/tabbar/ (`mini`), the scroll's steps checked by harness/tabbar/minimize-check.cNowPlayingBar/ the glass now playing bar (NowPlayingBar.x), with Spotify's device button on it hidden on request- (BarConnect.x, its own key and its own Now playing page, apart from the native look's). In a Jam the+ (BarConnect.x, its own key and its own row on the Player page, apart from the native look's). In a Jam theglass stays on the track and Spotify's Jam strip gets a pane of its own above it (harness/tabbar/, jam)ContextMenu/ the ⋯ of the player and the ⋯ pinned over the playlist, album and artist pages open the system menu,always (ContextMenu.h): Spotify's sheet is still made, presented unanimated in a container hidden from@@ -430,7 +430,11 @@ lyrics' style, Still or Animated), which work with either look;in the native look also Now playing bar (its device button and its flags), Queue & devices, andSpotify's own player screen (artwork background, glass header buttons, Disable Canvas and the sheet,header, slider and sticky header flags, the cards under the player and the lyrics preview and player-buttons to hide); in the redesign instead Now playing (its device button). Then Vibrations under either look, a card for+buttons to hide); in the redesign the page instead leads with a showcase of the player (Redesigned/Player/+PlayerSettings.m): a small copy of it over the background chosen, the cover, title and artist, and a glass sheet over+the artwork with its progress and volume sliders and the transport between them; under it the Background pull-down+(Still, Colours, Fluid, Animated, changing the showcase at once), Download in Low Data Mode while Animated is+chosen, and the now playing bar's device button, checked in the simulator against harness/player/ (`settings`). Then Vibrations under either look, a card forControls (on until switched off) and one for Music Haptics, a choice of None, Generated or Native iOS(left out below iOS 18) with an ⓘ saying what each does. Someone with no choice stored gets Native iOSwhen Music Haptics is on in Accessibility, else Generated if the old switch was on, else None. Controlsdiff --git a/harness/player/README.md b/harness/player/README.mdindex e7a7a3b2..5b8a7d8e 100644--- a/harness/player/README.md+++ b/harness/player/README.md@@ -15,7 +15,7 @@ sources, for example an older commit, to see a bug before its fix.`build.sh` runs `logos.pl -c generator=internal` over `PlayerLyrics.x`, `PlayerArtwork.x`,`PlayerFooter.x`, `PlayerScroll.x`, `PlayerField.x` and the Kit's `SGRBridges.x`, and links them with-the real `Core/`, `Redesigned/Kit/` and `SGRKaraokeView`. `stubs.m` stands in for the hooks the harness+the real `Core/`, `Redesigned/Kit/`, `SGRKaraokeView`, `Settings/` and the Player page. `stubs.m` stands in for the hooks the harnessdoes not compile (the Kit's accent and repaint, the rest of the player, the lyrics store, the haptics,Sing's mic) and plays a mock player: `SGRHarnessSetTrack` reports a track, with the image ids Spotify'smetadata carries, to every state observer. A song of ten timed lines plays on from launch. `main.m` also answers@@ -62,6 +62,12 @@ come late, out of order, or not at all.and the cover crossing over half way through the switch) and the log ends with`motion checks: n of 11 right -- PASS` or `FAIL`.+- `settings` opens the redesign's Player page (`PlayerSettings.m`, with the real `Settings/` framework) over the+ player at 3 s, with the clip of `motion` in. It checks the showcase leads the page in the window's shape, the+ background and device button rows are on the page, and then, as the Background pull-down picks each in turn,+ that the showcase shows Animated (the clip, the cover gone, Low Data Mode's row in), Fluid, Colours, Still and+ Animated again. The log ends with `settings checks: n of 7 right -- PASS` or `FAIL`.+`HARNESS_VOLUME=0` leaves out the volume row that the phone has and the tree does not.A screen recording is the way to see a move:diff --git a/harness/player/build.sh b/harness/player/build.shindex 285b6736..830bb2b8 100755--- a/harness/player/build.sh+++ b/harness/player/build.sh@@ -22,6 +22,8 @@ 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/SGRMarquee.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \"$SRC"/Redesigned/Kit/SGRedesign.m \+ "$SRC"/Redesigned/Player/PlayerSettings.m "$SRC"/Redesigned/NowPlayingBar/NowPlayingBarSettings.m \+ "$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m "$SRC"/Settings/SGModPage.m "$SRC"/Settings/SGGlowSwitch.m \"$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/SGRSingButton.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/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 8896d9ee..38a7a42f 100644--- a/harness/player/main.m+++ b/harness/player/main.m@@ -19,6 +19,9 @@// motion Animated artwork: a clip (HARNESS_CANVAS_FILE, an mp4) that comes in before the player has// laid out, then the field, the lyrics, a field built again, the menu's switch and the player// closed, each step checked; the log ends with motion checks n of m right -- PASS or FAIL+// settings the redesign's Player page (PlayerSettings.m) over the player with the clip of `motion`: the+// showcase over Animated, then Fluid, Colours and Still as the Background menu picks them, and+// Animated again; each step checked, the log ends with settings checks n of m right -- PASS or FAIL// 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>@@ -542,6 +545,7 @@ static void loadLyrics(void) {else if ([scenario() isEqualToString:@"badge"]) [self runBadgeChecks];else if ([scenario() isEqualToString:@"cover"]) [self runCoverChecks];else if ([scenario() isEqualToString:@"immersive"]) [self runImmersiveChecks];+ else if ([scenario() isEqualToString:@"settings"]) [self runSettingsChecks];// 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(), ^{@@ -791,7 +795,7 @@ static UIView *motionView(void) {- (void)expect:(BOOL)ok step:(NSString *)step detail:(NSString *)detail {_checks++;if (!ok) _failures++;- NSLog(@"[harness] motion check %@: %@ -- %@", step, detail, ok ? @"ok" : @"WRONG");+ NSLog(@"[harness] %@ check %@: %@ -- %@", scenario(), step, detail, ok ? @"ok" : @"WRONG");}// The field covered by the clip, and its Fluid copies hidden for it.@@ -906,6 +910,66 @@ static BOOL fieldCovered(void) {});}+static UIView *firstOfClass(UIView *root, NSString *name) {+ if ([NSStringFromClass(root.class) isEqualToString:name]) return root;+ for (UIView *sub in root.subviews) {+ UIView *found = firstOfClass(sub, name);+ if (found) return found;+ }+ return nil;+}++// The Player page over the player, its showcase checked for each background the Background menu picks.+- (void)runSettingsChecks {+ __block UINavigationController *nav;+ UITableView *(^table)(void) = ^{ return ((UITableViewController *)nav.topViewController).tableView; };+ UIView *(^showcase)(void) = ^{ return firstOfClass(table().tableHeaderView, @"SGRPlayerShowcase"); };+ // The Background row's pull-down, picked as a tap on its item does.+ void (^pick)(NSUInteger) = ^(NSUInteger index) {+ UIButton *button = (UIButton *)[table() cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].accessoryView;+ UIAction *item = (UIAction *)button.menu.children[index];+ NSLog(@"[harness] Background menu offers %@, picking %@", [[button.menu.children valueForKey:@"title"] componentsJoinedByString:@" / "], item.title);+ [item performWithSender:button target:nil];+ };+ void (^expectBackground)(NSString *, BOOL, BOOL, BOOL) = ^(NSString *step, BOOL fluid, BOOL flows, BOOL clip) {+ UIView *view = showcase();+ SGRArtworkField *field = (SGRArtworkField *)firstOfClass(view, @"SGRArtworkField");+ UIView *motion = firstOfClass(view, @"SGRPlayerMotionView");+ UIView *cover = [view valueForKey:@"_cover"];+ NSInteger lowData = [table() numberOfRowsInSection:0];+ BOOL ok = field && field.fluid == fluid && field.flows == flows && (motion != nil) == clip && cover.hidden == clip && lowData == (clip ? 2 : 1);+ [self expect:ok step:step detail:[NSString stringWithFormat:@"field %@ fluid %d flows %d, clip %@, cover %@, %ld rows over the device button (%@)",+ field ? @"in" : @"missing", field.fluid, field.flows, motion ? @"on" : @"off", cover.hidden ? @"hidden" : @"shown",+ (long)lowData, view.accessibilityValue]];+ };+ // The clip is in by 3 s (the motion scenario's first step), and the page opens over the player then.+ after(3, ^{+ nav = [[UINavigationController alloc] initWithRootViewController:SGRPlayerSettingsPage(@[])];+ nav.modalPresentationStyle = UIModalPresentationFullScreen;+ [self.window.rootViewController presentViewController:nav animated:NO completion:nil];+ });+ after(4, ^{+ UIView *view = showcase();+ CGSize window = self.window.bounds.size;+ BOOL shaped = view.window && fabs(view.bounds.size.width / view.bounds.size.height - window.width / window.height) < 0.01;+ [self expect:shaped step:@"the showcase leads the page"+ detail:[NSString stringWithFormat:@"%@ in a header of %@", NSStringFromCGRect(view.frame), NSStringFromCGRect(table().tableHeaderView.frame)]];+ NSInteger sections = table().numberOfSections;+ [self expect:sections == 2 && [table() numberOfRowsInSection:1] == 1 step:@"the background and device button rows on the page"+ detail:[NSString stringWithFormat:@"%ld sections", (long)sections]];+ expectBackground(@"Animated", YES, NO, YES);+ pick(2);+ });+ after(5, ^{ expectBackground(@"Fluid", YES, NO, NO); pick(1); });+ after(6, ^{ expectBackground(@"Colours", NO, YES, NO); pick(0); });+ after(7, ^{ expectBackground(@"Still", NO, NO, NO); pick(3); });+ after(8, ^{+ expectBackground(@"Animated again", YES, NO, YES);+ NSLog(@"[harness] settings checks: %lu of %lu right -- %@", (unsigned long)(self->_checks - self->_failures), (unsigned long)self->_checks,+ self->_failures ? @"FAIL" : @"PASS");+ });+}+- (void)runScrollChecks {after(2, ^{UIScrollView *list = self->_list;@@ -1138,7 +1202,7 @@ static BOOL linesSeek(SGRKaraokeView *lyrics) {__attribute__((constructor(101))) static void sgr_harnessDefaults(void) {[NSUserDefaults.standardUserDefaults setBool:YES forKey:@"spotifyglass.redesign"];// Animated artwork, its clip served by the picture server to the shared session too.- if ([scenario() isEqualToString:@"motion"]) {+ if ([scenario() isEqualToString:@"motion"] || [scenario() isEqualToString:@"settings"]) {[NSUserDefaults.standardUserDefaults setInteger:3 forKey:@"spotifyglass.redesign.player.background"];setenv("HARNESS_CANVAS", "https://canvas.harness/clip.mp4", 1);[NSURLProtocol registerClass:SGRHarnessPictureServer.class];diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 679c8383..5f11b2c4 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -136,7 +136,6 @@ 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; }// Local files: no edits in the harness, so the name is all PlayerLyrics.x needs to watch for one.#import "Shared/LocalFiles/LocalFiles.h"diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex 8f0cacd6..5a3e21e4 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -125,8 +125,6 @@ UIViewController *SGPlayerSettingsPage(void) {if (native) {[pages addObject:SGWithSymbol(SGPageRow(@"Now playing bar", ^UIViewController *{ return SGNowPlayingBarSettingsPage(); }), @"rectangle.bottomthird.inset.filled")];[pages addObject:SGWithSymbol(SGPageRow(@"Queue & devices", ^UIViewController *{ return SGQueueSettingsPage(); }), @"text.line.first.and.arrowtriangle.forward")];- } else {- [pages addObject:SGWithSymbol(SGPageRow(@"Now playing", ^UIViewController *{ return SGRNowPlayingBarSettingsPage(); }), @"rectangle.bottomthird.inset.filled")];}[pages addObject:SGWithSymbol(SGPageRow(@"Lock screen widget", ^UIViewController *{ return SGLockScreenWidgetPage(); }), @"lock")];[sections addObject:SGSection(nil, pages)];@@ -138,5 +136,7 @@ UIViewController *SGPlayerSettingsPage(void) {// Vibrations hook Spotify's own controls and its audio, so they answer under either look.[sections addObjectsFromArray:SGVibrationsSections()];+ // The redesign's page leads with a showcase of its player, the background and device button rows under it.+ if (!native) return SGRPlayerSettingsPage(sections);return [[SGModPage alloc] initWithTitle:@"Player" intro:SGRestartNote sections:sections footer:nil];}diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.hindex 43e2b39f..76efa73e 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h@@ -1,13 +1,16 @@// The redesign's now playing bar: the glass card it becomes (NowPlayingBar.x), Spotify's device button// on that card hidden on request (BarConnect.x), glass behind the bar's and the tab bar's stand-ins while-// the player opens and closes (BarTransition.x), and the bar's page in Mod Settings+// the player opens and closes (BarTransition.x), and the bar's rows in Mod Settings// (NowPlayingBarSettings.m). The redesign keeps its own copy of the hide switch and its own key; the// native look's lives in Native/NowPlayingBar/.#import <UIKit/UIKit.h>+@class SGModRow;+#define SGRHideBarConnect @"spotifyglass.redesign.hide.barConnect" // the device button on the card-UIViewController *SGRNowPlayingBarSettingsPage(void);+// The bar's rows, on the Player page under its showcase (Redesigned/Player/PlayerSettings.m).+NSArray<SGModRow *> *SGRNowPlayingBarRows(void);// The bar's glass card in `host`'s coordinates, with its corner radius; CGRectNull before the bar has// been styled or while it is out of a window (NowPlayingBar.x). The bar keeps its geometry whilediff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.mindex c8e1dd18..04bf2c49 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m@@ -1,20 +1,11 @@-// The Now playing page of the redesign, under Player (App/Pages.m puts it there): the bar and the-// player behind it.+// The now playing bar's rows of the redesign, on the Player page under its showcase+// (Redesigned/Player/PlayerSettings.m puts them there).#import "Core/SGCore.h"#import "Settings/SGModPage.h"#import "NowPlayingBar.h"-#import "Redesigned/Player/Player.h"-#import "Shared/AnimatedArtwork/AnimatedArtwork.h"-UIViewController *SGRNowPlayingBarSettingsPage(void) {- return [[SGModPage alloc] initWithTitle:@"Now playing" intro:SGRestartNote sections:@[- SGSection(nil, @[- SGHideRow(@"Hide the device button", nil, SGRHideBarConnect),- ]),- SGSection(nil, @[- SGChoiceRow(@"Background", @"Animated plays the Canvas or Apple Music's animated cover, over Fluid; the player's ⋯ menu switches between the two",- SGRKeyPlayerBackground, SGRPlayerBackgroundNames(), SGRPlayerBackground()),- SGOptionRow(@"Download in Low Data Mode", @"Animated artwork, up to about 7 MB a song", SGKeyMotionLowData),- ]),- ] footer:nil];+NSArray<SGModRow *> *SGRNowPlayingBarRows(void) {+ return @[+ SGHideRow(@"Hide the device button", @"On the now playing bar", SGRHideBarConnect),+ ];}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 79fec28d..b82094e5 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -20,6 +20,7 @@// PlayerMotion.x Animated artwork: the Canvas or Apple Music's animated cover behind the player// PlayerMenu.m the more button's system menu: Spotify's rows, then speed, pitch, reverb and// Animated artwork (Redesigned/ContextMenu)+// PlayerSettings.m the Player page in Mod Settings, led by a showcase of the player//// Speed and pitch, once the redesign's own, are Shared/Player/SpeedPitch.h's; PlayerHeader.x still hands// the more button over, so a menu opened from it is taken for the player's, and hands it to PlayerMenu.m,@@ -31,7 +32,7 @@@class SGRArtworkField;-// What is behind the player, chosen on the Now playing page (Redesigned/NowPlayingBar/NowPlayingBarSettings.m).+// What is behind the player, chosen on the Player page (PlayerSettings.m).// SGRKeyPlayerMotion is the switch the choice replaced: until a choice is stored, it picks Still or Colours.#define SGRKeyPlayerBackground @"spotifyglass.redesign.player.background"#define SGRKeyPlayerMotion @"spotifyglass.redesign.player.movingBackground"@@ -91,6 +92,15 @@ void SGRPlayerMotionFieldLaidOut(void);// A clip is playing in place of the cover, which is then hidden: the lyrics' thumbnail and the open's// flown cover fade where they are rather than flying to or from it.BOOL SGRPlayerMotionShowing(void);+// A view of its own playing that clip, drawn as the player draws it (its foot, the blur under the controls),+// for the Player page's showcase; nil while no clip plays. It plays only in a window, like the player's.+UIView *SGRPlayerMotionPreview(void);++#pragma mark - Mod Settings (PlayerSettings.m)++// The redesign's Player page: a showcase of the player over the background chosen, the background's and+// the now playing bar's rows under it, then `more`, the sections either look shares (App/Pages.m).+UIViewController *SGRPlayerSettingsPage(NSArray *more);// Alpha 0, no touches, hidden from accessibility, set again on every call: for Spotify's Swift views,// which SGRSuppress cannot keep (PlayerControls.x).diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xindex 88c3481c..419ab4b4 100644--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -210,6 +210,9 @@ static UIBlurEffect *blurEffect(void) {static SGRPlayerMotionView *sg_motion;static NSString *sg_track;+// The clip sg_motion plays and its poster, for the Player page's showcase (SGRPlayerMotionPreview).+static NSURL *sg_motionFile;+static UIImage *sg_motionPoster;// The clip is in and opaque, so the field under it is covered.static BOOL sg_covering;// The list the mask went on, so it comes off even while the player is closed and the list cannot be found,@@ -305,10 +308,20 @@ BOOL SGRPlayerMotionShowing(void) {return sg_motion != nil;}+UIView *SGRPlayerMotionPreview(void) {+ if (!sg_motionFile) return nil;+ SGRPlayerMotionView *preview = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];+ [preview playFile:sg_motionFile poster:sg_motionPoster];+ [preview appear:NO then:^{}];+ return preview;+}+// The clip fades out over the cover coming back where the player is on screen, and goes at once where not.static void clear(BOOL animated) {SGRPlayerMotionView *old = sg_motion;sg_motion = nil;+ sg_motionFile = nil;+ sg_motionPoster = nil;// Uncovered before the clip starts to fade, so the field is there under it.cover(NO);holdField();@@ -325,6 +338,8 @@ static void show(NSString *track, NSURL *file) {clear(YES);sg_motion = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];[sg_motion playFile:file poster:poster];+ sg_motionFile = file;+ sg_motionPoster = poster;layOut();holdField();[sg_motion setBlurred:SGRPlayerLyricsOpen() animated:NO];@@ -380,7 +395,7 @@ static SGRPlayerMotionWatcher *sg_watcher;#pragma mark - the ⋯ menu's switch (Shared/Player/SpeedPitch.h)// Fluid and Animated share the field, so the menu moves between the two without a restart. The other-// backgrounds are a field of another kind, chosen on the Now playing page.+// backgrounds are a field of another kind, chosen on the Player page (PlayerSettings.m).BOOL SGPlayerMenuOffersAnimatedArtwork(void) {if (!sg_watcher) return NO;SGRPlayerBackgroundKind background = SGRPlayerBackground();diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mnew file mode 100644index 00000000..6cebed79--- /dev/null+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -0,0 +1,316 @@+// The redesign's Player page in Mod Settings (App/Pages.m opens it in place of the native look's).+//+// It leads with a showcase of the player: a small copy of it in the player's own proportions, over the+// background chosen on the page, with the playing track's cover, title and artist, and above the artwork a+// glass sheet carrying the player's sliders, progress and volume, with previous, play and next between+// them. The progress is where the track was when the page appeared and the volume is the phone's.+//+// The background is the player's own: a field of the same kind (Still, Colours, Fluid), and for Animated+// the clip the player is playing (SGRPlayerMotionPreview) in place of the cover, or Fluid and the cover+// while there is none, as in the player. It moves under the field's own conditions (in a window, Spotify+// in front, Reduce Motion and Low Power Mode off). Picking another background changes the showcase at+// once; the player takes it after a restart, as the note under the showcase says.+//+// Under the showcase: the background and its Low Data Mode switch, the now playing bar's device button+// (Redesigned/NowPlayingBar/NowPlayingBarSettings.m), then the sections either look shares.+//+// Threading: main thread only.+#import <AVFoundation/AVFoundation.h>+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Settings/SGPageStyle.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Redesigned/NowPlayingBar/NowPlayingBar.h"+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"+#import "Player.h"++// The showcase's height on the page; its width follows the window's shape.+static const CGFloat kShowcaseHeight = 340;+// The player's layout on a 402 x 874 screen, as shares of the showcase's width (w) and height (h).+static const CGFloat kCoverTop = 0.14; // h, the cover's top under the header+static const CGFloat kCoverSide = 0.88; // w, 354 of 402+static const CGFloat kScreenRadius = 0.063; // h, a 55pt display corner++@interface SGRPlayerShowcase : UIView <SGPlayerStateObserver>+- (void)reloadTrack;+- (void)reloadBackgroundAnimated:(BOOL)animated;+@end++@implementation SGRPlayerShowcase {+ SGRArtworkField *_field;+ UIView *_motion;+ UIImageView *_cover;+ UILabel *_title, *_artist;+ UIVisualEffectView *_sheet;+ UIView *_progress, *_progressFill, *_volume, *_volumeFill;+ UIImageView *_previous, *_play, *_next, *_quiet, *_loud;+ CGFloat _position, _level;+}++// A slider of the player as it is drawn at rest: a track, and in it a fill up to the value (its only subview).+static UIView *bar(UIView *host) {+ UIView *track = [UIView new];+ track.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];+ track.layer.cornerCurve = kCACornerCurveContinuous;+ track.clipsToBounds = YES;+ UIView *fill = [UIView new];+ fill.backgroundColor = SGRPrimary();+ [track addSubview:fill];+ [host addSubview:track];+ return track;+}++static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {+ UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:symbol]];+ view.tintColor = color;+ view.contentMode = UIViewContentModeCenter;+ [host addSubview:view];+ return view;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.clipsToBounds = YES;+ self.layer.cornerCurve = kCACornerCurveContinuous;+ self.backgroundColor = SGRNeutralField();+ self.userInteractionEnabled = NO;+ self.isAccessibilityElement = YES;+ self.accessibilityTraits = UIAccessibilityTraitImage;+ self.accessibilityLabel = @"Player preview";++ _field = [[SGRArtworkField alloc] initWithFrame:frame];+ _field.showsBackdrop = YES;+ [self addSubview:_field];++ _cover = [UIImageView new];+ _cover.contentMode = UIViewContentModeScaleAspectFill;+ _cover.clipsToBounds = YES;+ _cover.layer.cornerCurve = kCACornerCurveContinuous;+ _cover.tintColor = SGRTertiary();+ _cover.backgroundColor = SGRSolidGlassFill();+ [self addSubview:_cover];++ _title = [UILabel new];+ _title.textColor = SGRPrimary();+ [self addSubview:_title];+ _artist = [UILabel new];+ _artist.textColor = SGRSecondary();+ [self addSubview:_artist];++ // The sheet is the control layer, so it is glass; the artwork under it is content.+ _sheet = [[UIVisualEffectView alloc] initWithEffect:SGRReduceTransparency() ? nil : SGGlassEffect()];+ if (SGRReduceTransparency()) _sheet.backgroundColor = SGRSolidGlassFill();+ _sheet.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ [self addSubview:_sheet];+ UIView *content = _sheet.contentView;+ _progress = bar(content);+ _progressFill = _progress.subviews.firstObject;+ _volume = bar(content);+ _volumeFill = _volume.subviews.firstObject;+ _previous = glyph(content, @"backward.fill", SGRPrimary());+ _play = glyph(content, @"play.fill", SGRPrimary());+ _next = glyph(content, @"forward.fill", SGRPrimary());+ _quiet = glyph(content, @"speaker.fill", SGRSecondary());+ _loud = glyph(content, @"speaker.wave.3.fill", SGRSecondary());++ SGAddPlayerStateObserver(self);+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(artworkChanged) name:SGRNowPlayingArtworkDidChangeNotification object:nil];+ [self reloadTrack];+ [self reloadBackgroundAnimated:NO];+ return self;+}++- (void)dealloc {+ [NSNotificationCenter.defaultCenter removeObserver:self];+}++- (void)playerStateDidChange:(SPTPlayerState *)state {+ [self reloadTrack];+}++- (void)artworkChanged {+ NSString *identity = nil;+ UIImage *image = SGRNowPlayingArtwork(NULL, &identity);+ if (!image) return;+ _cover.image = image;+ _cover.contentMode = UIViewContentModeScaleAspectFill;+ [_field setArtwork:image identity:identity animated:self.window != nil];+}++// The track, where it is, whether it plays, and the volume, read again.+- (void)reloadTrack {+ SPTPlayerState *state = SGPlayerState();+ SPTPlayerTrack *track = state.track;+ _title.text = track.trackTitle.length ? track.trackTitle : @"Not Playing";+ _artist.text = track.artistName ?: @"";+ _position = state.duration > 0 ? MIN(1, MAX(0, state.position / state.duration)) : 0;+ _level = AVAudioSession.sharedInstance.outputVolume;+ _play.image = [UIImage systemImageNamed:state.isPlaying && !state.isPaused ? @"pause.fill" : @"play.fill"];+ // The clip covers the field, which then holds still, as in the player (PlayerMotion.x).+ _field.motionHeld = state.isPaused || _motion != nil;+ if (SGRNowPlayingArtwork(NULL, NULL)) {+ [self artworkChanged];+ } else {+ _cover.image = [UIImage systemImageNamed:@"music.note"];+ _cover.contentMode = UIViewContentModeCenter;+ }+ [self setNeedsLayout];+}++// The background chosen, read again; a new one crosses over when animated. The clip is the one playing when+// this is called: a track changed while the page shows keeps the last one until the page appears again.+- (void)reloadBackgroundAnimated:(BOOL)animated {+ SGRPlayerBackgroundKind kind = SGRPlayerBackground();+ void (^apply)(void) = ^{+ self->_field.flows = kind == SGRPlayerBackgroundColours;+ self->_field.fluid = kind >= SGRPlayerBackgroundFluid;+ [self->_motion removeFromSuperview];+ self->_motion = kind == SGRPlayerBackgroundAnimated ? SGRPlayerMotionPreview() : nil;+ if (self->_motion) [self insertSubview:self->_motion aboveSubview:self->_field];+ self->_cover.hidden = self->_motion != nil;+ self->_field.motionHeld = SGPlayerState().isPaused || self->_motion != nil;+ };+ self.accessibilityValue = [SGRPlayerBackgroundNames()[(NSUInteger)kind] stringByAppendingString:@" background"];+ if (animated && self.window) {+ // A crossfade, which Reduce Motion keeps: nothing moves.+ [UIView transitionWithView:self duration:SGRCrossfade options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowAnimatedContent+ animations:apply completion:nil];+ } else {+ apply();+ }+ [self setNeedsLayout];+}++- (void)layoutSubviews {+ [super layoutSubviews];+ CGRect bounds = self.bounds;+ CGFloat w = bounds.size.width, h = bounds.size.height;+ self.layer.cornerRadius = round(h * kScreenRadius);+ _field.frame = bounds;+ _field.backdropHeight = h;+ _motion.frame = bounds;++ CGFloat side = round(w * kCoverSide), x = round((w - side) / 2);+ _cover.frame = CGRectMake(x, round(h * kCoverTop), side, side);+ _cover.layer.cornerRadius = side * SGRRadiusArtwork / 354;+ _cover.preferredSymbolConfiguration = [UIImageSymbolConfiguration configurationWithPointSize:side * 0.3 weight:UIImageSymbolWeightRegular];++ _title.font = [UIFont systemFontOfSize:w * 0.055 weight:UIFontWeightBold];+ _artist.font = [UIFont systemFontOfSize:w * 0.045];+ CGFloat y = CGRectGetMaxY(_cover.frame) + round(h * 0.035);+ _title.frame = CGRectMake(x, y, side, ceil(_title.font.lineHeight));+ _artist.frame = CGRectMake(x, CGRectGetMaxY(_title.frame), side, ceil(_artist.font.lineHeight));++ CGFloat inset = round(w * 0.035), top = CGRectGetMaxY(_artist.frame) + round(h * 0.025);+ _sheet.frame = CGRectMake(inset, top, w - 2 * inset, h - inset - top);+ SGShapeGlass(_sheet, round(w * 0.075), NO);+ if (!_sheet.effect) {+ _sheet.layer.cornerRadius = round(w * 0.075);+ _sheet.layer.cornerCurve = kCACornerCurveContinuous;+ _sheet.clipsToBounds = YES;+ }++ CGSize sheet = _sheet.bounds.size;+ CGFloat pad = round(sheet.width * 0.07), line = MAX(2, round(w * 0.012));+ CGFloat width = sheet.width - 2 * pad;+ _progress.frame = CGRectMake(pad, round(sheet.height * 0.17), width, line);+ _progressFill.frame = CGRectMake(0, 0, round(width * _position), line);++ CGFloat speaker = round(w * 0.06), gap = round(w * 0.02);+ CGFloat volumeY = round(sheet.height * 0.83);+ _quiet.frame = CGRectMake(pad, volumeY - speaker / 2, speaker, speaker);+ _loud.frame = CGRectMake(sheet.width - pad - speaker, volumeY - speaker / 2, speaker, speaker);+ CGFloat volumeX = CGRectGetMaxX(_quiet.frame) + gap, volumeWidth = CGRectGetMinX(_loud.frame) - gap - volumeX;+ _volume.frame = CGRectMake(volumeX, volumeY - line / 2, volumeWidth, line);+ _volumeFill.frame = CGRectMake(0, 0, round(volumeWidth * _level), line);+ _progress.layer.cornerRadius = _volume.layer.cornerRadius = line / 2;++ CGFloat middle = round(sheet.height * 0.5), button = round(w * 0.16);+ _play.frame = CGRectMake(round((sheet.width - button) / 2), middle - button / 2, button, button);+ _previous.frame = CGRectOffset(_play.frame, -round(sheet.width * 0.28), 0);+ _next.frame = CGRectOffset(_play.frame, round(sheet.width * 0.28), 0);+ UIImageSymbolConfiguration *large = [UIImageSymbolConfiguration configurationWithPointSize:w * 0.1 weight:UIImageSymbolWeightBold];+ UIImageSymbolConfiguration *small = [UIImageSymbolConfiguration configurationWithPointSize:w * 0.07 weight:UIImageSymbolWeightBold];+ _play.preferredSymbolConfiguration = large;+ _previous.preferredSymbolConfiguration = _next.preferredSymbolConfiguration = small;+ _quiet.preferredSymbolConfiguration = _loud.preferredSymbolConfiguration =+ [UIImageSymbolConfiguration configurationWithPointSize:w * 0.032 weight:UIImageSymbolWeightSemibold];+}++@end++#pragma mark - the page++@interface SGRPlayerPage : SGModPage+@property (nonatomic, strong) SGRPlayerShowcase *showcase;+@end++@implementation SGRPlayerPage {+ UIView *_header;+ UILabel *_note;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ _header = [UIView new];+ [_header addSubview:self.showcase];+ _note = [UILabel new];+ _note.text = SGRestartNote;+ _note.font = SGSubtitleFont();+ _note.textColor = SGGrey();+ _note.numberOfLines = 0;+ [_header addSubview:_note];+ self.tableView.tableHeaderView = _header;+}++// The header keeps the height it is given, so it is sized here and given back to the table only when that+// changes (a table header set on every pass lays the table out again forever).+- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ UITableView *table = self.tableView;+ CGFloat width = table.bounds.size.width, inset = table.layoutMargins.left;+ CGSize window = table.window.bounds.size;+ CGFloat aspect = window.height > 0 ? window.width / window.height : 402.0 / 874.0;+ CGFloat showcaseWidth = round(kShowcaseHeight * aspect);+ self.showcase.frame = CGRectMake(round((width - showcaseWidth) / 2), 16, showcaseWidth, kShowcaseHeight);+ CGFloat noteWidth = width - 2 * inset;+ CGFloat noteHeight = ceil([_note sizeThatFits:CGSizeMake(noteWidth, CGFLOAT_MAX)].height);+ _note.frame = CGRectMake(inset, CGRectGetMaxY(self.showcase.frame) + 16, noteWidth, noteHeight);+ CGSize size = CGSizeMake(width, CGRectGetMaxY(_note.frame));+ if (CGSizeEqualToSize(_header.bounds.size, size)) return;+ _header.frame = (CGRect){CGPointZero, size};+ table.tableHeaderView = _header;+}++- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ [self.showcase reloadTrack];+ [self.showcase reloadBackgroundAnimated:NO];+}++@end++UIViewController *SGRPlayerSettingsPage(NSArray *more) {+ SGRPlayerShowcase *showcase = [[SGRPlayerShowcase alloc] initWithFrame:CGRectMake(0, 0, 160, kShowcaseHeight)];+ __block __weak SGRPlayerPage *weakPage;+ NSArray<NSString *> *names = SGRPlayerBackgroundNames();+ // A pull-down rather than a list of its own, so the showcase changes in front of you.+ SGModRow *background = SGMenuRow(@"Background", names, ^NSString *{ return names[(NSUInteger)SGRPlayerBackground()]; }, ^(NSInteger index) {+ SGSetInt(SGRKeyPlayerBackground, index);+ [showcase reloadBackgroundAnimated:YES];+ [weakPage refreshVisibility];+ });+ SGModRow *lowData = SGOptionRow(@"Download in Low Data Mode", @"Animated artwork, up to about 7 MB a song", SGKeyMotionLowData);+ lowData.visible = ^BOOL { return SGRPlayerBackground() == SGRPlayerBackgroundAnimated; };++ NSMutableArray<SGModSection *> *sections = [NSMutableArray arrayWithObjects:+ SGNotedSection(nil, @[background, lowData],+ @"Animated plays the Canvas or Apple Music's animated cover over Fluid, and the player's ⋯ menu switches between the two."),+ SGSection(nil, SGRNowPlayingBarRows()), nil];+ [sections addObjectsFromArray:more];+ SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:nil];+ page.showcase = showcase;+ weakPage = page;+ return page;+}