From e8643c4059c4506356541cc92dd0fe37da7b32d2 Mon Sep 17 00:00:00 2001 From: Psychotoxical <171614930+Psychotoxical@users.noreply.github.com> Date: Fri, 8 May 2026 13:35:43 +0200 Subject: [PATCH] refactor(audio): extract AutoEQ proxy commands into own module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pull autoeq_entries + autoeq_fetch_profile out of audio/commands.rs into audio/autoeq_commands.rs (~52 LOC). They proxy autoeq.app + GitHub raw content via Rust to bypass WebView CORS — pure HTTP-fetch flow with no playback state coupling, so they don't need to live next to the playback orchestrator. lib.rs invoke_handler updated to register them under `audio::autoeq_commands::*`. audio/commands.rs: 1830 → 1784 LOC. --- src-tauri/src/audio/autoeq_commands.rs | 52 ++++++++++++++++++++++++++ src-tauri/src/audio/commands.rs | 45 ---------------------- src-tauri/src/audio/mod.rs | 1 + src-tauri/src/lib.rs | 4 +- 4 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 src-tauri/src/audio/autoeq_commands.rs diff --git a/src-tauri/src/audio/autoeq_commands.rs b/src-tauri/src/audio/autoeq_commands.rs new file mode 100644 index 00000000..c84ca98c --- /dev/null +++ b/src-tauri/src/audio/autoeq_commands.rs @@ -0,0 +1,52 @@ +//! AutoEQ proxy commands: fetch entry list and FixedBandEQ profiles from +//! GitHub via Rust to bypass WebView CORS. + +use tauri::State; + +use super::engine::{audio_http_client, AudioEngine}; + +/// Proxy: fetches https://autoeq.app/entries via Rust to bypass WebView CORS restrictions. +#[tauri::command] +pub async fn autoeq_entries(state: State<'_, AudioEngine>) -> Result { + audio_http_client(&state) + .get("https://autoeq.app/entries") + .send().await.map_err(|e| e.to_string())? + .text().await.map_err(|e| e.to_string()) +} + +/// Fetches the AutoEQ FixedBandEQ profile for a specific headphone from GitHub raw content. +/// +/// Directory layout in the AutoEQ repo: +/// results/{source}/{form}/{name}/{name} FixedBandEQ.txt (most sources) +/// results/{source}/{rig} {form}/{name}/{name} FixedBandEQ.txt (crinacle — rig-prefixed dir) +/// +/// We try the rig-prefixed path first (when rig is present), then fall back to form-only. +#[tauri::command] +pub async fn autoeq_fetch_profile( + name: String, + source: String, + rig: Option, + form: String, + state: State<'_, AudioEngine>, +) -> Result { + let base = "https://raw.githubusercontent.com/jaakkopasanen/AutoEq/master/results"; + let filename = format!("{} FixedBandEQ.txt", name); + + let candidates: Vec = if let Some(ref r) = rig { + vec![ + format!("{}/{}/{} {}/{}/{}", base, source, r, form, name, filename), + format!("{}/{}/{}/{}/{}", base, source, form, name, filename), + ] + } else { + vec![format!("{}/{}/{}/{}/{}", base, source, form, name, filename)] + }; + + for url in &candidates { + let resp = audio_http_client(&state).get(url).send().await.map_err(|e| e.to_string())?; + if resp.status().is_success() { + return resp.text().await.map_err(|e| e.to_string()); + } + } + + Err(format!("FixedBandEQ profile not found for '{}'", name)) +} diff --git a/src-tauri/src/audio/commands.rs b/src-tauri/src/audio/commands.rs index fe1cf6ae..1178a9d7 100644 --- a/src-tauri/src/audio/commands.rs +++ b/src-tauri/src/audio/commands.rs @@ -1498,51 +1498,6 @@ pub fn audio_update_replay_gain( ); } -/// Proxy: fetches https://autoeq.app/entries via Rust to bypass WebView CORS restrictions. -#[tauri::command] -pub async fn autoeq_entries(state: State<'_, AudioEngine>) -> Result { - audio_http_client(&state) - .get("https://autoeq.app/entries") - .send().await.map_err(|e| e.to_string())? - .text().await.map_err(|e| e.to_string()) -} - -/// Fetches the AutoEQ FixedBandEQ profile for a specific headphone from GitHub raw content. -/// -/// Directory layout in the AutoEQ repo: -/// results/{source}/{form}/{name}/{name} FixedBandEQ.txt (most sources) -/// results/{source}/{rig} {form}/{name}/{name} FixedBandEQ.txt (crinacle — rig-prefixed dir) -/// -/// We try the rig-prefixed path first (when rig is present), then fall back to form-only. -#[tauri::command] -pub async fn autoeq_fetch_profile( - name: String, - source: String, - rig: Option, - form: String, - state: State<'_, AudioEngine>, -) -> Result { - let base = "https://raw.githubusercontent.com/jaakkopasanen/AutoEq/master/results"; - let filename = format!("{} FixedBandEQ.txt", name); - - let candidates: Vec = if let Some(ref r) = rig { - vec![ - format!("{}/{}/{} {}/{}/{}", base, source, r, form, name, filename), - format!("{}/{}/{}/{}/{}", base, source, form, name, filename), - ] - } else { - vec![format!("{}/{}/{}/{}/{}", base, source, form, name, filename)] - }; - - for url in &candidates { - let resp = audio_http_client(&state).get(url).send().await.map_err(|e| e.to_string())?; - if resp.status().is_success() { - return resp.text().await.map_err(|e| e.to_string()); - } - } - - Err(format!("FixedBandEQ profile not found for '{}'", name)) -} #[tauri::command] pub fn audio_set_eq(gains: [f32; 10], enabled: bool, pre_gain: f32, state: State<'_, AudioEngine>) { diff --git a/src-tauri/src/audio/mod.rs b/src-tauri/src/audio/mod.rs index 3d950707..7b3d582b 100644 --- a/src-tauri/src/audio/mod.rs +++ b/src-tauri/src/audio/mod.rs @@ -3,6 +3,7 @@ //! Implementation is split into submodules (`sources`, `decode`, `stream`, `commands`, …) //! for navigation; behavior matches the historical single `audio.rs` file. +pub mod autoeq_commands; mod codec; pub mod commands; mod decode; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 54508bd7..847caf87 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -395,8 +395,8 @@ pub fn run() { audio::commands::audio_set_volume, audio::commands::audio_update_replay_gain, audio::commands::audio_set_eq, - audio::commands::autoeq_entries, - audio::commands::autoeq_fetch_profile, + audio::autoeq_commands::autoeq_entries, + audio::autoeq_commands::autoeq_fetch_profile, audio::commands::audio_preload, audio::commands::audio_play_radio, audio::preview::audio_preview_play,