tauri_plugin_android_fs/models.rs
1use serde::{Deserialize, Serialize};
2
3
4/// Path to represent a file.
5/// This is [`tauri_plugin_fs::FilePath`] for compatibility.
6///
7/// # Note
8/// In this crate, functions that take this as an argument will work correctly if it is the value returned by a function within this crate, at a minimum.
9/// And [`FilePath::Path(_)`](tauri_plugin_fs::FilePath::Path) will not work in this crate.
10///
11/// # Typescript type
12/// ```typescript
13/// type DirPath = string
14/// ```
15pub type FilePath = tauri_plugin_fs::FilePath;
16
17/// Path to represent a directory.
18///
19/// # Typescript type
20/// You should use the following type because it might change in the future, and the inner value should not be used directly.
21/// ```typescript
22/// type DirPath = any
23/// ```
24///
25/// If the version of this crate is 2.x.x at least, it is guaranteed to be in the following format.
26/// ````typescript
27/// type DirPath_ver2XX = {
28/// topTreeUri: string,
29/// relativeTerms: string[]
30/// }
31/// ``````
32#[derive(Clone, Serialize, Deserialize)]
33#[serde(rename_all = "camelCase")]
34pub struct DirPath {
35 pub(crate) top_tree_uri: String,
36 pub(crate) relative_terms: Vec<String>,
37}
38
39/// Path to represent a file or directory.
40///
41/// # Typescript type
42/// ```typescript
43/// type EntryPath =
44/// | { type: "File", path: FilePath }
45/// | { type: "Dir", path: DirPath }
46/// ```
47#[derive(Clone, Deserialize, Serialize)]
48#[serde(tag = "type", content = "path")]
49pub enum EntryPath {
50
51 /// File path
52 File(FilePath),
53
54 /// Directory path
55 Dir(DirPath),
56}
57
58/// Access mode
59#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
60pub enum PersistableAccessMode {
61
62 /// Read-only access.
63 ReadOnly,
64
65 /// Write-only access.
66 WriteOnly,
67
68 /// Read-write access.
69 ReadAndWrite,
70}
71
72/// Filters for VisualMediaPicker.
73#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
74pub enum VisualMediaTarget {
75
76 /// Allow only images to be selected.
77 ImageOnly,
78
79 /// Allow only videos to be selected.
80 VideoOnly,
81
82 /// Allow only images and videos to be selected.
83 ImageAndVideo
84}
85
86/// The application specific directory.
87#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
88#[non_exhaustive]
89pub enum PrivateDir {
90
91 /// The application specific persistent-data directory.
92 ///
93 /// The system prevents other apps from accessing these locations, and on Android 10 (API level 29) and higher, these locations are encrypted.
94 ///
95 /// These files will be deleted when the app is uninstalled and may also be deleted at the user’s request.
96 ///
97 /// ex: `/data/user/0/{app-package-name}/files`
98 Data,
99
100 /// The application specific cache directory.
101 ///
102 /// The system prevents other apps from accessing these locations, and on Android 10 (API level 29) and higher, these locations are encrypted.
103 ///
104 /// These files will be deleted when the app is uninstalled and may also be deleted at the user’s request.
105 /// In addition, the system will automatically delete files in this directory as disk space is needed elsewhere on the device.
106 ///
107 /// ex: `/data/user/0/{app-package-name}/cache`
108 Cache,
109}
110
111/// Directory in which to place images that are available to other applications and users.
112#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
113#[non_exhaustive]
114pub enum PublicImageDir {
115
116 /// Standard directory in which to place pictures that are available to the user.
117 ///
118 /// ex: `~/Pictures`
119 Pictures,
120
121 /// The traditional location for pictures and videos when mounting the device as a camera.
122 ///
123 /// ex: `~/DCIM`
124 DCIM,
125}
126
127/// Directory in which to place videos that are available to other applications and users.
128#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
129#[non_exhaustive]
130pub enum PublicVideoDir {
131
132 /// Standard directory in which to place movies that are available to the user.
133 ///
134 /// ex: `~/Movies`
135 Movies,
136
137 /// The traditional location for pictures and videos when mounting the device as a camera.
138 ///
139 /// ex: `~/DCIM`
140 DCIM,
141}
142
143/// Directory in which to place audios that are available to other applications and users.
144#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
145#[non_exhaustive]
146pub enum PublicAudioDir {
147
148 /// Standard directory in which to place movies that are available to the user.
149 ///
150 /// ex: `~/Music`
151 Music,
152
153 /// Standard directory in which to place any audio files that should be in the list of alarms that the user can select (not as regular music).
154 ///
155 /// ex: `~/Alarms`
156 Alarms,
157
158 /// Standard directory in which to place any audio files that should be in the list of audiobooks that the user can select (not as regular music).
159 ///
160 /// This is not available on Android 9 (API level 28) and lower.
161 /// Availability on a given device can be verified by calling [`PublicStorage::is_audiobooks_dir_available`](crate::PublicStorage::is_audiobooks_dir_available).
162 ///
163 /// ex: `~/Audiobooks`
164 Audiobooks,
165
166 /// Standard directory in which to place any audio files that should be in the list of notifications that the user can select (not as regular music).
167 ///
168 /// ex: `~/Notifications`
169 Notifications,
170
171 /// Standard directory in which to place any audio files that should be in the list of podcasts that the user can select (not as regular music).
172 ///
173 /// ex: `~/Podcasts`
174 Podcasts,
175
176 /// Standard directory in which to place any audio files that should be in the list of ringtones that the user can select (not as regular music).
177 ///
178 /// ex: `~/Ringtones`
179 Ringtones,
180
181 /// Standard directory in which to place any audio files that should be in the list of voice recordings recorded by voice recorder apps that the user can select (not as regular music).
182 ///
183 /// This is not available on Android 11 (API level 30) and lower.
184 /// Availability on a given device can be verified by calling [`PublicStorage::is_recordings_dir_available`](crate::PublicStorage::is_recordings_dir_available).
185 ///
186 /// ex: `~/Recordings`
187 Recordings,
188}
189
190/// Directory in which to place files that are available to other applications and users.
191#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
192#[non_exhaustive]
193pub enum PublicGeneralPurposeDir {
194
195 /// Standard directory in which to place documents that have been created by the user.
196 ///
197 Documents,
198
199 /// Standard directory in which to place files that have been downloaded by the user.
200 ///
201 /// ex: `~/Download`
202 Download,
203}
204
205
206#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
207pub(crate) enum PublicDir {
208 #[serde(untagged)]
209 Image(PublicImageDir),
210
211 #[serde(untagged)]
212 Video(PublicVideoDir),
213
214 #[serde(untagged)]
215 Audio(PublicAudioDir),
216
217 #[serde(untagged)]
218 GeneralPurpose(PublicGeneralPurposeDir),
219}