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