add current song

This commit is contained in:
2026-01-02 16:58:58 +01:00
parent e36bb1ab55
commit a2753bcf66
9 changed files with 596 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ use serde_json::json;
use tauri::{AppHandle, Manager, State};
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
use tauri_plugin_shell::ShellExt;
use reqwest;
struct SidecarState {
child: Mutex<Option<CommandChild>>,
@@ -115,6 +116,24 @@ async fn cast_set_volume(
Ok(())
}
#[tauri::command]
async fn fetch_url(_app: AppHandle, url: String) -> Result<String, String> {
// Simple GET with default client, return body text. Errors are stringified for frontend.
match reqwest::Client::new().get(&url).send().await {
Ok(resp) => {
let status = resp.status();
if !status.is_success() {
return Err(format!("HTTP {} while fetching {}", status, url));
}
match resp.text().await {
Ok(t) => Ok(t),
Err(e) => Err(e.to_string()),
}
}
Err(e) => Err(e.to_string()),
}
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
@@ -168,7 +187,9 @@ pub fn run() {
list_cast_devices,
cast_play,
cast_stop,
cast_set_volume
cast_set_volume,
// allow frontend to request arbitrary URLs via backend (bypass CORS)
fetch_url
])
.run(tauri::generate_context!())
.expect("error while running tauri application");