more stuff to improve robustness
This commit is contained in:
@ -208,6 +208,17 @@ async fn save_captions(content: String, output_path: String) -> Result<String, S
|
||||
.map_err(|e| format!("Task error: {:?}", e))?
|
||||
}
|
||||
|
||||
/// List downloaded models (Whisper + LLM) with sizes.
|
||||
#[tauri::command]
|
||||
fn log_error(message: String, stack: String, component_stack: String) {
|
||||
log::error!(
|
||||
"[Frontend Error] {} — Stack: {} — Component: {}",
|
||||
message,
|
||||
stack,
|
||||
component_stack,
|
||||
);
|
||||
}
|
||||
|
||||
/// List downloaded models (Whisper + LLM) with sizes.
|
||||
#[tauri::command]
|
||||
fn list_models(app_handle: tauri::AppHandle) -> Result<Vec<models::ModelInfo>, String> {
|
||||
@ -310,6 +321,39 @@ async fn remove_background_on_export(input_path: String, output_path: String, re
|
||||
.map_err(|e| format!("Task error: {:?}", e))?
|
||||
}
|
||||
|
||||
/// Write autosave data to the app data directory
|
||||
#[tauri::command]
|
||||
fn write_autosave(app_handle: tauri::AppHandle, data: String) -> Result<(), String> {
|
||||
let data_dir = app_handle.path().app_data_dir().map_err(|e| format!("No app data directory: {e}"))?;
|
||||
let path = data_dir.join("autosave.json");
|
||||
std::fs::write(&path, data).map_err(|e| format!("Failed to write autosave: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read autosave data if it exists
|
||||
#[tauri::command]
|
||||
fn read_autosave(app_handle: tauri::AppHandle) -> Result<Option<String>, String> {
|
||||
let data_dir = app_handle.path().app_data_dir().map_err(|e| format!("No app data directory: {e}"))?;
|
||||
let path = data_dir.join("autosave.json");
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(data) => Ok(Some(data)),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
|
||||
Err(e) => Err(format!("Failed to read autosave: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the autosave file
|
||||
#[tauri::command]
|
||||
fn delete_autosave(app_handle: tauri::AppHandle) -> Result<(), String> {
|
||||
let data_dir = app_handle.path().app_data_dir().map_err(|e| format!("No app data directory: {e}"))?;
|
||||
let path = data_dir.join("autosave.json");
|
||||
match std::fs::remove_file(&path) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
||||
Err(e) => Err(format!("Failed to delete autosave: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
// --- App entry point ---
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
@ -377,6 +421,10 @@ pub fn run() {
|
||||
has_license_feature,
|
||||
list_models,
|
||||
delete_model,
|
||||
log_error,
|
||||
write_autosave,
|
||||
read_autosave,
|
||||
delete_autosave,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user