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