#[cfg(target_arch = "wasm32")]
pub use crate::web::{DirectoryHandle, FileHandle, WritableFileStream};
#[cfg(not(target_arch = "wasm32"))]
pub use crate::native::{DirectoryHandle, FileHandle, WritableFileStream};
#[cfg(not(target_arch = "wasm32"))]
mod native_root;
#[cfg(not(target_arch = "wasm32"))]
pub use native_root::{configure_app, configure_root};
pub type Error = <DirectoryHandle as crate::DirectoryHandle>::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(target_arch = "wasm32")]
pub async fn app_specific_dir() -> Result<DirectoryHandle> {
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::FileSystemDirectoryHandle;
let global = js_sys::global();
let storage = if let Some(window) = global.dyn_ref::<web_sys::Window>() {
window.navigator().storage()
} else if let Some(worker) = global.dyn_ref::<web_sys::WorkerGlobalScope>() {
worker.navigator().storage()
} else {
return Err("No window or worker global scope".into());
};
let root_directory_handle =
FileSystemDirectoryHandle::from(JsFuture::from(storage.get_directory()).await?);
Ok(DirectoryHandle::from(root_directory_handle))
}
#[cfg(not(target_arch = "wasm32"))]
pub async fn app_specific_dir() -> Result<DirectoryHandle> {
let root = native_root::configured_root()?;
tokio::fs::create_dir_all(root).await?;
Ok(DirectoryHandle::from(root.to_owned()))
}