1use 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 events;
16mod ipc;
17mod models;
18mod process;
19
20pub use error::{Error, Result};
21
22#[cfg(desktop)]
23use desktop::Mpv;
24#[cfg(mobile)]
25use mobile::Mpv;
26
27pub trait MpvExt<R: Runtime> {
28 fn mpv(&self) -> &Mpv<R>;
29}
30
31impl<R: Runtime, T: Manager<R>> crate::MpvExt<R> for T {
32 fn mpv(&self) -> &Mpv<R> {
33 self.state::<Mpv<R>>().inner()
34 }
35}
36
37pub fn init<R: Runtime>() -> TauriPlugin<R> {
38 Builder::new("mpv")
39 .invoke_handler(tauri::generate_handler![
40 commands::init,
41 commands::destroy,
42 commands::command,
43 commands::set_video_margin_ratio,
44 ])
45 .setup(|app, api| {
46 #[cfg(mobile)]
47 let mpv = mobile::init(app, api)?;
48 #[cfg(desktop)]
49 let mpv = desktop::init(app, api)?;
50 app.manage(mpv);
51 Ok(())
52 })
53 .build()
54}