start_tray_host_poll

Function start_tray_host_poll 

Source
pub fn start_tray_host_poll(app: AppHandle<Wry>)
Expand description

Background thread that polls audio-engine playback_status and pushes fresh elapsed / total / paused state to the tray icon and the tray-popover WebView, regardless of JS timer throttling. The JS side (update_tray_now_playing in audio.js) still owns the title and subtitle — those come from DOM state that Rust cannot see — but this thread keeps the elapsed / total / playing fields live when the main window is unfocused (on macOS the rAF loop and setInterval both pause behind isUiIdleHeavyCpu, leaving the tray frozen).

The thread is idempotent (guarded by TRAY_POLL_ACTIVE) and runs for the lifetime of the app. On each tick:

  1. Poll playback_status from audio-engine.
  2. If loaded != true, skip (HTML5 / reverse playback does not reach the engine poll; the JS timeupdate + keepalive paths handle those).
  3. Merge fresh position / duration / paused into the last JS-reported TrayPopoverEmit.
  4. Update tray.set_title (macOS) + tray.set_tooltip and emit tray-popover-state.