tauri_plugin_android_fs/
lib.rs

1//! Overview and usage is [here](https://crates.io/crates/tauri-plugin-android-fs)
2
3#![allow(unused_variables)]
4
5mod models;
6mod error;
7mod api;
8
9#[cfg(target_os = "android")]
10mod utils;
11
12pub mod api_level;
13
14pub use models::*;
15pub use error::*;
16pub use api::*;
17
18#[cfg(target_os = "android")]
19pub(crate) use utils::*;
20
21/// Initializes the plugin.
22pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
23    tauri::plugin::Builder::new("android-fs")
24        .setup(|app, api| {
25            use tauri::Manager as _;
26
27            let afs = AndroidFs::new(app.clone(), api)?;
28
29            #[cfg(target_os = "android")] {
30                // Cleanup temporary files;
31                let _ = afs
32                    .private_storage()
33                    .remove_all_tmp_files();
34            }
35
36            app.manage(afs);
37            Ok(())
38        })
39        .build()
40}
41
42pub trait AndroidFsExt<R: tauri::Runtime> {
43
44    fn android_fs(&self) -> &AndroidFs<R>;
45}
46
47impl<R: tauri::Runtime, T: tauri::Manager<R>> AndroidFsExt<R> for T {
48
49    fn android_fs(&self) -> &AndroidFs<R> {
50        self.try_state::<AndroidFs<R>>()
51            .map(|i| i.inner())
52            .expect("You should call tauri_plugin_android_fs::init() and registier it to your project. See https://crates.io/crates/tauri-plugin-android-fs")
53    }
54}