INNER CODE UNIT · Rust
sidecar_status
mouseart2025/AI-Reader-V2 · frontend/src-tauri/src/lib.rs:242
fn sidecar_status(state: State<'_, Mutex<SidecarState>>) -> Result<Option<SidecarInfo>, String> {
let s = state.lock().map_err(|e| format!("Lock error: {e}"))?;
Ok(match (s.port, s.token.clone()) {
(Some(port), Some(token)) => Some(SidecarInfo { port, token }),
_ => None,
})
}
/// Read a bundled resource file (supports both .json and .json.gz)
/// Returns the decompressed JSON string to the frontend.
#[tauri::command]
fn load_resource(app: tauri::AppHandle, path: String) -> Result<String, String> {
let resource_path = app
.path()
.resolve(&path, tauri::path::BaseDirectory::Resource)
.map_err(|e| format!("路径解析失败: {e}"))?;
let bytes = std::fs::read(&resource_path)