diff --git a/Cargo.toml b/Cargo.toml index 910221a..f79c5e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ toml = "0.7.2" tokio = { version = "1", features = ["full"] } log = "0.4" dirs = "4.0.0" -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive", "rc"] } image = "0.24.5" async-trait = "0.1.66" futures-util = "0.3.27" diff --git a/src/device.rs b/src/device.rs index 2fbb507..c5ee923 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,13 +1,14 @@ use crate::{ modules::{retrieve_module_from_name, start_module, HostEvent}, Button, ConfigError, DeviceConfig, + skip_if_none, unwrap_or_error }; use deck_driver as streamdeck; use hidapi::HidApi; use std::{ collections::HashMap, - fmt::{self, Display}, - sync::Arc, + fmt::Display, + sync::Arc, cell::Cell, }; use streamdeck::{ asynchronous::{AsyncStreamDeck, ButtonStateUpdate}, @@ -16,24 +17,12 @@ use streamdeck::{ }; use tokio::{ process::Command, - sync::{ - mpsc::{self, error::TrySendError}, - Mutex, - }, - task::JoinHandle, + sync::mpsc::{self, error::TrySendError}, + runtime::Runtime, }; use tracing::{debug, error, info_span, trace}; -macro_rules! skip_if_none { - ($res:expr) => { - match $res { - Some(v) => v, - None => continue, - } - }; -} - -pub type ModuleController = (Button, JoinHandle<()>, mpsc::Sender); +pub type ModuleController = (Arc