tauri_plugin_media_toolkit/
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::{cleanup_old_cache, get_media_cache_dir, get_media_output_dir, validate_path};
20
21#[cfg(desktop)]
22use desktop::MediaEditor;
23#[cfg(mobile)]
24use mobile::MediaEditor;
25
26pub trait MediaToolkitExt<R: Runtime> {
28 fn media_toolkit(&self) -> &MediaEditor<R>;
29}
30
31impl<R: Runtime, T: Manager<R>> crate::MediaToolkitExt<R> for T {
32 fn media_toolkit(&self) -> &MediaEditor<R> {
33 self.state::<MediaEditor<R>>().inner()
34 }
35}
36
37pub fn init<R: Runtime>() -> TauriPlugin<R> {
39 Builder::new("media-toolkit")
40 .invoke_handler(tauri::generate_handler![
41 commands::get_media_info,
42 commands::trim,
43 commands::convert,
44 commands::extract_audio,
45 commands::play,
46 commands::pause,
47 commands::resume,
48 commands::stop,
49 commands::seek,
50 commands::get_playback_status,
51 commands::set_volume,
52 commands::select_media_file,
53 commands::check_permission,
54 commands::request_permission,
55 commands::cleanup_cache,
56 ])
57 .setup(|app, api| {
58 #[cfg(mobile)]
59 let media_editor = mobile::init(app, api)?;
60 #[cfg(desktop)]
61 let media_editor = desktop::init(app, api)?;
62 app.manage(media_editor);
63 Ok(())
64 })
65 .build()
66}