app_tauri_plugin_player/
lib.rs

1#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
2#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
3#![allow(clippy::multiple_crate_versions)]
4
5use tauri::{
6    Manager, Runtime,
7    plugin::{Builder, TauriPlugin},
8};
9
10pub use models::*;
11
12#[cfg(desktop)]
13mod desktop;
14#[cfg(mobile)]
15mod mobile;
16
17mod commands;
18mod error;
19mod models;
20
21pub use error::{Error, Result};
22
23#[cfg(desktop)]
24use desktop::Player;
25#[cfg(mobile)]
26use mobile::Player;
27
28/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the player APIs.
29pub trait PlayerExt<R: Runtime> {
30    fn player(&self) -> &Player<R>;
31}
32
33impl<R: Runtime, T: Manager<R>> crate::PlayerExt<R> for T {
34    fn player(&self) -> &Player<R> {
35        self.state::<Player<R>>().inner()
36    }
37}
38
39/// Initializes the plugin.
40#[must_use]
41pub fn init<R: Runtime>() -> TauriPlugin<R> {
42    Builder::new("player")
43        .invoke_handler(tauri::generate_handler![commands::update_state])
44        .setup(|app, api| {
45            #[cfg(mobile)]
46            let player = mobile::init(app, &api)?;
47            #[cfg(desktop)]
48            let player = desktop::init(app, &api);
49            app.manage(player);
50            Ok(())
51        })
52        .build()
53}