Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: Music Haptics plays again when iOS does not play the song in the background
My-Name-Is-Jeff72b7f789e2da
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex bd32185b..caab5524 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -334,9 +334,11 @@ Shared:ISRC with Spotify's own spclient headers, asks Apple Music's catalog for that ISRC (the phone's own country first, then the US), and names thematched song's catalog id (same ISRC, length within 2 s, a haptic track) or else the ISRC in the nowplaying info for iOS's own Music Haptics, which plays on the lock screen and in other apps too- (SystemMusicHaptics.x, its pure steps in SGHapticTrack.m). Both may be on: while it asks and while- iOS has a haptic track for the song, the mod's own stays quiet, since iOS plays the track in front- of Spotify too; once iOS has none, the mod's own plays while Spotify is in front. The analyzer is+ (SystemMusicHaptics.x, its pure steps in SGHapticTrack.m). Both may be on: while iOS reports the named song+ playing, the mod's own stays quiet, since iOS plays the track in front of Spotify too, and also while+ it asks (10 s at most) and for 3 s after a song is named; with no report by then, once iOS has none,+ while iOS's is paused in Control Center or in an install iOS does not list, the mod's own plays while+ Spotify is in front. The analyzer isscored on the Mac against harness/haptics/, as are the pure steps (build/track), the hook, the twoswitches, the stand-down and the move from the old choice in the simulator against its sim/, thesettings against harness/haptics-page/@@ -750,7 +752,7 @@ has its Strength under it, grayed out while the switch is off (10 to 100%, a tapMusic Haptics its Strength (20 to 200%, 100% being how it first shipped, a kick at the new strength with each step) andFollows, grayed out the same way, Everything (a tap on each kick and snare and a rumble under the bass), Beat (thetaps without the rumble) or Bass (the kicks' taps and the rumble); In the Background a Status row (Paused, Waiting,-Checking, Ready, Playing or Unavailable) while it is on, or, while Music Haptics is off in Settings > Accessibility, a+Checking, "Sent, iOS not playing yet", Playing or Unavailable) while it is on, or, while Music Haptics is off in Settings > Accessibility, arow saying so whose tap opens its ⓘ, all applying straight away. Live Activity, on iOS 17 and up under either look: its switch and which view itshows, Lyrics, Queue or Control menu, and for Lyrics its Without lyrics (Note or Track), Alignment (Center, or Left),Translations (off until switched on) and Text size (Small, Medium or Large); then for every view a Card section ofdiff --git a/tweak/Sources/Shared/Haptics/Haptics.h b/tweak/Sources/Shared/Haptics/Haptics.hindex dadcbfee..a11dfa44 100644--- a/tweak/Sources/Shared/Haptics/Haptics.h+++ b/tweak/Sources/Shared/Haptics/Haptics.h@@ -82,8 +82,8 @@ BOOL SGMusicHapticsListedByInstall(void);void SGMigrateMusicHaptics(void);// Posted on the main thread when either switch flips; both engines take it up at once.extern NSNotificationName const SGMusicHapticsSwitchesChangedNotification;-// From SystemMusicHaptics.x: YES while it finds out whether iOS has a haptic track for the song and while iOS-// has one named, so the mod's own stays quiet and the two never play at once. Main thread.+// From SystemMusicHaptics.x: YES while iOS reports the named song playing, and for a short while as it asks+// and names one, so the mod's own stays quiet and the two never play at once. Main thread.void SGMusicHapticsSetSystemCovers(BOOL covers);// From its strength and its choice of what to follow: reads them again, for the next tap.void SGMusicHapticsSettingsChanged(void);diff --git a/tweak/Sources/Shared/Haptics/MusicHaptics.x b/tweak/Sources/Shared/Haptics/MusicHaptics.xindex bc0c2e6d..876d6634 100644--- a/tweak/Sources/Shared/Haptics/MusicHaptics.x+++ b/tweak/Sources/Shared/Haptics/MusicHaptics.x@@ -541,7 +541,7 @@ static void updateListening(void) {void SGMusicHapticsSetSystemCovers(BOOL covers) {if (atomic_exchange(&sg_systemCovers, covers) == covers || !sg_wake) return;- if (SGMusicHapticsOn()) SGLog(@"music haptics: %@", covers ? @"iOS's own has this song, standing down" : @"iOS's own has none for this song, playing along");+ if (SGMusicHapticsOn()) SGLog(@"music haptics: %@", covers ? @"iOS's own covers this song, standing down" : @"iOS's own does not play this song, playing along");updateListening();}diff --git a/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.xindex 814adabd..74a2a068 100644--- a/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x+++ b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x@@ -20,14 +20,13 @@//// The handover to the mod's own (MusicHaptics.x): iOS plays the haptic track of the now playing song// whether the app is in front or not (MAMusicHapticsManager reports its status per now playing song, with no-// foreground or background to it), so the mod's own stands down for the song entirely, from the moment the-// track is asked about (Checking) through an identifier with a haptic track named (Ready), paused from-// Control Center or not. It plays again once the answer is that iOS has none (Unavailable), or with nothing-// asked (Waiting: In the Background off, iOS's switch off, nothing playing). Ready is taken on the catalog's-// word or iOS's availability check, not the status observer's report that iOS plays it, since when that-// observer fires for an app's song is unproven: waiting on it could leave both playing.-// ponytail: quiet while Checking means a song with no haptic track gets the mod's own only once the lookup-// answers, a moment with the ISRC kept, up to kSpotifyTries * kSpotifyRetryAfter when Spotify does not answer.+// foreground or background to it), so the mod's own stands down while iOS's status observer reports the named+// song playing. Before that report it stands down only for a while: while the track is asked about+// (Checking, at most kCheckingFor) and for kReadyGrace after an identifier with a haptic track is named+// (Ready), so the two do not play at once as iOS starts. With no report by then it plays again: a named song+// is no proof that iOS plays it (issue #22, where neither played). It also plays when iOS has none+// (Unavailable), with nothing asked (Waiting), while iOS's is paused from Control Center, and in an install+// that iOS does not list for Music Haptics.//// ponytail: the identifier rides on Spotify's info by title, as NowPlayingExtras matches it, so a next track// with the same title can carry the last one's for the moment before the player reports it. Matching by the@@ -51,6 +50,10 @@ static NSString *const kExtendedMetadata = @"https://spclient.wg.spotify.com/extstatic const NSUInteger kSpotifyTries = 3;static const NSTimeInterval kSpotifyRetryAfter = 4;static const NSUInteger kKeptISRCs = 100;+// How long a track may stay Checking, and how long Ready waits for iOS to report the song playing, before the+// mod's own plays again.+static const NSTimeInterval kCheckingFor = 10;+static const NSTimeInterval kReadyGrace = 3;#pragma mark - Spotify's ISRC@@ -151,6 +154,7 @@ API_AVAILABLE(ios(18.0))id _observer;NSString *_observedCode;BOOL _observedActive;+ BOOL _graceOver; // Ready for kReadyGrace with no report that iOS plays the song}- (void)playerStateDidChange:(SPTPlayerState *)state {@@ -159,20 +163,43 @@ API_AVAILABLE(ios(18.0))- (void)setPhase:(SGNativePhase)phase {_phase = phase;- // follow: leaves Waiting only with In the Background on, iOS's switch on and a track playing.- SGMusicHapticsSetSystemCovers(phase == SGNativeChecking || phase == SGNativeReady);+ NSUInteger revision = _revision;+ if (phase == SGNativeChecking) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kCheckingFor * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ if (revision != self->_revision || self->_phase != SGNativeChecking) return;+ // Answers still to come for this track are dropped, so a late one cannot undo this.+ self->_revision++;+ SGLog(@"music haptics: no answer for %@ in %.0f s, unavailable", self->_track, kCheckingFor);+ self.phase = SGNativeUnavailable;+ });+ } else if (phase == SGNativeReady) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kReadyGrace * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ if (revision != self->_revision || self->_phase != SGNativeReady || [self iOSPlays]) return;+ self->_graceOver = YES;+ SGLog(@"music haptics: iOS has not reported %@ playing in %.0f s, the mod's own plays", self->_track, kReadyGrace);+ [self showStatus];+ });+ }[self showStatus];}+// A status callback alone is not proof: it has to be for the identifier named, and iOS active for it.+- (BOOL)iOSPlays {+ return _observedActive && ([_observedCode isEqualToString:_isrc] || [_observedCode isEqualToString:_songID]);+}++// Every change ends here: the status, and whether the mod's own stands down.- (void)showStatus {+ // follow: leaves Waiting only with In the Background on, iOS's switch on and a track playing.+ BOOL starting = _phase == SGNativeChecking || (_phase == SGNativeReady && !_graceOver);+ SGMusicHapticsSetSystemCovers(SGMusicHapticsListedByInstall() && _enabled && _active && ([self iOSPlays] || starting));NSString *status;if (!_enabled) status = @"Off in iOS";else if (!_active) status = @"Paused in Control Center";else if (_phase == SGNativeChecking) status = @"Checking";else if (_phase == SGNativeUnavailable) status = @"Unavailable";else if (_phase == SGNativeWaiting) status = @"Waiting";- // A status callback alone is not proof: it has to be for the identifier named, and iOS active for it.- else status = _observedActive && ([_observedCode isEqualToString:_isrc] || [_observedCode isEqualToString:_songID]) ? @"Playing" : @"Ready";+ else status = [self iOSPlays] ? @"Playing" : @"Sent, iOS not playing yet";SGSetMusicHapticsStatus(status);}@@ -191,6 +218,7 @@ API_AVAILABLE(ios(18.0))_isrc = _songID = nil;_observedCode = nil;_observedActive = NO;+ _graceOver = NO;// Off before anything is asked, so no answer can arrive while the last track's is still named.SGNowPlayingSetExtras(@"haptics", nil, nil);if (!SGMusicHapticsInBackground() || !_enabled || !track) {