From ee7c1de3d6686687b25eafd3cb0da9b2cfba87a0 Mon Sep 17 00:00:00 2001 From: Psychotoxical <171614930+Psychotoxical@users.noreply.github.com> Date: Fri, 8 May 2026 14:20:11 +0200 Subject: [PATCH] refactor(app_api): extract cli_bridge wrappers into own submodule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lift the four cli_publish_* Tauri commands (player_snapshot, library_list, server_list, search_results) out of app_api/core.rs into app_api/cli_bridge.rs. Each is a thin pass-through to `crate::cli::write_*_response` — the renderer-side counterpart to the file-based IPC layer in cli/exchange.rs. This is the "cli-bridge" slice from cucadmuh's plan for splitting core.rs's mixed concerns. Together with the earlier perf split, core.rs is now down to runtime-control + platform + logging slices — one possible follow-up but each is small enough to leave as-is for now. app_api/core.rs: 122 → 99 LOC. --- .../src/lib_commands/app_api/cli_bridge.rs | 27 +++++++++++++++++++ src-tauri/src/lib_commands/app_api/core.rs | 24 ----------------- src-tauri/src/lib_commands/app_api/mod.rs | 2 ++ 3 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 src-tauri/src/lib_commands/app_api/cli_bridge.rs diff --git a/src-tauri/src/lib_commands/app_api/cli_bridge.rs b/src-tauri/src/lib_commands/app_api/cli_bridge.rs new file mode 100644 index 00000000..d027f381 --- /dev/null +++ b/src-tauri/src/lib_commands/app_api/cli_bridge.rs @@ -0,0 +1,27 @@ +//! Tauri commands the frontend invokes to push player state and list payloads +//! to the JSON response files that `psysonic --info` / `--player library list` +//! / `--player server list` / `--player search …` then read. + +/// Writes `psysonic-cli-snapshot.json` for `psysonic --info` (debounced from the frontend). +#[tauri::command] +pub(crate) fn cli_publish_player_snapshot(snapshot: serde_json::Value) -> Result<(), String> { + crate::cli::write_cli_snapshot(&snapshot) +} + +/// Writes `psysonic-cli-library.json` for `psysonic --player library list`. +#[tauri::command] +pub(crate) fn cli_publish_library_list(payload: serde_json::Value) -> Result<(), String> { + crate::cli::write_library_cli_response(&payload) +} + +/// Writes `psysonic-cli-servers.json` for `psysonic --player server list`. +#[tauri::command] +pub(crate) fn cli_publish_server_list(payload: serde_json::Value) -> Result<(), String> { + crate::cli::write_server_list_cli_response(&payload) +} + +/// Writes `psysonic-cli-search.json` for `psysonic --player search …`. +#[tauri::command] +pub(crate) fn cli_publish_search_results(payload: serde_json::Value) -> Result<(), String> { + crate::cli::write_search_cli_response(&payload) +} diff --git a/src-tauri/src/lib_commands/app_api/core.rs b/src-tauri/src/lib_commands/app_api/core.rs index 8e7ab975..86b45976 100644 --- a/src-tauri/src/lib_commands/app_api/core.rs +++ b/src-tauri/src/lib_commands/app_api/core.rs @@ -11,30 +11,6 @@ pub(crate) fn exit_app(app_handle: tauri::AppHandle) { app_handle.exit(0); } -/// Writes `psysonic-cli-snapshot.json` for `psysonic --info` (debounced from the frontend). -#[tauri::command] -pub(crate) fn cli_publish_player_snapshot(snapshot: serde_json::Value) -> Result<(), String> { - crate::cli::write_cli_snapshot(&snapshot) -} - -/// Writes `psysonic-cli-library.json` for `psysonic --player library list`. -#[tauri::command] -pub(crate) fn cli_publish_library_list(payload: serde_json::Value) -> Result<(), String> { - crate::cli::write_library_cli_response(&payload) -} - -/// Writes `psysonic-cli-servers.json` for `psysonic --player server list`. -#[tauri::command] -pub(crate) fn cli_publish_server_list(payload: serde_json::Value) -> Result<(), String> { - crate::cli::write_server_list_cli_response(&payload) -} - -/// Writes `psysonic-cli-search.json` for `psysonic --player search …`. -#[tauri::command] -pub(crate) fn cli_publish_search_results(payload: serde_json::Value) -> Result<(), String> { - crate::cli::write_search_cli_response(&payload) -} - /// Toggle native window decorations at runtime (Linux custom title bar opt-out). #[tauri::command] pub(crate) fn set_window_decorations(enabled: bool, app_handle: tauri::AppHandle) { diff --git a/src-tauri/src/lib_commands/app_api/mod.rs b/src-tauri/src/lib_commands/app_api/mod.rs index abb50c86..c23a227e 100644 --- a/src-tauri/src/lib_commands/app_api/mod.rs +++ b/src-tauri/src/lib_commands/app_api/mod.rs @@ -1,5 +1,6 @@ use super::*; +mod cli_bridge; mod core; mod navidrome; mod perf; @@ -7,6 +8,7 @@ mod remote; mod integration; mod analysis; +pub(crate) use cli_bridge::*; pub(crate) use core::*; pub(crate) use navidrome::*; pub(crate) use perf::*;