use sync_async::sync_async;
use crate::*;
use super::*;
#[sync_async]
pub struct PrivateStorage<'a, R: tauri::Runtime> {
#[cfg(target_os = "android")]
pub(crate) handle: &'a tauri::plugin::PluginHandle<R>,
#[cfg(not(target_os = "android"))]
#[allow(unused)]
pub(crate) handle: &'a std::marker::PhantomData<fn() -> R>,
}
#[cfg(target_os = "android")]
#[sync_async(
use(if_sync) impls::SyncImpls as Impls;
use(if_async) impls::AsyncImpls as Impls;
)]
impl<'a, R: tauri::Runtime> PrivateStorage<'a, R> {
#[always_sync]
fn impls(&self) -> Impls<'_, R> {
Impls { handle: &self.handle }
}
}
#[sync_async(
use(if_async) api_async::{AndroidFs, FileOpener, FilePicker, PublicStorage};
use(if_sync) api_sync::{AndroidFs, FileOpener, FilePicker, PublicStorage};
)]
impl<'a, R: tauri::Runtime> PrivateStorage<'a, R> {
#[maybe_async]
pub fn resolve_path(
&self,
dir: PrivateDir
) -> Result<std::path::PathBuf> {
#[cfg(not(target_os = "android"))] {
Err(Error::NOT_ANDROID)
}
#[cfg(target_os = "android")] {
self.impls().private_dir_path(dir).map(Clone::clone)
}
}
#[maybe_async]
pub fn resolve_uri(
&self,
dir: PrivateDir,
relative_path: impl AsRef<std::path::Path>
) -> Result<FileUri> {
#[cfg(not(target_os = "android"))] {
Err(Error::NOT_ANDROID)
}
#[cfg(target_os = "android")] {
let mut path = self.resolve_path(dir).await?;
path.push(relative_path.as_ref());
Ok(path.into())
}
}
}