tauri_plugin_torchlight/
lib.rs1use tauri::{plugin::{Builder, TauriPlugin}, Manager, Runtime};
2
3#[cfg(desktop)]
4mod desktop;
5#[cfg(mobile)]
6mod mobile;
7
8mod commands;
9mod error;
10mod models;
11
12pub use error::{Error, Result};
13
14use crate::commands::{is_available, is_enabled, torch};
15
16#[cfg(desktop)]
17use desktop::Torchlight;
18#[cfg(mobile)]
19use mobile::Torchlight;
20
21pub trait TorchlightExt<R: Runtime> {
22 fn torchlight(&self) -> &Torchlight<R>;
23}
24
25impl<R: Runtime, T: Manager<R>> TorchlightExt<R> for T {
26 fn torchlight(&self) -> &Torchlight<R> {
27 self.state::<Torchlight<R>>().inner()
28 }
29}
30
31pub fn init<R: Runtime>() -> TauriPlugin<R> {
32 Builder::new("torchlight")
33 .invoke_handler(tauri::generate_handler![
34 torch,
35 is_available,
36 is_enabled,
37 ])
38 .setup(|app, api| {
39 #[cfg(mobile)]
40 let torchlight = mobile::init(app, api).unwrap();
41 #[cfg(desktop)]
42 let torchlight = desktop::init(app, api).unwrap();
43 app.manage(torchlight);
44 Ok(())
45 })
46 .build()
47}