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 37 38 39 40 41 42 43 44 45 46 47 48
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/process)
//!
//! This plugin provides APIs to access the current process. To spawn child processes, see the [`shell`](https://github.com/tauri-apps/tauri-plugin-shell) plugin.
#![doc(
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]
use crate::commands::*;
use crate::state::SerialportState;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tauri::{
plugin::{Builder, TauriPlugin},
Manager, Runtime,
};
pub mod commands;
mod error;
pub mod state;
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("serialplugin")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![
available_ports,
cancel_read,
close,
close_all,
force_close,
open,
read,
write,
write_binary,
])
.setup(|app, _| {
app.manage(SerialportState {
serialports: Arc::new(Mutex::new(HashMap::new())),
});
Ok(())
})
.build()
}