tauri_plugin_android_fs/api/
private_storage.rs1use sync_async::sync_async;
2use crate::*;
3use super::*;
4
5
6#[sync_async]
18pub struct PrivateStorage<'a, R: tauri::Runtime> {
19 #[cfg(target_os = "android")]
20 pub(crate) handle: &'a tauri::plugin::PluginHandle<R>,
21
22 #[cfg(not(target_os = "android"))]
23 #[allow(unused)]
24 pub(crate) handle: &'a std::marker::PhantomData<fn() -> R>,
25}
26
27#[cfg(target_os = "android")]
28#[sync_async(
29 use(if_sync) impls::SyncImpls as Impls;
30 use(if_async) impls::AsyncImpls as Impls;
31)]
32impl<'a, R: tauri::Runtime> PrivateStorage<'a, R> {
33
34 #[always_sync]
35 fn impls(&self) -> Impls<'_, R> {
36 Impls { handle: &self.handle }
37 }
38}
39
40#[sync_async(
41 use(if_async) api_async::{AndroidFs, FileOpener, FilePicker, PublicStorage, WritableStream};
42 use(if_sync) api_sync::{AndroidFs, FileOpener, FilePicker, PublicStorage, WritableStream};
43)]
44impl<'a, R: tauri::Runtime> PrivateStorage<'a, R> {
45
46 #[maybe_async]
71 pub fn resolve_path(
72 &self,
73 dir: PrivateDir
74 ) -> Result<std::path::PathBuf> {
75
76 #[cfg(not(target_os = "android"))] {
77 Err(Error::NOT_ANDROID)
78 }
79 #[cfg(target_os = "android")] {
80 self.impls().private_dir_path(dir).map(Clone::clone)
81 }
82 }
83
84 #[maybe_async]
85 #[allow(deprecated)]
86 #[deprecated = "Use `AppStorage::resolve_path` instead"]
87 pub fn resolve_outside_path(
88 &self,
89 volume_id: Option<&StorageVolumeId>,
90 dir: OutsidePrivateDir
91 ) -> Result<std::path::PathBuf> {
92
93 #[cfg(not(target_os = "android"))] {
94 Err(Error::NOT_ANDROID)
95 }
96 #[cfg(target_os = "android")] {
97 self.impls().resolve_dir_path_in_app_storage(volume_id, dir).await
98 }
99 }
100
101 #[deprecated = "Use `AppStorage::get_volumes` instead"]
102 #[maybe_async]
103 pub fn get_volumes(&self) -> Result<Vec<StorageVolume>> {
104 #[cfg(not(target_os = "android"))] {
105 Err(Error::NOT_ANDROID)
106 }
107 #[cfg(target_os = "android")] {
108 self.impls().get_available_storage_volumes_for_app_storage().await
109 }
110 }
111
112 #[deprecated = "Use `AppStorage::get_primary_volume` instead"]
113 #[maybe_async]
114 pub fn get_primary_volume(&self) -> Result<Option<StorageVolume>> {
115 #[cfg(not(target_os = "android"))] {
116 Err(Error::NOT_ANDROID)
117 }
118 #[cfg(target_os = "android")] {
119 self.impls().get_primary_storage_volume_if_available_for_app_storage().await
120 }
121 }
122
123
124 #[deprecated = "use `FileUri::from_path` instead"]
126 #[maybe_async]
127 pub fn resolve_uri(
128 &self,
129 dir: PrivateDir,
130 relative_path: impl AsRef<std::path::Path>
131 ) -> Result<FileUri> {
132
133 #[cfg(not(target_os = "android"))] {
134 Err(Error::NOT_ANDROID)
135 }
136 #[cfg(target_os = "android")] {
137 let mut path = self.resolve_path(dir).await?;
138 path.push(relative_path.as_ref());
139 Ok(path.into())
140 }
141 }
142}