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