app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 9ac979c736abd2ef0e5058cd68930774d996a412
parent 1027e3b1cbd7b0fa96aa64538c6f29827f64be22
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 16:28:24 +0000

app: add init completion storage helpers

- add app init storage key and helper functions
- read/write/reset completion flag via localStorage on wasm
- keep non-wasm behavior safe with tests
- re-export init helpers for app use

Diffstat:
MCargo.toml | 1+
Mapp/src/init.rs | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mapp/src/lib.rs | 4++++
3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -76,6 +76,7 @@ web-sys = { version = "0.3.77", features = [ "RequestInit", "Response", "ResponseType", + "Storage", "Url", ] } wasm-bindgen-futures = "0.4" diff --git a/app/src/init.rs b/app/src/init.rs @@ -14,6 +14,11 @@ use radroots_app_core::idb::{ }; use radroots_app_core::keystore::{RadrootsClientKeystoreError, RadrootsClientWebKeystoreNostr}; +#[cfg(target_arch = "wasm32")] +use leptos::prelude::window; + +pub const APP_INIT_STORAGE_KEY: &str = "radroots.app.init.ready"; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AppInitError { Idb(RadrootsClientIdbStoreError), @@ -48,6 +53,44 @@ pub struct AppBackends { pub type AppInitResult<T> = Result<T, AppInitError>; +pub fn app_init_has_completed() -> bool { + #[cfg(target_arch = "wasm32")] + { + let window = window(); + match window.local_storage() { + Ok(Some(storage)) => match storage.get_item(APP_INIT_STORAGE_KEY) { + Ok(Some(value)) => value == "1", + _ => false, + }, + _ => false, + } + } + #[cfg(not(target_arch = "wasm32"))] + { + false + } +} + +pub fn app_init_mark_completed() { + #[cfg(target_arch = "wasm32")] + { + let window = window(); + if let Ok(Some(storage)) = window.local_storage() { + let _ = storage.set_item(APP_INIT_STORAGE_KEY, "1"); + } + } +} + +pub fn app_init_reset() { + #[cfg(target_arch = "wasm32")] + { + let window = window(); + if let Ok(Some(storage)) = window.local_storage() { + let _ = storage.remove_item(APP_INIT_STORAGE_KEY); + } + } +} + pub async fn app_init_backends() -> AppInitResult<AppBackends> { idb_store_bootstrap(RADROOTS_IDB_DATABASE, None) .await @@ -104,4 +147,15 @@ mod tests { AppInitError::Idb(RadrootsClientIdbStoreError::IdbUndefined) ); } + + #[test] + fn app_init_has_completed_is_false_on_native() { + assert!(!super::app_init_has_completed()); + } + + #[test] + fn app_init_reset_is_noop_on_native() { + super::app_init_mark_completed(); + super::app_init_reset(); + } } diff --git a/app/src/lib.rs b/app/src/lib.rs @@ -7,8 +7,12 @@ mod entry; pub use app::App; pub use init::{ app_init_backends, + app_init_has_completed, + app_init_mark_completed, + app_init_reset, AppBackends, AppInitError, AppInitErrorMessage, AppInitResult, + APP_INIT_STORAGE_KEY, };