tauri_plugin_android_fs/api/
utils.rs1use sync_async::sync_async;
2use crate::*;
3use super::*;
4
5
6#[sync_async]
8pub struct Utils<'a, R: tauri::Runtime> {
9 #[cfg(target_os = "android")]
10 pub(crate) handle: &'a tauri::plugin::PluginHandle<R>,
11
12 #[cfg(not(target_os = "android"))]
13 #[allow(unused)]
14 pub(crate) handle: &'a std::marker::PhantomData<fn() -> R>,
15}
16
17#[cfg(target_os = "android")]
18#[sync_async(
19 use(if_sync) impls::SyncImpls as Impls;
20 use(if_async) impls::AsyncImpls as Impls;
21)]
22impl<'a, R: tauri::Runtime> Utils<'a, R> {
23
24 #[always_sync]
25 fn impls(&self) -> Impls<'_, R> {
26 Impls { handle: &self.handle }
27 }
28}
29
30#[sync_async(
31 use(if_async) api_async::{AndroidFs, ProgressNotificationGuard};
32 use(if_sync) api_sync::{AndroidFs, ProgressNotificationGuard};
33)]
34impl<'a, R: tauri::Runtime> Utils<'a, R> {
35
36 #[maybe_async]
61 pub fn create_progress_notification(
62 &self,
63 icon: ProgressNotificationIcon,
64 title: Option<&str>,
65 text: Option<&str>,
66 sub_text: Option<&str>,
67 progress: Option<u64>,
68 progress_max: Option<u64>,
69 ) -> Result<ProgressNotificationGuard<R>> {
70
71 #[cfg(not(target_os = "android"))] {
72 Err(Error::NOT_ANDROID)
73 }
74 #[cfg(target_os = "android")] {
75 ProgressNotificationGuard::with_new_notification(
76 icon,
77 title.map(|s| s.to_string()),
78 text.map(|s| s.to_string()),
79 sub_text.map(|s| s.to_string()),
80 progress,
81 progress_max,
82 self.handle.clone()
83 ).await
84 }
85 }
86
87 #[maybe_async]
88 pub fn cancel_all_notifications(&self) -> Result<()> {
89 #[cfg(not(target_os = "android"))] {
90 Err(Error::NOT_ANDROID)
91 }
92 #[cfg(target_os = "android")] {
93 self.impls().cancel_all_notifications().await
94 }
95 }
96
97 #[maybe_async]
102 pub fn request_notification_permission(&self) -> Result<bool> {
103 #[cfg(not(target_os = "android"))] {
104 Err(Error::NOT_ANDROID)
105 }
106 #[cfg(target_os = "android")] {
107 self.impls().request_notification_permission().await
108 }
109 }
110
111 #[maybe_async]
112 pub fn check_notification_permission(&self) -> Result<bool> {
113 #[cfg(not(target_os = "android"))] {
114 Err(Error::NOT_ANDROID)
115 }
116 #[cfg(target_os = "android")] {
117 self.impls().check_notification_permission().await
118 }
119 }
120}