refactor(audio): extract AutoEQ proxy commands into own module

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.
This commit is contained in:
Psychotoxical
2026-05-08 13:35:43 +02:00
parent 605021102f
commit e8643c4059
4 changed files with 55 additions and 47 deletions
+52
View File
@@ -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<String, String> {
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<String>,
form: String,
state: State<'_, AudioEngine>,
) -> Result<String, String> {
let base = "https://raw.githubusercontent.com/jaakkopasanen/AutoEq/master/results";
let filename = format!("{} FixedBandEQ.txt", name);
let candidates: Vec<String> = 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))
}
-45
View File
@@ -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<String, String> {
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<String>,
form: String,
state: State<'_, AudioEngine>,
) -> Result<String, String> {
let base = "https://raw.githubusercontent.com/jaakkopasanen/AutoEq/master/results";
let filename = format!("{} FixedBandEQ.txt", name);
let candidates: Vec<String> = 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>) {
+1
View File
@@ -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;
+2 -2
View File
@@ -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,