tauri_plugin_android_fs/
lib.rs1#![allow(unused_variables)]
4
5mod models;
6mod consts;
7mod utils;
8
9pub mod api;
10
11pub use models::*;
12pub use consts::*;
13
14#[allow(unused_imports)]
15pub(crate) use utils::*;
16
17pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
31 tauri::plugin::Builder::new("android-fs")
32 .setup(|app, api| {
33 use tauri::Manager as _;
34
35 #[cfg(target_os = "android")] {
36 let handle = api.register_android_plugin("com.plugin.android_fs", "AndroidFsPlugin")?;
37 let afs_sync = crate::api::api_sync::AndroidFs { handle: handle.clone() };
38 let afs_async = crate::api::api_async::AndroidFs { handle: handle.clone() };
39
40 afs_sync.impls().remove_all_tmp_files().ok();
42
43 app.manage(afs_sync);
44 app.manage(afs_async);
45 }
46 #[cfg(not(target_os = "android"))] {
47 let afs_sync = crate::api::api_sync::AndroidFs::<R> { handle: Default::default() };
48 let afs_async = crate::api::api_async::AndroidFs::<R> { handle: Default::default() };
49 app.manage(afs_sync);
50 app.manage(afs_async);
51 }
52
53 Ok(())
54 })
55 .build()
56}
57
58pub trait AndroidFsExt<R: tauri::Runtime> {
59
60 fn android_fs(&self) -> &api::api_sync::AndroidFs<R>;
61
62 fn android_fs_async(&self) -> &api::api_async::AndroidFs<R>;
63}
64
65impl<R: tauri::Runtime, T: tauri::Manager<R>> AndroidFsExt<R> for T {
66
67 fn android_fs(&self) -> &api::api_sync::AndroidFs<R> {
68 self.try_state::<api::api_sync::AndroidFs<R>>()
69 .map(|i| i.inner())
70 .expect("should register this plugin by tauri_plugin_android_fs::init(). see https://crates.io/crates/tauri-plugin-android-fs")
71 }
72
73 fn android_fs_async(&self) -> &api::api_async::AndroidFs<R> {
74 self.try_state::<api::api_async::AndroidFs<R>>()
75 .map(|i| i.inner())
76 .expect("should register this plugin by tauri_plugin_android_fs::init(). see https://crates.io/crates/tauri-plugin-android-fs")
77 }
78}