refactor: extract commands_v2/diagnostics.rs
cc
This commit is contained in:
2 files changed
+170
-161
No files matched your search
@@ -0,0 +1,168 @@
|
||||
use tauri::State;
|
||||
|
||||
use crate::config::audio_settings::AudioSettingsState;
|
||||
use crate::config::developer_settings::DeveloperSettingsState;
|
||||
use crate::config::graphics_settings::GraphicsSettingsState;
|
||||
use crate::runtime::RuntimeError;
|
||||
|
||||
// ==================== Utility Commands ====================
|
||||
|
||||
/// Fetch a remote URL as bytes (bypasses WebView CORS restrictions).
|
||||
/// Used for loading PDF booklets from Qobuz CDN.
|
||||
#[tauri::command]
|
||||
pub async fn v2_fetch_url_bytes(url: String) -> Result<Vec<u8>, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.map_err(|e| format!("HTTP client error: {}", e))?;
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to fetch URL: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("HTTP {}: {}", response.status(), url));
|
||||
}
|
||||
|
||||
response
|
||||
.bytes()
|
||||
.await
|
||||
.map(|b| b.to_vec())
|
||||
.map_err(|e| format!("Failed to read response: {}", e))
|
||||
}
|
||||
|
||||
// ==================== Runtime Diagnostics ====================
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RuntimeDiagnostics {
|
||||
// Audio: saved settings
|
||||
pub audio_output_device: Option<String>,
|
||||
pub audio_backend_type: Option<String>,
|
||||
pub audio_exclusive_mode: bool,
|
||||
pub audio_dac_passthrough: bool,
|
||||
pub audio_preferred_sample_rate: Option<u32>,
|
||||
pub audio_alsa_plugin: Option<String>,
|
||||
pub audio_alsa_hardware_volume: bool,
|
||||
pub audio_normalization_enabled: bool,
|
||||
pub audio_normalization_target_lufs: f32,
|
||||
pub audio_gapless_enabled: bool,
|
||||
pub audio_pw_force_bitperfect: bool,
|
||||
pub audio_stream_buffer_seconds: u8,
|
||||
pub audio_streaming_only: bool,
|
||||
|
||||
// Graphics: saved settings
|
||||
pub gfx_hardware_acceleration: bool,
|
||||
pub gfx_force_x11: bool,
|
||||
pub gfx_gdk_scale: Option<String>,
|
||||
pub gfx_gdk_dpi_scale: Option<String>,
|
||||
pub gfx_gsk_renderer: Option<String>,
|
||||
|
||||
// Graphics: runtime (what actually applied at startup)
|
||||
pub runtime_using_fallback: bool,
|
||||
pub runtime_is_wayland: bool,
|
||||
pub runtime_has_nvidia: bool,
|
||||
pub runtime_has_amd: bool,
|
||||
pub runtime_has_intel: bool,
|
||||
pub runtime_is_vm: bool,
|
||||
pub runtime_hw_accel_enabled: bool,
|
||||
pub runtime_force_x11_active: bool,
|
||||
|
||||
// Developer settings
|
||||
pub dev_force_dmabuf: bool,
|
||||
|
||||
// Environment variables (what WebKit actually sees)
|
||||
pub env_webkit_disable_dmabuf: Option<String>,
|
||||
pub env_webkit_disable_compositing: Option<String>,
|
||||
pub env_gdk_backend: Option<String>,
|
||||
pub env_gsk_renderer: Option<String>,
|
||||
pub env_libgl_always_software: Option<String>,
|
||||
pub env_wayland_display: Option<String>,
|
||||
pub env_xdg_session_type: Option<String>,
|
||||
|
||||
// App info
|
||||
pub app_version: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn v2_get_runtime_diagnostics(
|
||||
audio_state: State<'_, AudioSettingsState>,
|
||||
graphics_state: State<'_, GraphicsSettingsState>,
|
||||
developer_state: State<'_, DeveloperSettingsState>,
|
||||
) -> Result<RuntimeDiagnostics, RuntimeError> {
|
||||
// Audio settings (may not be available before login)
|
||||
let audio = audio_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
// Graphics settings
|
||||
let gfx = graphics_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
// Graphics runtime status (static atomics — always available)
|
||||
let gfx_status = crate::config::graphics_settings::get_graphics_startup_status();
|
||||
|
||||
// Developer settings
|
||||
let dev = developer_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
let env_var = |name: &str| std::env::var(name).ok();
|
||||
|
||||
let audio_defaults = crate::config::audio_settings::AudioSettings::default();
|
||||
let audio = audio.unwrap_or(audio_defaults);
|
||||
let gfx = gfx.unwrap_or_default();
|
||||
let dev = dev.unwrap_or_default();
|
||||
|
||||
Ok(RuntimeDiagnostics {
|
||||
audio_output_device: audio.output_device,
|
||||
audio_backend_type: audio.backend_type.map(|b| format!("{:?}", b)),
|
||||
audio_exclusive_mode: audio.exclusive_mode,
|
||||
audio_dac_passthrough: audio.dac_passthrough,
|
||||
audio_preferred_sample_rate: audio.preferred_sample_rate,
|
||||
audio_alsa_plugin: audio.alsa_plugin.map(|p| format!("{:?}", p)),
|
||||
audio_alsa_hardware_volume: audio.alsa_hardware_volume,
|
||||
audio_normalization_enabled: audio.normalization_enabled,
|
||||
audio_normalization_target_lufs: audio.normalization_target_lufs,
|
||||
audio_gapless_enabled: audio.gapless_enabled,
|
||||
audio_pw_force_bitperfect: audio.pw_force_bitperfect,
|
||||
audio_stream_buffer_seconds: audio.stream_buffer_seconds,
|
||||
audio_streaming_only: audio.streaming_only,
|
||||
|
||||
gfx_hardware_acceleration: gfx.hardware_acceleration,
|
||||
gfx_force_x11: gfx.force_x11,
|
||||
gfx_gdk_scale: gfx.gdk_scale,
|
||||
gfx_gdk_dpi_scale: gfx.gdk_dpi_scale,
|
||||
gfx_gsk_renderer: gfx.gsk_renderer,
|
||||
|
||||
runtime_using_fallback: gfx_status.using_fallback,
|
||||
runtime_is_wayland: gfx_status.is_wayland,
|
||||
runtime_has_nvidia: gfx_status.has_nvidia,
|
||||
runtime_has_amd: gfx_status.has_amd,
|
||||
runtime_has_intel: gfx_status.has_intel,
|
||||
runtime_is_vm: gfx_status.is_vm,
|
||||
runtime_hw_accel_enabled: gfx_status.hardware_accel_enabled,
|
||||
runtime_force_x11_active: gfx_status.force_x11_active,
|
||||
|
||||
dev_force_dmabuf: dev.force_dmabuf,
|
||||
|
||||
env_webkit_disable_dmabuf: env_var("WEBKIT_DISABLE_DMABUF_RENDERER"),
|
||||
env_webkit_disable_compositing: env_var("WEBKIT_DISABLE_COMPOSITING_MODE"),
|
||||
env_gdk_backend: env_var("GDK_BACKEND"),
|
||||
env_gsk_renderer: env_var("GSK_RENDERER"),
|
||||
env_libgl_always_software: env_var("LIBGL_ALWAYS_SOFTWARE"),
|
||||
env_wayland_display: env_var("WAYLAND_DISPLAY"),
|
||||
env_xdg_session_type: env_var("XDG_SESSION_TYPE"),
|
||||
|
||||
app_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
})
|
||||
}
|
||||
@@ -104,34 +104,6 @@ pub use session::*;
|
||||
mod legacy_compat;
|
||||
pub use legacy_compat::*;
|
||||
|
||||
// ==================== Utility Commands ====================
|
||||
|
||||
/// Fetch a remote URL as bytes (bypasses WebView CORS restrictions).
|
||||
/// Used for loading PDF booklets from Qobuz CDN.
|
||||
#[tauri::command]
|
||||
pub async fn v2_fetch_url_bytes(url: String) -> Result<Vec<u8>, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.map_err(|e| format!("HTTP client error: {}", e))?;
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to fetch URL: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("HTTP {}: {}", response.status(), url));
|
||||
}
|
||||
|
||||
response
|
||||
.bytes()
|
||||
.await
|
||||
.map(|b| b.to_vec())
|
||||
.map_err(|e| format!("Failed to read response: {}", e))
|
||||
}
|
||||
|
||||
mod image_cache;
|
||||
pub use image_cache::*;
|
||||
|
||||
@@ -139,136 +111,5 @@ mod discovery;
|
||||
pub use discovery::*;
|
||||
pub(crate) use discovery::normalize_artist_name;
|
||||
|
||||
// ==================== Runtime Diagnostics ====================
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RuntimeDiagnostics {
|
||||
// Audio: saved settings
|
||||
pub audio_output_device: Option<String>,
|
||||
pub audio_backend_type: Option<String>,
|
||||
pub audio_exclusive_mode: bool,
|
||||
pub audio_dac_passthrough: bool,
|
||||
pub audio_preferred_sample_rate: Option<u32>,
|
||||
pub audio_alsa_plugin: Option<String>,
|
||||
pub audio_alsa_hardware_volume: bool,
|
||||
pub audio_normalization_enabled: bool,
|
||||
pub audio_normalization_target_lufs: f32,
|
||||
pub audio_gapless_enabled: bool,
|
||||
pub audio_pw_force_bitperfect: bool,
|
||||
pub audio_stream_buffer_seconds: u8,
|
||||
pub audio_streaming_only: bool,
|
||||
|
||||
// Graphics: saved settings
|
||||
pub gfx_hardware_acceleration: bool,
|
||||
pub gfx_force_x11: bool,
|
||||
pub gfx_gdk_scale: Option<String>,
|
||||
pub gfx_gdk_dpi_scale: Option<String>,
|
||||
pub gfx_gsk_renderer: Option<String>,
|
||||
|
||||
// Graphics: runtime (what actually applied at startup)
|
||||
pub runtime_using_fallback: bool,
|
||||
pub runtime_is_wayland: bool,
|
||||
pub runtime_has_nvidia: bool,
|
||||
pub runtime_has_amd: bool,
|
||||
pub runtime_has_intel: bool,
|
||||
pub runtime_is_vm: bool,
|
||||
pub runtime_hw_accel_enabled: bool,
|
||||
pub runtime_force_x11_active: bool,
|
||||
|
||||
// Developer settings
|
||||
pub dev_force_dmabuf: bool,
|
||||
|
||||
// Environment variables (what WebKit actually sees)
|
||||
pub env_webkit_disable_dmabuf: Option<String>,
|
||||
pub env_webkit_disable_compositing: Option<String>,
|
||||
pub env_gdk_backend: Option<String>,
|
||||
pub env_gsk_renderer: Option<String>,
|
||||
pub env_libgl_always_software: Option<String>,
|
||||
pub env_wayland_display: Option<String>,
|
||||
pub env_xdg_session_type: Option<String>,
|
||||
|
||||
// App info
|
||||
pub app_version: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn v2_get_runtime_diagnostics(
|
||||
audio_state: State<'_, AudioSettingsState>,
|
||||
graphics_state: State<'_, GraphicsSettingsState>,
|
||||
developer_state: State<'_, DeveloperSettingsState>,
|
||||
) -> Result<RuntimeDiagnostics, RuntimeError> {
|
||||
// Audio settings (may not be available before login)
|
||||
let audio = audio_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
// Graphics settings
|
||||
let gfx = graphics_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
// Graphics runtime status (static atomics — always available)
|
||||
let gfx_status = crate::config::graphics_settings::get_graphics_startup_status();
|
||||
|
||||
// Developer settings
|
||||
let dev = developer_state
|
||||
.store
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|g| g.as_ref().and_then(|s| s.get_settings().ok()));
|
||||
|
||||
let env_var = |name: &str| std::env::var(name).ok();
|
||||
|
||||
let audio_defaults = crate::config::audio_settings::AudioSettings::default();
|
||||
let audio = audio.unwrap_or(audio_defaults);
|
||||
let gfx = gfx.unwrap_or_default();
|
||||
let dev = dev.unwrap_or_default();
|
||||
|
||||
Ok(RuntimeDiagnostics {
|
||||
audio_output_device: audio.output_device,
|
||||
audio_backend_type: audio.backend_type.map(|b| format!("{:?}", b)),
|
||||
audio_exclusive_mode: audio.exclusive_mode,
|
||||
audio_dac_passthrough: audio.dac_passthrough,
|
||||
audio_preferred_sample_rate: audio.preferred_sample_rate,
|
||||
audio_alsa_plugin: audio.alsa_plugin.map(|p| format!("{:?}", p)),
|
||||
audio_alsa_hardware_volume: audio.alsa_hardware_volume,
|
||||
audio_normalization_enabled: audio.normalization_enabled,
|
||||
audio_normalization_target_lufs: audio.normalization_target_lufs,
|
||||
audio_gapless_enabled: audio.gapless_enabled,
|
||||
audio_pw_force_bitperfect: audio.pw_force_bitperfect,
|
||||
audio_stream_buffer_seconds: audio.stream_buffer_seconds,
|
||||
audio_streaming_only: audio.streaming_only,
|
||||
|
||||
gfx_hardware_acceleration: gfx.hardware_acceleration,
|
||||
gfx_force_x11: gfx.force_x11,
|
||||
gfx_gdk_scale: gfx.gdk_scale,
|
||||
gfx_gdk_dpi_scale: gfx.gdk_dpi_scale,
|
||||
gfx_gsk_renderer: gfx.gsk_renderer,
|
||||
|
||||
runtime_using_fallback: gfx_status.using_fallback,
|
||||
runtime_is_wayland: gfx_status.is_wayland,
|
||||
runtime_has_nvidia: gfx_status.has_nvidia,
|
||||
runtime_has_amd: gfx_status.has_amd,
|
||||
runtime_has_intel: gfx_status.has_intel,
|
||||
runtime_is_vm: gfx_status.is_vm,
|
||||
runtime_hw_accel_enabled: gfx_status.hardware_accel_enabled,
|
||||
runtime_force_x11_active: gfx_status.force_x11_active,
|
||||
|
||||
dev_force_dmabuf: dev.force_dmabuf,
|
||||
|
||||
env_webkit_disable_dmabuf: env_var("WEBKIT_DISABLE_DMABUF_RENDERER"),
|
||||
env_webkit_disable_compositing: env_var("WEBKIT_DISABLE_COMPOSITING_MODE"),
|
||||
env_gdk_backend: env_var("GDK_BACKEND"),
|
||||
env_gsk_renderer: env_var("GSK_RENDERER"),
|
||||
env_libgl_always_software: env_var("LIBGL_ALWAYS_SOFTWARE"),
|
||||
env_wayland_display: env_var("WAYLAND_DISPLAY"),
|
||||
env_xdg_session_type: env_var("XDG_SESSION_TYPE"),
|
||||
|
||||
app_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
})
|
||||
}
|
||||
mod diagnostics;
|
||||
pub use diagnostics::*;
|
||||
Reference in new issue
Block a user