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

feat: iOS Music Haptics keeps playing in the background and on the lock screen

My-Name-Is-Jeff79910289e0c4
diff --git a/docs/tweaks.md b/docs/tweaks.md
index ba6ec332..2965ce0c 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -120,7 +120,9 @@ Shared:
and bass analyzer on the render thread (SGMusicAnalyzer.m, plain C), and a thread of its own schedules
the taps and the rumble for when the sound is heard, at their strength and leaving out what Follows
leaves out (MusicHaptics.x). Everything applies at once; nothing plays while Spotify is not the active
- app. The analyzer is scored on the Mac against harness/haptics/, the hook in the simulator against its
+ app. iOS's own Music Haptics, when on in Accessibility, is handed the song's ISRC from Apple Music's
+ catalog (SystemMusicHaptics.x), and for a song Apple has a haptic track for the mod's stands down
+ until the next song. The analyzer is scored on the Mac against harness/haptics/, the hook in the simulator against its
sim/, the settings against harness/haptics-page/
LiveActivity/ a Live Activity on the lock screen and in the Dynamic Island in one of three views, the line being
sung with the next one under it, the tracks up next (a tap on one skipping ahead to it), or a control
diff --git a/harness/haptics/README.md b/harness/haptics/README.md
index 8fa3e1c8..353f3526 100644
--- a/harness/haptics/README.md
+++ b/harness/haptics/README.md
@@ -43,7 +43,8 @@ generator), the analyzer and the Vibrations settings compiled into an app whose
so its `AudioOutputUnitStart` goes through the rebound import slot as Spotify's does. `sim/fakehaptics.m`
stands in for Core Haptics and counts what it is asked to play. A beat of a kick and a snare a second plays
through a 44.1 kHz client into the simulator's 48 kHz hardware while a script checks each Follows choice, the
-strength at 50% and 200%, the switch off and on, then a 16-bit interleaved client.
+strength at 50% and 200%, the switch off and on, standing down while iOS's own Music Haptics plays the song and
+back at the next, then a 16-bit interleaved client. The app has harness/scene.m's scene, which iOS 27 needs.
THEOS=$HOME/theos ./build-sim.sh
xcrun simctl install <udid> build/sim/HapticsHarness.app
@@ -53,6 +54,8 @@ strength at 50% and 200%, the switch off and on, then a 16-bit interleaved clien
`./build-sim.sh before <dir>` builds the same against an older `MusicHaptics.x`, `Haptics.h` and analyzer put in
`<dir>`, running only the format steps. Use a device of your own (`xcrun simctl create`), by UDID.
+2026-10-05, iPhone 17 Pro on iOS 27.0: every step passes, the stand-down and its return too.
+
2026-09-19: every step passes. Beat sends no rumble, Bass no snare, 50% halves the taps (0.44 from 0.88) and the
rumble's loudest (0.162 from 0.322), 200% doubles the rumble (0.64). The hook now listens at the hardware's
48 kHz float, a buffer per channel, whatever the client ("from 44100 Hz ... Spotify hands it"). Before, it read
diff --git a/harness/haptics/build-sim.sh b/harness/haptics/build-sim.sh
index 6e3117c0..6a965ce7 100755
--- a/harness/haptics/build-sim.sh
+++ b/harness/haptics/build-sim.sh
@@ -25,7 +25,7 @@ mkdir -p "$OUT/gen" "$OUT/HapticsHarness.app"
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O1 -isysroot "$SDK" -Wno-deprecated-declarations \
$EXTRA -I"$SRC" -I"$SRC/Shared/Haptics" -Isim \
- sim/main.m sim/fakehaptics.m "$OUT/gen/MusicHaptics.m" "$HAPTICS/SGMusicAnalyzer.m" $SETTINGS \
+ sim/main.m sim/fakehaptics.m ../scene.m "$OUT/gen/MusicHaptics.m" "$HAPTICS/SGMusicAnalyzer.m" $SETTINGS \
"$SRC/Core/SGRebind.m" "$SRC/Core/SGLog.m" "$SRC/Core/SGPrefs.m" "$SRC/Core/SGUIMode.m" "$SRC/Core/SGViewTree.m" "$SRC/Core/SGFlagForce.m" \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework AudioToolbox -framework AVFoundation -framework Foundation \
-o "$OUT/HapticsHarness.app/HapticsHarness"
@@ -39,7 +39,15 @@ cat > "$OUT/HapticsHarness.app/Info.plist" <<'PLIST'
<key>CFBundleVersion</key><string>1</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
<key>UILaunchScreen</key><dict/>
-<key>UIApplicationSceneManifest</key><dict><key>UIApplicationSupportsMultipleScenes</key><false/></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>SGRHarnessScene</string>
+ </dict></array>
+ </dict>
+</dict>
</dict></plist>
PLIST
echo "built $OUT/HapticsHarness.app"
diff --git a/harness/haptics/sim/main.m b/harness/haptics/sim/main.m
index ac9009c7..e7563b01 100644
--- a/harness/haptics/sim/main.m
+++ b/harness/haptics/sim/main.m
@@ -217,6 +217,13 @@ static int sg_failures;
}, ^(double s) {
[self report:@"on again, Everything, 100%" seconds:s kicks:1 snares:1 rumble:YES intensity:tap100 level:level100];
}],
+ // What SystemMusicHaptics.x says when Apple has a haptic track for the song, and at the next song.
+ @[@"iOS's own Music Haptics plays", ^{ SGMusicHapticsSetSystemPlaying(YES); }, ^(double s) {
+ [self report:@"iOS's own Music Haptics plays" seconds:s kicks:0 snares:0 rumble:NO intensity:NAN level:NAN];
+ }],
+ @[@"a song iOS has none for", ^{ SGMusicHapticsSetSystemPlaying(NO); }, ^(double s) {
+ [self report:@"a song iOS has none for" seconds:s kicks:1 snares:1 rumble:YES intensity:tap100 level:level100];
+ }],
]];
#endif
[steps addObject:@[@"16-bit interleaved client at 48 kHz", ^{ [self startInt16ChainAt:48000]; }, ^(double s) {
diff --git a/plist/liquid-glass.plist b/plist/liquid-glass.plist
index 58f1c582..db76b5e1 100644
--- a/plist/liquid-glass.plist
+++ b/plist/liquid-glass.plist
@@ -8,5 +8,7 @@
<true/>
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
<true/>
+ <key>MusicHapticsSupported</key>
+ <true/>
</dict>
</plist>
diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h
index 9a846bf0..d0a5adb1 100644
--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h
+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h
@@ -25,6 +25,9 @@ void SGMotionArtistLogo(NSString *artist, CGFloat pixels, void (^done)(UIImage *
// screen's full width ran to 29 MB a song; at this width it was 7 MB and looks the same in motion.
CGFloat SGMotionPixels(void);
+// A song's ISRC from Apple Music's catalog, or nil. Main queue.
+void SGMotionSongISRC(NSString *artist, NSString *title, void (^done)(NSString *isrc));
+
// Any remote video (a Canvas) as a local file, or nil. Main queue.
void SGMotionFile(NSURL *remote, void (^done)(NSURL *file));
diff --git a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x
index eb434425..4924816a 100644
--- a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x
+++ b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x
@@ -1,34 +1,15 @@
// The lock screen's artwork moves: the track's Canvas, else Apple Music's animated album cover. iOS 26
// takes a local video through MPMediaItemAnimatedArtwork under one of two now playing keys, 1:1 or 3:4,
-// picked here by the video's own shape.
-//
-// Spotify's now playing info passes through with the artwork added. Lock screen lyrics hooks the same
-// setter and keeps Spotify's own dictionary behind the getter, so this hook stores nothing of it: once
-// a video is ready, the info the getter gives back is sent again with its clock moved on.
+// picked here by the video's own shape. It rides on Spotify's now playing info as an extra
+// (Shared/Player/NowPlayingExtras.h).
#import <MediaPlayer/MediaPlayer.h>
#import "Core/SGCore.h"
#import "AnimatedArtwork.h"
+#import "Shared/Player/NowPlayingExtras.h"
#import "Shared/Player/PlayerState.h"
-// Read on whatever thread Spotify sets the info from, written on the main one.
-static NSObject *sg_lock;
+static NSString *sg_track; // the URI the artwork is for
static NSString *sg_title;
-static NSDictionary *sg_motion;
-static double sg_elapsed, sg_rate;
-static CFAbsoluteTime sg_clockAt;
-
-static NSString *sg_track; // main thread: the URI the artwork is for
-
-API_AVAILABLE(ios(26.0))
-static void resend(void) {
- MPNowPlayingInfoCenter *center = MPNowPlayingInfoCenter.defaultCenter;
- NSMutableDictionary *info = [center.nowPlayingInfo mutableCopy];
- if (!info) return;
- @synchronized (sg_lock) {
- if (sg_clockAt > 0) info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(sg_elapsed + sg_rate * (CFAbsoluteTimeGetCurrent() - sg_clockAt));
- }
- center.nowPlayingInfo = info;
-}
API_AVAILABLE(ios(26.0))
static void show(NSString *uri, NSURL *file) {
@@ -41,11 +22,8 @@ static void show(NSString *uri, NSURL *file) {
MPMediaItemAnimatedArtwork *artwork = [[MPMediaItemAnimatedArtwork alloc] initWithArtworkID:file.lastPathComponent
previewImageRequestHandler:^(CGSize wanted, void (^completion)(UIImage *)) { completion(poster); }
videoAssetFileURLRequestHandler:^(CGSize wanted, void (^completion)(NSURL *)) { completion(file); }];
- @synchronized (sg_lock) {
- sg_motion = @{key: artwork};
- }
+ SGNowPlayingSetExtras(@"motion", @{key: artwork}, sg_title);
SGLog(@"lock motion: %@ as %@", file.lastPathComponent, square ? @"1:1" : @"3:4");
- resend();
});
}
@@ -58,10 +36,8 @@ static void show(NSString *uri, NSURL *file) {
NSString *uri = SGURIString(state.track.URI);
if (!uri || [uri isEqualToString:sg_track]) return;
sg_track = uri;
- @synchronized (sg_lock) {
- sg_title = state.track.trackTitle;
- sg_motion = nil;
- }
+ sg_title = state.track.trackTitle;
+ SGNowPlayingSetExtras(@"motion", nil, nil);
NSDictionary *metadata = [state.track.metadata isKindOfClass:NSDictionary.class] ? state.track.metadata : nil;
NSString *artist = state.track.artistName, *album = metadata[@"album_title"];
id type = metadata[@"canvas.type"], address = metadata[@"canvas.url"];
@@ -83,32 +59,9 @@ static void show(NSString *uri, NSURL *file) {
}
@end
-%hook MPNowPlayingInfoCenter
-- (void)setNowPlayingInfo:(NSDictionary *)info {
- NSDictionary *motion = nil;
- @synchronized (sg_lock) {
- if (info[MPNowPlayingInfoPropertyElapsedPlaybackTime]) {
- sg_elapsed = [info[MPNowPlayingInfoPropertyElapsedPlaybackTime] doubleValue];
- sg_rate = [info[MPNowPlayingInfoPropertyPlaybackRate] doubleValue];
- sg_clockAt = CFAbsoluteTimeGetCurrent();
- }
- if (sg_motion && [info[MPMediaItemPropertyTitle] isEqual:sg_title]) motion = sg_motion;
- }
- if (!motion) {
- %orig;
- return;
- }
- NSMutableDictionary *withMotion = [info mutableCopy];
- [withMotion addEntriesFromDictionary:motion];
- %orig(withMotion);
-}
-%end
-
%ctor {
if (!SGFlag(SGKeyLockScreenMotion, NO)) return;
if (@available(iOS 26.0, *)) {
- sg_lock = [NSObject new];
- %init;
static SGLockScreenMotion *observer;
observer = [SGLockScreenMotion new];
SGAddPlayerStateObserver(observer);
diff --git a/tweak/Sources/Shared/AnimatedArtwork/SGMotionCatalog.m b/tweak/Sources/Shared/AnimatedArtwork/SGMotionCatalog.m
index 470a22e3..48ecfba1 100644
--- a/tweak/Sources/Shared/AnimatedArtwork/SGMotionCatalog.m
+++ b/tweak/Sources/Shared/AnimatedArtwork/SGMotionCatalog.m
@@ -395,3 +395,37 @@ void SGMotionArtistLogo(NSString *artist, CGFloat pixels, void (^done)(UIImage *
});
});
}
+
+#pragma mark - recordings
+
+// The song's ISRC, for iOS's Music Haptics, which plays haptics for a recording it knows by that code.
+void SGMotionSongISRC(NSString *artist, NSString *title, void (^done)(NSString *isrc)) {
+ if (!NSThread.isMainThread) {
+ dispatch_async(dispatch_get_main_queue(), ^{ SGMotionSongISRC(artist, title, done); });
+ return;
+ }
+ NSString *artistKey = SGMotionNameKey(artist), *titleKey = SGMotionNameKey(title);
+ if (!artistKey.length || !titleKey.length) {
+ done(nil);
+ return;
+ }
+ NSString *key = [NSString stringWithFormat:@"isrc\n%@\n%@", artistKey, titleKey];
+ lookUp(key, ^(NSString *isrc) { done(isrc); }, ^(void (^answer)(id, BOOL)) {
+ search(@"songs", [NSString stringWithFormat:@"%@ %@", artist, title], @"", YES, ^(NSArray *found, BOOL answered) {
+ if (!answered) {
+ answer(nil, NO);
+ return;
+ }
+ NSString *isrc = nil;
+ for (id result in found) {
+ id attributes = dig(result, @"attributes");
+ if (!sameArtist(artistKey, SGMotionNameKey(dig(attributes, @"artistName")))) continue;
+ if (![SGMotionNameKey(dig(attributes, @"name")) isEqualToString:titleKey]) continue;
+ id code = dig(attributes, @"isrc");
+ if ([code isKindOfClass:NSString.class] && [code length]) isrc = code;
+ break;
+ }
+ answer(isrc, YES);
+ });
+ });
+}
diff --git a/tweak/Sources/Shared/Haptics/Haptics.h b/tweak/Sources/Shared/Haptics/Haptics.h
index 883265b4..41819791 100644
--- a/tweak/Sources/Shared/Haptics/Haptics.h
+++ b/tweak/Sources/Shared/Haptics/Haptics.h
@@ -5,6 +5,7 @@
// ControlHaptics.x the player's and the now playing bar's controls, the scrubber, the cover swipes, the gestures
// MusicHaptics.x Spotify's audio output listened to, and Core Haptics played along with it
// SGMusicAnalyzer.m the listening: taps and a rumble out of the samples
+// SystemMusicHaptics.x iOS's own Music Haptics given the song's ISRC; the mod's stands down for its songs
// HapticsSettings.m the Vibrations cards, with each switch's strength and what Music Haptics follows
//
// Everything on them applies at once, without a restart. Everything hooked is Spotify's own (its controls
@@ -63,6 +64,9 @@ void SGPrepareFeedback(SGFeedback feedback);
void SGSetMusicHapticsEnabled(BOOL on);
// From its strength and its choice of what to follow: reads them again, for the next tap.
void SGMusicHapticsSettingsChanged(void);
+// From SystemMusicHaptics.x: iOS's own Music Haptics has a haptic track for the song playing, so the mod's
+// stands down (YES), or the song changed and it may play again (NO).
+void SGMusicHapticsSetSystemPlaying(BOOL playing);
// A strength key's percentage as a factor, 1 for 100%, kept within its range.
double SGHapticsStrength(NSString *key);
diff --git a/tweak/Sources/Shared/Haptics/HapticsSettings.m b/tweak/Sources/Shared/Haptics/HapticsSettings.m
index 45e72288..6fb012ab 100644
--- a/tweak/Sources/Shared/Haptics/HapticsSettings.m
+++ b/tweak/Sources/Shared/Haptics/HapticsSettings.m
@@ -7,7 +7,7 @@
#import "Settings/SGModPage.h"
#import "Haptics.h"
-static NSString *const kMusicHapticsInfo = @"The iPhone taps along with the drums and rumbles under the bass of whatever Spotify is playing, worked out from the sound as it plays, much like Music Haptics in Apple Music.\n\nIt follows the sound this iPhone plays, through its speaker or headphones, while Spotify is open: iOS plays no haptics for an app in the background, and a song playing on another device through Connect has no sound here to follow.";
+static NSString *const kMusicHapticsInfo = @"The iPhone taps along with the drums and rumbles under the bass of whatever Spotify is playing, worked out from the sound as it plays, much like Music Haptics in Apple Music.\n\nIt follows the sound this iPhone plays, through its speaker or headphones, while Spotify is open: iOS plays no haptics for an app in the background, and a song playing on another device through Connect has no sound here to follow.\n\nWith Music Haptics on in Settings > Accessibility, iOS plays its own haptics for songs Apple Music has them for, in the background and on the lock screen too, and this one steps aside for those songs.";
static NSArray<NSString *> *followsNames(void) {
return @[@"Everything", @"Beat", @"Bass"];
diff --git a/tweak/Sources/Shared/Haptics/MusicHaptics.x b/tweak/Sources/Shared/Haptics/MusicHaptics.x
index 20e3960f..f2bd98f9 100644
--- a/tweak/Sources/Shared/Haptics/MusicHaptics.x
+++ b/tweak/Sources/Shared/Haptics/MusicHaptics.x
@@ -21,6 +21,8 @@
// with the switch off the notify returns straight away. Nothing listens while Spotify is not the active
// app, since iOS plays no haptics for an app in the background. Sound that is not Spotify's own
// output (Connect, AirPlay to another device, video) never passes the unit, and plays no haptics.
+// Nothing listens either while iOS's own Music Haptics plays a haptic track of the song
+// (SystemMusicHaptics.x), so the two never play at once; the mod's fills in for songs Apple has none for.
//
// Threading: the notify runs on the render thread and only touches atomics, the analyzer and the
// ring; the Core Haptics objects belong to the player thread; the switch, its settings and the app's
@@ -60,7 +62,7 @@ enum { kRingSize = 1024, kMonoFrames = 4096 };
#pragma mark - shared between the threads
-static atomic_bool sg_enabled, sg_active, sg_listening;
+static atomic_bool sg_enabled, sg_active, sg_systemPlaying, sg_listening;
static atomic_uint sg_generation;
static atomic_uint_fast64_t sg_latencyBits;
static atomic_uint sg_lastFrames;
@@ -496,7 +498,7 @@ static void readLatency(void) {
}
static void updateListening(void) {
- BOOL listening = atomic_load(&sg_enabled) && atomic_load(&sg_active);
+ BOOL listening = atomic_load(&sg_enabled) && atomic_load(&sg_active) && !atomic_load(&sg_systemPlaying);
if (atomic_exchange(&sg_listening, listening) == listening) return;
if (listening) {
atomic_fetch_add(&sg_generation, 1);
@@ -520,6 +522,12 @@ void SGSetMusicHapticsEnabled(BOOL on) {
updateListening();
}
+void SGMusicHapticsSetSystemPlaying(BOOL playing) {
+ if (atomic_exchange(&sg_systemPlaying, playing) == playing || !sg_wake) return;
+ if (atomic_load(&sg_enabled)) SGLog(@"music haptics: %@", playing ? @"iOS's own plays this song, standing down" : @"playing along again");
+ updateListening();
+}
+
static void readSettings(void) {
storeDouble(&sg_strengthBits, SGHapticsStrength(SGKeyMusicStrength));
atomic_store(&sg_follows, (int)SGMusicHapticsFollows());
diff --git a/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x
new file mode 100644
index 00000000..b73b9c0f
--- /dev/null
+++ b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x
@@ -0,0 +1,67 @@
+// iOS's own Music Haptics for Spotify: the system plays a haptic track along with a recording it knows by
+// its ISRC, in the background and on the lock screen too, for an app that declares MusicHapticsSupported
+// (plist/liquid-glass.plist) and names the ISRC in its now playing info. Spotify names none, so the song is
+// looked up in Apple Music's catalog and its ISRC rides on Spotify's info as an extra. Nothing is asked
+// while Music Haptics is off in Settings > Accessibility, and turning it on there looks the playing song up
+// at once. When Apple has a haptic track for the song, the mod's own Music Haptics (MusicHaptics.x) stands
+// down until the next one, so the two never play over each other.
+#import <MediaAccessibility/MediaAccessibility.h>
+#import <MediaPlayer/MediaPlayer.h>
+#import "Core/SGCore.h"
+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"
+#import "Shared/Player/NowPlayingExtras.h"
+#import "Shared/Player/PlayerState.h"
+#import "Haptics.h"
+
+API_AVAILABLE(ios(18.0))
+@interface SGSystemMusicHaptics : NSObject <SGPlayerStateObserver>
+- (void)follow:(SPTPlayerState *)state;
+@end
+
+@implementation SGSystemMusicHaptics {
+ NSString *_track;
+}
+
+- (void)playerStateDidChange:(SPTPlayerState *)state {
+ NSString *track = SGURIString(state.track.URI);
+ if (!track || [track isEqualToString:_track]) return;
+ [self follow:state];
+}
+
+- (void)follow:(SPTPlayerState *)state {
+ NSString *track = SGURIString(state.track.URI);
+ _track = track;
+ SGNowPlayingSetExtras(@"haptics", nil, nil);
+ SGMusicHapticsSetSystemPlaying(NO);
+ MAMusicHapticsManager *manager = MAMusicHapticsManager.sharedManager;
+ // Only a song can have a recording code: an episode or an ad is not looked up.
+ if (!manager.isActive || !([track hasPrefix:@"spotify:track:"] || [track hasPrefix:@"spotify:local:"])) return;
+ NSString *title = state.track.trackTitle;
+ SGMotionSongISRC(state.track.artistName, title, ^(NSString *isrc) {
+ if (!isrc || ![track isEqualToString:self->_track]) return;
+ SGNowPlayingSetExtras(@"haptics", @{MPNowPlayingInfoPropertyInternationalStandardRecordingCode: isrc}, title);
+ static NSUInteger logged;
+ if (logged++ < 3) SGLog(@"music haptics: %@ named for iOS's Music Haptics", isrc);
+ [manager checkHapticTrackAvailabilityForMediaMatchingCode:isrc completionHandler:^(BOOL available) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (!available || ![track isEqualToString:self->_track] || !manager.isActive) return;
+ SGMusicHapticsSetSystemPlaying(YES);
+ });
+ }];
+ });
+}
+
+@end
+
+%ctor {
+ if (@available(iOS 18.0, *)) {
+ static SGSystemMusicHaptics *watcher;
+ watcher = [SGSystemMusicHaptics new];
+ SGAddPlayerStateObserver(watcher);
+ [NSNotificationCenter.defaultCenter addObserverForName:MAMusicHapticsManagerActiveStatusDidChangeNotification object:nil
+ queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
+ SGLog(@"music haptics: iOS's Music Haptics %@", MAMusicHapticsManager.sharedManager.isActive ? @"on" : @"off");
+ [watcher follow:SGPlayerState()];
+ }];
+ }
+}
diff --git a/tweak/Sources/Shared/Player/NowPlayingExtras.h b/tweak/Sources/Shared/Player/NowPlayingExtras.h
new file mode 100644
index 00000000..1bbab70f
--- /dev/null
+++ b/tweak/Sources/Shared/Player/NowPlayingExtras.h
@@ -0,0 +1,11 @@
+// Keys the mod adds to Spotify's now playing info, under one hook of the setter: the lock screen's moving
+// artwork, the song's ISRC for iOS's Music Haptics. Each feature sets its own keys for one title, and
+// they ride on every dictionary Spotify sends for that title until the feature sets others.
+//
+// Lock screen lyrics hooks the same setter and keeps Spotify's own dictionary behind the getter, so
+// nothing here stores Spotify's: when extras change, or are cleared while the info still carries them,
+// the info the getter gives back is sent again without the old ones and with its clock moved on.
+#import <Foundation/Foundation.h>
+
+// `extras` nil or empty clears the owner's. Main thread.
+void SGNowPlayingSetExtras(NSString *owner, NSDictionary *extras, NSString *title);
diff --git a/tweak/Sources/Shared/Player/NowPlayingExtras.x b/tweak/Sources/Shared/Player/NowPlayingExtras.x
new file mode 100644
index 00000000..d82cff6f
--- /dev/null
+++ b/tweak/Sources/Shared/Player/NowPlayingExtras.x
@@ -0,0 +1,78 @@
+// NowPlayingExtras.h says what this is and why it stores nothing of Spotify's.
+#import <MediaPlayer/MediaPlayer.h>
+#import "Core/SGCore.h"
+#import "Shared/Player/NowPlayingExtras.h"
+
+// Read on whatever thread Spotify sets the info from, written on the main one.
+static NSObject *sg_lock;
+static NSMutableDictionary<NSString *, NSDictionary *> *sg_extras; // by owner
+static NSMutableDictionary<NSString *, NSString *> *sg_titles; // by owner
+static double sg_elapsed, sg_rate;
+static CFAbsoluteTime sg_clockAt;
+
+// `stale` are an owner's old keys: the info the getter gives back can still carry them, and the hook puts
+// back only the extras that are current.
+static void resend(NSArray *stale) {
+ MPNowPlayingInfoCenter *center = MPNowPlayingInfoCenter.defaultCenter;
+ NSMutableDictionary *info = [center.nowPlayingInfo mutableCopy];
+ if (!info) return;
+ [info removeObjectsForKeys:stale];
+ @synchronized (sg_lock) {
+ if (sg_clockAt > 0) info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(sg_elapsed + sg_rate * (CFAbsoluteTimeGetCurrent() - sg_clockAt));
+ }
+ center.nowPlayingInfo = info;
+}
+
+void SGNowPlayingSetExtras(NSString *owner, NSDictionary *extras, NSString *title) {
+ NSDictionary *old;
+ @synchronized (sg_lock) {
+ old = sg_extras[owner];
+ sg_extras[owner] = extras.count ? extras : nil;
+ sg_titles[owner] = extras.count ? title : nil;
+ }
+ if (extras.count) {
+ resend(old.allKeys ?: @[]);
+ return;
+ }
+ // Cleared, they are taken off if they are still on: the next track can have the same title, and then
+ // the last track's artwork or ISRC rode on its info.
+ NSDictionary *info = MPNowPlayingInfoCenter.defaultCenter.nowPlayingInfo;
+ for (id key in old) {
+ if (![info[key] isEqual:old[key]]) continue;
+ resend(old.allKeys);
+ return;
+ }
+}
+
+%hook MPNowPlayingInfoCenter
+- (void)setNowPlayingInfo:(NSDictionary *)info {
+ NSMutableDictionary *added = nil;
+ @synchronized (sg_lock) {
+ if (info[MPNowPlayingInfoPropertyElapsedPlaybackTime]) {
+ sg_elapsed = [info[MPNowPlayingInfoPropertyElapsedPlaybackTime] doubleValue];
+ sg_rate = [info[MPNowPlayingInfoPropertyPlaybackRate] doubleValue];
+ sg_clockAt = CFAbsoluteTimeGetCurrent();
+ }
+ id title = info[MPMediaItemPropertyTitle];
+ for (NSString *owner in sg_extras) {
+ if (![title isEqual:sg_titles[owner]]) continue;
+ if (!added) added = [NSMutableDictionary dictionary];
+ [added addEntriesFromDictionary:sg_extras[owner]];
+ }
+ }
+ if (!added) {
+ %orig;
+ return;
+ }
+ NSMutableDictionary *withExtras = [info mutableCopy];
+ [withExtras addEntriesFromDictionary:added];
+ %orig(withExtras);
+}
+%end
+
+%ctor {
+ sg_lock = [NSObject new];
+ sg_extras = [NSMutableDictionary dictionary];
+ sg_titles = [NSMutableDictionary dictionary];
+ %init;
+}