feat(remote): sync shuffle/repeat between desktop and PWA

- Add shuffle/repeat fields to PlaybackEvent struct
- Emit queue:state event when shuffle/repeat changes via API
- Add queue event listener in desktop frontend
- Include shuffle/repeat in WebSocket broadcasts
- PWA updates shuffle/repeat from WebSocket messages

This enables bidirectional sync: changes from PWA update desktop UI,
and changes from desktop update PWA via WebSocket.
This commit is contained in:
vicrodh committed 2026-02-03 09:22:55 -06:00
1 parent 6b85086b0a
commit 477258d94a
5 files changed
+90 -3

No files matched your search

+27 -1
View File
@@ -277,13 +277,35 @@ pub fn broadcast_playback_event(app_handle: &AppHandle, event: &PlaybackEvent) {
/// Emit playback event to both desktop UI (Tauri event) and PWA (WebSocket)
fn emit_playback_update(app_handle: &AppHandle) {
let app_state = app_handle.state::<AppState>();
let event = app_state.player.get_playback_event();
let mut event = app_state.player.get_playback_event();
// Add queue state to event for PWA sync
event.shuffle = Some(app_state.queue.is_shuffle());
event.repeat = Some(match app_state.queue.get_repeat() {
crate::queue::RepeatMode::Off => "off".to_string(),
crate::queue::RepeatMode::All => "all".to_string(),
crate::queue::RepeatMode::One => "one".to_string(),
});
// Emit to desktop UI
let _ = app_handle.emit("playback:state", &event);
// Broadcast to WebSocket clients (PWA)
broadcast_playback_event(app_handle, &event);
}
/// Emit queue state event to desktop UI when shuffle/repeat changes
fn emit_queue_state_update(app_handle: &AppHandle) {
let app_state = app_handle.state::<AppState>();
let shuffle = app_state.queue.is_shuffle();
let repeat = match app_state.queue.get_repeat() {
crate::queue::RepeatMode::Off => "off",
crate::queue::RepeatMode::All => "all",
crate::queue::RepeatMode::One => "one",
};
let _ = app_handle.emit("queue:state", serde_json::json!({
"shuffle": shuffle,
"repeat": repeat
}));
}
#[tauri::command]
pub async fn remote_control_get_status(app: AppHandle) -> Result<RemoteControlStatus, String> {
let settings_state = app.state::<RemoteControlSettingsState>();
@@ -722,6 +744,8 @@ async fn set_shuffle(
crate::queue::RepeatMode::All => "all",
crate::queue::RepeatMode::One => "one",
};
// Notify desktop UI of queue state change
emit_queue_state_update(&ctx.app_handle);
Ok(Json(ShuffleRepeatResponse {
shuffle: app_state.queue.is_shuffle(),
repeat: repeat.to_string(),
@@ -739,6 +763,8 @@ async fn set_repeat(
_ => crate::queue::RepeatMode::Off,
};
app_state.queue.set_repeat(mode);
// Notify desktop UI of queue state change
emit_queue_state_update(&ctx.app_handle);
Ok(Json(ShuffleRepeatResponse {
shuffle: app_state.queue.is_shuffle(),
repeat: payload.mode,
+10
View File
@@ -415,6 +415,14 @@ pub fn run() {
if should_emit {
let sample_rate = player_state.get_sample_rate();
let bit_depth = player_state.get_bit_depth();
// Get queue state for shuffle/repeat
let queue_state = &app_handle.state::<AppState>().queue;
let shuffle = queue_state.is_shuffle();
let repeat = match queue_state.get_repeat() {
queue::RepeatMode::Off => "off",
queue::RepeatMode::All => "all",
queue::RepeatMode::One => "one",
};
let event = player::PlaybackEvent {
is_playing,
position,
@@ -423,6 +431,8 @@ pub fn run() {
volume,
sample_rate: if sample_rate > 0 { Some(sample_rate) } else { None },
bit_depth: if bit_depth > 0 { Some(bit_depth) } else { None },
shuffle: Some(shuffle),
repeat: Some(repeat.to_string()),
};
let _ = app_handle.emit("playback:state", &event);
api_server::broadcast_playback_event(&app_handle, &event);
+6
View File
@@ -489,6 +489,10 @@ pub struct PlaybackEvent {
pub sample_rate: Option<u32>,
/// Actual bit depth of the current stream
pub bit_depth: Option<u32>,
/// Queue shuffle state
pub shuffle: Option<bool>,
/// Queue repeat mode ("off", "all", "one")
pub repeat: Option<String>,
}
/// Shared state between main thread and audio thread
@@ -2012,6 +2016,8 @@ impl Player {
volume: self.state.volume(),
sample_rate: if sample_rate > 0 { Some(sample_rate) } else { None },
bit_depth: if bit_depth > 0 { Some(bit_depth) } else { None },
shuffle: None, // Set by caller with access to queue state
repeat: None, // Set by caller with access to queue state
}
}
}