Files
gpx.studio/tauri/src/commands/storage.rs
T

48 lines
1.3 KiB
Rust
Raw Normal View History

2026-10-14 19:15:02 +02:00
//! What the frontend knows of the storage, which is kept by the engine thread (see `state`).
2026-10-14 08:51:38 +02:00
2026-10-14 19:15:02 +02:00
use std::collections::BTreeMap;
use gpx_engine::api;
2026-10-14 08:51:38 +02:00
use serde::Serialize;
use tauri::State;
use crate::state::AppState;
/// What opening the storage found.
#[derive(Serialize)]
pub struct StorageOpened {
2026-10-14 19:15:02 +02:00
settings: BTreeMap<String, String>,
/// All the files of the engine as added: the frontend starts with none.
outcome: api::Outcome,
2026-10-14 08:51:38 +02:00
}
2026-10-14 19:15:02 +02:00
/// The files were restored when the app started: the frontend is told about all of them.
2026-10-14 08:51:38 +02:00
#[tauri::command(async)]
pub fn open_storage(state: State<AppState>) -> StorageOpened {
StorageOpened {
2026-10-14 19:15:02 +02:00
settings: state.storage().settings(),
outcome: state.read(api::Outcome::everything),
2026-10-14 08:51:38 +02:00
}
}
2026-10-14 19:15:02 +02:00
/// Resolves when what was changed has been written to the storage, which is the case when a command
/// returns.
2026-10-14 08:51:38 +02:00
#[tauri::command(async)]
pub fn flush_storage() {}
2026-10-14 19:15:02 +02:00
/// There is no other writer.
2026-10-14 08:51:38 +02:00
#[tauri::command(async)]
2026-10-14 19:15:02 +02:00
pub fn sync_storage() -> api::Outcome {
api::Outcome::failed_none()
2026-10-14 08:51:38 +02:00
}
/// Saves a setting, `value` being its JSON.
#[tauri::command(async)]
pub fn set_setting(state: State<AppState>, key: String, value: String) {
2026-10-14 19:15:02 +02:00
state.put_setting(&key, &value);
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
pub fn delete_setting(state: State<AppState>, key: String) {
2026-10-14 19:15:02 +02:00
state.delete_setting(&key);
2026-10-14 08:51:38 +02:00
}