tauri_plugin_audio_recorder/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(desktop)]
9mod desktop;
10#[cfg(mobile)]
11mod mobile;
12
13mod commands;
14mod error;
15mod models;
16mod paths;
17
18pub use error::{Error, Result};
19pub use paths::{get_cache_dir, get_recordings_dir, resolve_output_path, validate_path};
20
21#[cfg(desktop)]
22use desktop::AudioRecorder;
23#[cfg(mobile)]
24use mobile::AudioRecorder;
25
26pub trait AudioRecorderExt<R: Runtime> {
28 fn audio_recorder(&self) -> &AudioRecorder<R>;
29}
30
31impl<R: Runtime, T: Manager<R>> crate::AudioRecorderExt<R> for T {
32 fn audio_recorder(&self) -> &AudioRecorder<R> {
33 self.state::<AudioRecorder<R>>().inner()
34 }
35}
36
37pub fn init<R: Runtime>() -> TauriPlugin<R> {
39 Builder::new("audio-recorder")
40 .invoke_handler(tauri::generate_handler![
41 commands::start_recording,
42 commands::stop_recording,
43 commands::pause_recording,
44 commands::resume_recording,
45 commands::get_status,
46 commands::get_devices,
47 commands::check_permission,
48 commands::request_permission,
49 ])
50 .setup(|app, api| {
51 #[cfg(mobile)]
52 let audio_recorder = mobile::init(app, api)?;
53 #[cfg(desktop)]
54 let audio_recorder = desktop::init(app, api)?;
55 app.manage(audio_recorder);
56 Ok(())
57 })
58 .build()
59}