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:
1 parent
084c1728cd
commit
2d0ee021e6
2 files changed
+26
-1
No files matched your search
@@ -88,9 +88,34 @@ class MainActivity : AppCompatActivity(), MusicService.StateListener {
|
|||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
// Notification tap while app is already running — WebView is ready immediately.
|
// Notification tap while app is already running — WebView is ready immediately.
|
||||||
if (intent.getBooleanExtra("open_now_playing", false)) {
|
if (intent.getBooleanExtra("open_now_playing", false)) {
|
||||||
|
// 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) }
|
webView.post { webView.evaluateJavascript("if(window.openNowPlaying)window.openNowPlaying()", null) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() { super.onResume(); webView.onResume() }
|
override fun onResume() { super.onResume(); webView.onResume() }
|
||||||
override fun onPause() { webView.onPause(); super.onPause() }
|
override fun onPause() { webView.onPause(); super.onPause() }
|
||||||
|
|||||||
+1
-1
@@ -405,7 +405,7 @@
|
|||||||
<div class="player-art" id="player-art" style="cursor:pointer" title="Jetzt läuft öffnen"><div class="no-art">♪</div></div>
|
<div class="player-art" id="player-art" style="cursor:pointer" title="Jetzt läuft öffnen"><div class="no-art">♪</div></div>
|
||||||
<div class="player-info">
|
<div class="player-info">
|
||||||
<div style="display:flex;align-items:center;gap:6px">
|
<div style="display:flex;align-items:center;gap:6px">
|
||||||
<div class="player-title" id="player-title" onclick="playerBarGoAlbum()" style="cursor:pointer" title="Zum Album">Kein Titel</div>
|
<div class="player-title" id="player-title">Kein Titel</div>
|
||||||
<button id="btn-star-current" onclick="starCurrent()" title="Favorit" style="background:none;border:none;cursor:pointer;padding:2px;flex-shrink:0;display:flex;align-items:center">
|
<button id="btn-star-current" onclick="starCurrent()" title="Favorit" style="background:none;border:none;cursor:pointer;padding:2px;flex-shrink:0;display:flex;align-items:center">
|
||||||
<svg id="star-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--text3)" stroke-width="2" style="transition:fill .2s,stroke .2s"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
|
<svg id="star-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--text3)" stroke-width="2" style="transition:fill .2s,stroke .2s"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in new issue
Block a user