From 0651acf1db33c9c1a07d0710276b5b704d688965 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 3 Feb 2026 07:54:39 -0600 Subject: [PATCH] Add playback preferences API endpoint for remote control - GET /api/playback/preferences - get current autoplay mode - POST /api/playback/autoplay - set autoplay mode (continue/track_only/infinite) --- src-tauri/src/api_server/mod.rs | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src-tauri/src/api_server/mod.rs b/src-tauri/src/api_server/mod.rs index 333db4f46..850385d5c 100644 --- a/src-tauri/src/api_server/mod.rs +++ b/src-tauri/src/api_server/mod.rs @@ -25,6 +25,7 @@ use crate::{ commands::{self, search::SearchAllResults}, config::{ audio_settings::AudioSettingsState, + playback_preferences::{AutoplayMode, PlaybackPreferencesState, PlaybackPreferences}, remote_control_settings::{RemoteControlSettings, RemoteControlSettingsState}, }, offline_cache::OfflineCacheState, @@ -399,6 +400,8 @@ fn build_router(ctx: ApiContext) -> Router { .route("/api/album/play", post(play_album)) .route("/api/album/:id", get(get_album)) .route("/api/artist/:id", get(get_artist)) + .route("/api/playback/preferences", get(get_playback_preferences)) + .route("/api/playback/autoplay", post(set_autoplay)) .route("/api/ws", get(ws_handler)) .with_state(ctx.clone()) .layer(middleware::from_fn(lan_only)) @@ -560,6 +563,37 @@ struct PlayAlbumRequest { album_id: String, } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct SetAutoplayRequest { + mode: String, +} + +async fn get_playback_preferences( + State(ctx): State, +) -> Result, StatusCode> { + let prefs_state = ctx.app_handle.state::(); + prefs_state.get_preferences() + .map(Json) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) +} + +async fn set_autoplay( + State(ctx): State, + Json(payload): Json, +) -> Result { + let prefs_state = ctx.app_handle.state::(); + let mode = match payload.mode.as_str() { + "continue" => AutoplayMode::ContinueWithinSource, + "track_only" => AutoplayMode::PlayTrackOnly, + "infinite" => AutoplayMode::InfiniteRadio, + _ => return Err(StatusCode::BAD_REQUEST), + }; + prefs_state.set_autoplay_mode(mode) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + Ok(StatusCode::NO_CONTENT) +} + async fn search_tracks( State(ctx): State, Query(query): Query,