tauri_plugin_video/
lib.rs1use tauri::{
2 plugin::{Builder as TauriBuilder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8mod commands;
9#[cfg(desktop)]
10mod desktop;
11mod error;
12#[cfg(mobile)]
13mod mobile;
14mod models;
15
16pub use error::{Error, Result};
17
18pub struct Video<R: Runtime> {
20 _app: tauri::AppHandle<R>,
21 #[cfg(desktop)]
22 desktop: desktop::DesktopVideo<R>,
23 #[cfg(mobile)]
24 mobile: mobile::MobileVideo<R>,
25}
26
27impl<R: Runtime> Video<R> {
28 fn new(
29 app: tauri::AppHandle<R>,
30 #[cfg(desktop)] desktop: desktop::DesktopVideo<R>,
31 #[cfg(mobile)] mobile: mobile::MobileVideo<R>,
32 ) -> Self {
33 Self {
34 _app: app,
35 #[cfg(desktop)]
36 desktop,
37 #[cfg(mobile)]
38 mobile,
39 }
40 }
41
42 #[cfg(desktop)]
43 pub(crate) fn desktop(&self) -> &desktop::DesktopVideo<R> {
44 &self.desktop
45 }
46
47 #[cfg(mobile)]
48 pub(crate) fn mobile(&self) -> &mobile::MobileVideo<R> {
49 &self.mobile
50 }
51}
52
53pub trait VideoExt<R: Runtime> {
55 fn video(&self) -> tauri::State<'_, Video<R>>;
56}
57
58impl<R: Runtime, T: Manager<R>> VideoExt<R> for T {
59 fn video(&self) -> tauri::State<'_, Video<R>> {
60 self.state::<Video<R>>()
61 }
62}
63
64pub struct Builder;
66
67impl Default for Builder {
68 fn default() -> Self {
69 Self::new()
70 }
71}
72
73impl Builder {
74 pub fn new() -> Self {
75 Self
76 }
77
78 pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
79 TauriBuilder::new("video")
80 .invoke_handler(tauri::generate_handler![
81 commands::native_diagnostics,
82 commands::native_open,
83 commands::native_control,
84 commands::native_layout,
85 commands::native_stats,
86 commands::native_close,
87 ])
88 .setup(move |app, api| {
89 #[cfg(mobile)]
90 let mobile = mobile::init(app, api)?;
91 #[cfg(desktop)]
92 let desktop = desktop::init(app, api)?;
93
94 let video = Video::new(
95 app.clone(),
96 #[cfg(desktop)]
97 desktop,
98 #[cfg(mobile)]
99 mobile,
100 );
101 app.manage(video);
102 Ok(())
103 })
104 .build()
105 }
106}
107
108pub fn init<R: Runtime>() -> TauriPlugin<R> {
110 Builder::new().build()
111}