Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: Live Activity buttons and AirPods route changes cannot hang Spotify at launch

My-Name-Is-Jeffabe82564591d
diff --git a/tweak/Sources/Shared/Haptics/MusicHaptics.x b/tweak/Sources/Shared/Haptics/MusicHaptics.x
index ff36f973..bc0c2e6d 100644
--- a/tweak/Sources/Shared/Haptics/MusicHaptics.x
+++ b/tweak/Sources/Shared/Haptics/MusicHaptics.x
@@ -593,7 +593,10 @@ void SGMusicHapticsWatchTaps(void (^watcher)(float intensity)) {
atomic_store(&sg_active, false);
updateListening();
}];
- [center addObserverForName:AVAudioSessionRouteChangeNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
- if (atomic_load(&sg_listening)) readLatency();
+ // Posted on the audio session's thread: a main-queue observer would make it wait for main (AGENTS.md).
+ [center addObserverForName:AVAudioSessionRouteChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (atomic_load(&sg_listening)) readLatency();
+ });
}];
}
diff --git a/tweak/Sources/Shared/LiveActivity/LiveActivity.x b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
index e594a122..009b9115 100644
--- a/tweak/Sources/Shared/LiveActivity/LiveActivity.x
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
@@ -462,14 +462,21 @@ void SGSetLiveActivityEnabled(BOOL on) {
static dispatch_once_t observing;
dispatch_once(&observing, ^{
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
- [center addObserverForName:@"SGLiveActivityPlay" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
- if ([note.object isKindOfClass:NSString.class]) playQueued(note.object);
+ // The card's intents post from a background thread. With a queue, the post would wait for main, which
+ // waits on Spotify's core at a launch in the background: no queue, and on to main without waiting.
+ [center addObserverForName:@"SGLiveActivityPlay" object:nil queue:nil usingBlock:^(NSNotification *note) {
+ id uri = note.object;
+ if (![uri isKindOfClass:NSString.class]) return;
+ dispatch_async(dispatch_get_main_queue(), ^{ playQueued(uri); });
}];
// The new state goes out at once rather than on the next tick, the card being slow enough to redraw.
- [center addObserverForName:@"SGLiveActivityAction" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
- if (![note.object isKindOfClass:NSString.class]) return;
- runAction(note.object);
- if (sg_timer) tick();
+ [center addObserverForName:@"SGLiveActivityAction" object:nil queue:nil usingBlock:^(NSNotification *note) {
+ id action = note.object;
+ if (![action isKindOfClass:NSString.class]) return;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ runAction(action);
+ if (sg_timer) tick();
+ });
}];
// Swiped away while it plays, Spotify is told it is ending, and the card goes with it rather than
// staying up frozen over other apps' activities. No queue, so the block runs before the notification