Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
chore: a Mac harness checks what reaches the system's now playing info
My-Name-Is-Jeffba67887e6f3d
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex e5806b32..323a07a1 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -99,7 +99,8 @@ Shared:LockScreenLyrics/ the line being sung in the system's now playing, and on iOS 26 the lyrics as the lock screen'sfull-screen artwork (LyricsArtwork.x): a new artwork ID per line, its 3:4 H.264 clip (the line and thenext one dimmed over the blurred cover, SGLyricsClip.m) written only when the lock screen asks for it,- Still (one frame) or Animated. Rendered on the Mac against harness/lyrics-clip/+ Still (one frame) or Animated. Rendered on the Mac against harness/lyrics-clip/. What reaches the+ system's now playing through this hook and Player/NowPlayingExtras.x is checked by harness/now-playing/Navigation/ the page transition fix (PageTransition.x) and opening a spotify: link (Links.x)Player/ the player's open and close announced (PlayerEvents.x), what the player is doing read throughone hook for every feature that wants it (PlayerState.x), the lock screen widget's flags, and in thediff --git a/harness/now-playing/README.md b/harness/now-playing/README.mdnew file mode 100644index 00000000..afaec4a6--- /dev/null+++ b/harness/now-playing/README.md@@ -0,0 +1,20 @@+# Now playing harness++The two hooks of `MPNowPlayingInfoCenter`'s setter, `Shared/Player/NowPlayingExtras.x` and+`Shared/LockScreenLyrics/LockScreenLyrics.x`, through Logos and nested as in the tweak, run on the Mac as a+Mac Catalyst tool. The system's setter and getter are replaced under both, so the check reads exactly what+the system was given. Karaoke is a stub with two lines of lyrics.++It checks that:++- once lock screen lyrics let a line go, the info sent with the artist back carries the elapsed time moved+ on, not the one Spotify reported a while ago, and a later resend of an extra is not pulled back by it+- an extra cleared while the info still carries it (the next track has the same title, or Spotify copied+ it onto its next info) is taken off at once, another owner's extra stays, and nothing is sent when there+ is nothing to take off++It runs once with lock screen lyrics off and once with it on (`LSL=1`).++ THEOS=$HOME/theos ./build.sh++`SRC=<checkout>/tweak/Sources` builds another checkout instead, to see a bug before its fix.diff --git a/harness/now-playing/build.sh b/harness/now-playing/build.shnew file mode 100755index 00000000..b14fdf0e--- /dev/null+++ b/harness/now-playing/build.sh@@ -0,0 +1,25 @@+#!/bin/sh+# Builds the now playing check for the Mac, as a Mac Catalyst tool: the two hooks of the now playing setter+# through Logos as the tweak builds them, Karaoke's timing, and main.m. Runs it with lock screen lyrics off+# and on.+set -e+# SRC may point at another checkout of tweak/Sources (an older commit, to see a bug before its fix).+SRC=${SRC:-$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)}+OUT=${OUT:-$(dirname "$0")/build}+rm -rf "$OUT"; mkdir -p "$OUT/gen"++# In the tweak's order (its Makefile sorts the files), so the setter's hooks nest the same way.+for f in Shared/LockScreenLyrics/LockScreenLyrics.x Shared/Player/NowPlayingExtras.x; do+ "$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$(basename "$f" .x).m"+done++# main.m first, so its constructor replaces the system's setter before the hooks wrap it.+SDK=$(xcrun --sdk macosx --show-sdk-path)+xcrun clang -target arm64-apple-ios18.0-macabi -isysroot "$SDK" -iframework "$SDK/System/iOSSupport/System/Library/Frameworks" \+ -fobjc-arc -g -O0 -Wall -I"$SRC" -I"$SRC/Shared/LockScreenLyrics" \+ "$(dirname "$0")/main.m" "$OUT/gen/LockScreenLyrics.m" "$OUT/gen/NowPlayingExtras.m" \+ "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/Lyrics/Protobuf.m" \+ -framework UIKit -framework MediaPlayer -o "$OUT/now-playing"++"$OUT/now-playing"+LSL=1 "$OUT/now-playing"diff --git a/harness/now-playing/main.m b/harness/now-playing/main.mnew file mode 100644index 00000000..4247cf03--- /dev/null+++ b/harness/now-playing/main.m@@ -0,0 +1,175 @@+// Checks what reaches the system's now playing through the mod's two hooks of the setter,+// Shared/Player/NowPlayingExtras.x and Shared/LockScreenLyrics/LockScreenLyrics.x, built as the tweak+// builds them. The system's setter and getter are replaced underneath both (this file links first, so its+// constructor runs before their %ctors), and Karaoke is a stub with two lines. Run with LSL=1 for lock+// screen lyrics on, without it for off; it exits non-zero on the first check that fails.+#import <MediaPlayer/MediaPlayer.h>+#import <objc/runtime.h>+#include <stdlib.h>+#import "Shared/Lyrics/Lyrics.h"+#import "Shared/Player/NowPlayingExtras.h"+#import "Headers/SPTPlayer.h"++#pragma mark - the system, underneath++static NSDictionary *sg_system; // what the system was last given+static NSUInteger sg_sets;++static void systemSet(id self, SEL _cmd, NSDictionary *info) {+ sg_system = info;+ sg_sets++;+}++static NSDictionary *systemGet(id self, SEL _cmd) {+ return sg_system;+}++__attribute__((constructor)) static void underneath(void) {+ Class center = MPNowPlayingInfoCenter.class;+ class_replaceMethod(center, @selector(setNowPlayingInfo:), (IMP)systemSet, "v@:@");+ class_replaceMethod(center, @selector(nowPlayingInfo), (IMP)systemGet, "@@:");+}++#pragma mark - stubs++BOOL SGFlag(NSString *key, BOOL fallback) { return getenv("LSL") != NULL; }++@implementation SPTPlayerTrack {+@public+ NSString *_title;+}+- (NSString *)trackTitle { return _title; }+@end++@implementation SPTPlayerState {+@public+ SPTPlayerTrack *_track;+}+- (SPTPlayerTrack *)track { return _track; }+@end++@interface SGStubPlayer : NSObject+@property (nonatomic) SPTPlayerState *state;+@end+@implementation SGStubPlayer+@end++static SGStubPlayer *sg_player;+static NSArray<SGKaraokeLine *> *sg_lines;++id SGKaraokePlayer(void) { return sg_player; }+NSString *SGKaraokePlayingTrack(void) { return @"track"; }+NSArray<SGKaraokeLine *> *SGKaraokeLinesForTrack(NSString *trackID) { return sg_lines; }+void SGKaraokeRequestLyrics(NSString *trackID) {}++static SGKaraokeLine *lineOf(NSString *text, NSInteger start, NSInteger end) {+ SGKaraokeWord *word = [SGKaraokeWord new];+ word.text = text;+ word.start = start;+ word.end = end;+ SGKaraokeLine *line = [SGKaraokeLine new];+ line.words = @[word];+ line.start = start;+ line.end = end;+ line.timing = SGKaraokeTimingWords;+ return line;+}++#pragma mark - checks++static int failures;++static void check(BOOL ok, NSString *what) {+ printf("%s %s\n", ok ? "ok " : "FAIL", what.UTF8String);+ if (!ok) failures++;+}++static void runFor(NSTimeInterval seconds) {+ [NSRunLoop.mainRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:seconds]];+}++static NSDictionary *spotifyInfo(NSString *title, double elapsed, double rate) {+ return @{MPMediaItemPropertyTitle: title, MPMediaItemPropertyArtist: @"Artist",+ MPNowPlayingInfoPropertyElapsedPlaybackTime: @(elapsed), MPNowPlayingInfoPropertyPlaybackRate: @(rate)};+}++static double systemElapsed(void) {+ return [sg_system[MPNowPlayingInfoPropertyElapsedPlaybackTime] doubleValue];+}++// Lock screen lyrics: once the line is let go, the artist comes back with the clock moved on, and the+// extras' clock, which records what passes, is not pulled back by it either.+static void progressBar(void) {+ MPNowPlayingInfoCenter *center = MPNowPlayingInfoCenter.defaultCenter;+ // Rate 4, so the 4 s break after the line's end comes in about a second of wall time.+ const double rate = 4;+ CFAbsoluteTime setAt = CFAbsoluteTimeGetCurrent();+ center.nowPlayingInfo = spotifyInfo(@"Song", 0, rate);+ check([sg_system[MPMediaItemPropertyArtist] isEqual:@"Hello"], @"the line sung shows in place of the artist");+ runFor(1.6);+ double expected = rate * (CFAbsoluteTimeGetCurrent() - setAt);+ check([sg_system[MPMediaItemPropertyArtist] isEqual:@"Artist"], @"the artist comes back in the break");+ // The line is let go 4 s past its end at 0.1 s, so the info that lets it go is from 4.1 s on.+ check(systemElapsed() > 4.1 && systemElapsed() <= expected,+ [NSString stringWithFormat:@"the break's info is at %.2f s, not Spotify's 0", systemElapsed()]);+ SGNowPlayingSetExtras(@"haptics", @{MPNowPlayingInfoPropertyInternationalStandardRecordingCode: @"ISRC"}, @"Song");+ expected = rate * (CFAbsoluteTimeGetCurrent() - setAt);+ check(fabs(systemElapsed() - expected) < 1.5,+ [NSString stringWithFormat:@"an extra's resend is at %.2f s (expected about %.2f)", systemElapsed(), expected]);+ SGNowPlayingSetExtras(@"haptics", nil, nil);+}++// Two tracks with one title: what the first had must not stay on the second's info once it is cleared.+static void sameTitle(void) {+ MPNowPlayingInfoCenter *center = MPNowPlayingInfoCenter.defaultCenter;+ NSString *key = MPNowPlayingInfoPropertyInternationalStandardRecordingCode;+ center.nowPlayingInfo = spotifyInfo(@"Intro", 50, 0);+ SGNowPlayingSetExtras(@"lyrics", @{key: @"first"}, @"Intro");+ check([sg_system[key] isEqual:@"first"], @"the extra rides on its title's info");+ center.nowPlayingInfo = spotifyInfo(@"Intro", 0, 0); // the next track, also called Intro+ check([sg_system[key] isEqual:@"first"], @"it rides on the next track of that title until cleared");+ SGNowPlayingSetExtras(@"lyrics", nil, nil);+ check(sg_system && !sg_system[key], @"cleared, it is taken off the info at once");+ check(fabs(systemElapsed()) < 0.01, @"the paused clock is kept");++ // Spotify building its next info from the one it reads back, so the extra comes along under a new title.+ SGNowPlayingSetExtras(@"lyrics", @{key: @"second"}, @"Intro");+ NSMutableDictionary *copied = [center.nowPlayingInfo mutableCopy];+ copied[MPMediaItemPropertyTitle] = @"Outro";+ center.nowPlayingInfo = copied;+ check([sg_system[key] isEqual:@"second"], @"copied, it rides on another title's info");+ SGNowPlayingSetExtras(@"lyrics", nil, nil);+ check(!sg_system[key], @"cleared, it comes off an info it was copied onto");++ // Nothing to take off: nothing is sent.+ SGNowPlayingSetExtras(@"lyrics", @{key: @"third"}, @"Intro");+ NSUInteger sets = sg_sets;+ SGNowPlayingSetExtras(@"lyrics", nil, nil);+ check(sg_sets == sets, @"cleared for another title, the info is not sent again");++ // Another owner's extra for the same title stays.+ center.nowPlayingInfo = spotifyInfo(@"Intro", 0, 0);+ SGNowPlayingSetExtras(@"haptics", @{@"other": @"kept"}, @"Intro");+ SGNowPlayingSetExtras(@"lyrics", @{key: @"fourth"}, @"Intro");+ SGNowPlayingSetExtras(@"lyrics", nil, nil);+ check(!sg_system[key] && [sg_system[@"other"] isEqual:@"kept"], @"another owner's extra stays on");+ SGNowPlayingSetExtras(@"haptics", nil, nil);+}++int main(void) {+ @autoreleasepool {+ SPTPlayerTrack *track = [SPTPlayerTrack new];+ track->_title = @"Song";+ SPTPlayerState *state = [SPTPlayerState new];+ state->_track = track;+ sg_player = [SGStubPlayer new];+ sg_player.state = state;+ sg_lines = @[lineOf(@"Hello", 0, 100), lineOf(@"Later", 60000, 61000)];+ BOOL lyrics = getenv("LSL") != NULL;+ printf("lock screen lyrics %s\n", lyrics ? "on" : "off");+ if (lyrics) progressBar();+ sameTitle();+ printf(failures ? "%d failed\n" : "all passed\n", failures);+ return failures ? 1 : 0;+ }+}