1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
mod windows;
use tauri::{
  plugin::{Builder, TauriPlugin},
  Runtime,
};

#[tauri::command]
// this will be accessible with `invoke('plugin:printer|get_printers')`.
fn get_printers() -> String {
  if cfg!(windows) {
      return windows::get_printers();
  }

  panic!("Unsupported OS");
}

#[tauri::command(rename_all = "snake_case")]
// this will be accessible with `invoke('plugin:printer|print_pdf')`.
fn print_pdf(path: String, driver_name: String) -> String {
  if cfg!(windows) {
      return windows::print_pdf(path, driver_name);
  }

  panic!("Unsupported OS");
}


pub fn init<R: Runtime>() -> TauriPlugin<R> {
  if cfg!(windows) {
    windows::init_windows();
}
  Builder::new("printer")
    .invoke_handler(tauri::generate_handler![get_printers, print_pdf])
    .build()
}