tauri_plugin_thermal_printer/
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 commands_esc_pos;
15mod error;
16mod models;
17mod desktop_printers;
18mod process;
19
20pub use commands::*;
21
22#[cfg(desktop)]
23use desktop::ThermalPrinter;
24#[cfg(mobile)]
25use mobile::ThermalPrinter;
26
27
28
29pub trait ThermalPrinterExt<R: Runtime> {
31 fn thermal_printer(&self) -> &ThermalPrinter<R>;
32}
33
34impl<R: Runtime, T: Manager<R>> crate::ThermalPrinterExt<R> for T {
35 fn thermal_printer(&self) -> &ThermalPrinter<R> {
36 self.state::<ThermalPrinter<R>>().inner()
37 }
38}
39
40pub fn init<R: Runtime>() -> TauriPlugin<R> {
42 Builder::new("thermal-printer")
43 .invoke_handler(tauri::generate_handler![commands::print_thermal_printer, commands::list_thermal_printers, commands::test_thermal_printer])
44 .setup(|app, api| {
45 #[cfg(mobile)]
46 let thermal_printer = mobile::init(app, api)?;
47 #[cfg(desktop)]
48 let thermal_printer = desktop::init(app, api)?;
49 app.manage(thermal_printer);
50 Ok(())
51 })
52 .build()
53}