From 2d0ee021e6c83185c0d11e88417a88adcbc561e4 Mon Sep 17 00:00:00 2001 From: Honey Date: Wed, 20 May 2026 22:58:49 +0200 Subject: [PATCH] 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 --- .../kotlin/com/novasonic/app/MainActivity.kt | 27 ++++++++++++++++++- index.html | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/kotlin/com/novasonic/app/MainActivity.kt b/android/app/src/main/kotlin/com/novasonic/app/MainActivity.kt index f745638..55adaa8 100644 --- a/android/app/src/main/kotlin/com/novasonic/app/MainActivity.kt +++ b/android/app/src/main/kotlin/com/novasonic/app/MainActivity.kt @@ -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) } + } } } diff --git a/index.html b/index.html index 624b4a1..b9b5d1e 100644 --- a/index.html +++ b/index.html @@ -405,7 +405,7 @@
♪
-
Kein Titel
+
Kein Titel