fix: sync track state before opening NP on notification tap; remove clickable title from player bar

- MainActivity: emit onTrackChanged + openNowPlaying in one JS tick on notification tap
  to prevent race where stale song appeared in NP overlay and bottom bar
- index.html: remove onclick/cursor from player-title so only album/artist are clickable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-20 22:58:49 +02:00
1 parent 084c1728cd
commit 2d0ee021e6
2 files changed
+27 -2

No files matched your search

@@ -88,7 +88,32 @@ class MainActivity : AppCompatActivity(), MusicService.StateListener {
super.onNewIntent(intent)
// Notification tap while app is already running — WebView is ready immediately.
if (intent.getBooleanExtra("open_now_playing", false)) {
webView.post { webView.evaluateJavascript("if(window.openNowPlaying)window.openNowPlaying()", null) }
// Refresh snapshot so getState() is never stale, then emit onTrackChanged
// + openNowPlaying in a single JS tick to avoid the race where the bottom
// bar and NP overlay show the previous song.
updateStateSnapshot()
val ctrl = mediaController
if (ctrl != null) {
val idx = ctrl.currentMediaItemIndex
val trackId = ctrl.currentMediaItem?.mediaId ?: ""
val json = JSONObject().apply {
put("index", idx)
put("trackId", trackId)
put("reason", "notification")
}.toString()
val escaped = escapeJs(json)
webView.post {
webView.evaluateJavascript(
"(function(){" +
"if(window.NSPlayer&&window.NSPlayer.onTrackChanged)window.NSPlayer.onTrackChanged(\"$escaped\");" +
"if(window.openNowPlaying)window.openNowPlaying();" +
"})()",
null
)
}
} else {
webView.post { webView.evaluateJavascript("if(window.openNowPlaying)window.openNowPlaying()", null) }
}
}
}