mirror of
https://codeberg.org/Fl1tzi/microdeck.git
synced 2024-05-08 14:40:44 +00:00
fmt
This commit is contained in:
parent
70ace076f8
commit
935a757b1f
|
@ -1,13 +1,13 @@
|
|||
use crate::Config;
|
||||
use dirs::config_dir;
|
||||
use tracing::debug;
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
env,
|
||||
fmt::{self, Display},
|
||||
fs,
|
||||
io::ErrorKind,
|
||||
path::PathBuf
|
||||
path::PathBuf,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
/// The name of the folder which holds the config
|
||||
pub const CONFIG_FOLDER_NAME: &'static str = "virtual-deck";
|
||||
|
@ -18,7 +18,7 @@ pub fn load_config() -> Result<Config, ConfigError> {
|
|||
Some(path) => {
|
||||
debug!("Using env variable: {:?}", path);
|
||||
PathBuf::from(path)
|
||||
},
|
||||
}
|
||||
None => {
|
||||
// try to get the system config dir; env var required if not available
|
||||
if let Some(mut path) = config_dir() {
|
||||
|
@ -27,7 +27,7 @@ pub fn load_config() -> Result<Config, ConfigError> {
|
|||
debug!("Using system path: {:?}", path);
|
||||
path
|
||||
} else {
|
||||
return Err(ConfigError::PathNotAvailable())
|
||||
return Err(ConfigError::PathNotAvailable());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -35,12 +35,14 @@ pub fn load_config() -> Result<Config, ConfigError> {
|
|||
let path = config_file.display().to_string().clone();
|
||||
|
||||
match fs::read_to_string(config_file) {
|
||||
Ok(content) => toml::from_str(&content).map_err(|e| ConfigError::SyntaxError(e.to_string())),
|
||||
Ok(content) => {
|
||||
toml::from_str(&content).map_err(|e| ConfigError::SyntaxError(e.to_string()))
|
||||
}
|
||||
Err(file_error) => {
|
||||
if file_error.kind() == ErrorKind::NotFound {
|
||||
return Err(ConfigError::FilePathDoesNotExist(path))
|
||||
return Err(ConfigError::FilePathDoesNotExist(path));
|
||||
} else {
|
||||
return Err(ConfigError::ReadError(file_error.to_string()))
|
||||
return Err(ConfigError::ReadError(file_error.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +55,9 @@ pub enum ConfigError {
|
|||
PathNotAvailable(),
|
||||
SyntaxError(String),
|
||||
FilePathDoesNotExist(String),
|
||||
ReadError(String)
|
||||
ReadError(String),
|
||||
}
|
||||
|
||||
|
||||
impl Display for ConfigError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
@ -90,4 +91,3 @@ impl Display for ConfigError {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
modules::{retrieve_module_from_name, start_module, HostEvent},
|
||||
config::ConfigError,
|
||||
modules::{retrieve_module_from_name, start_module, HostEvent},
|
||||
skip_if_none, unwrap_or_error, Button, DeviceConfig,
|
||||
};
|
||||
use deck_driver as streamdeck;
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -2,11 +2,7 @@ use deck_driver as streamdeck;
|
|||
use device::Device;
|
||||
use hidapi::HidApi;
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::Arc,
|
||||
time::Duration, process::exit,
|
||||
};
|
||||
use std::{collections::HashMap, process::exit, sync::Arc, time::Duration};
|
||||
use tracing::{debug, error, info, warn};
|
||||
use tracing_subscriber::{
|
||||
self, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter,
|
||||
|
@ -14,10 +10,9 @@ use tracing_subscriber::{
|
|||
|
||||
use config::load_config;
|
||||
|
||||
mod config;
|
||||
mod device;
|
||||
mod modules;
|
||||
mod config;
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! skip_if_none {
|
||||
|
@ -156,7 +151,6 @@ pub async fn start_device(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct DeviceConfig {
|
||||
pub serial: String,
|
||||
|
|
Loading…
Reference in a new issue