mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 22:29:01 -05:00
use serde default to allow deserializing missing Conf fields
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
pub static CONF: std::sync::LazyLock<Conf> = std::sync::LazyLock::new(Conf::load);
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Conf {
|
||||
/// Parameters from settings pages
|
||||
pub settings: Settings,
|
||||
@@ -55,8 +56,7 @@ pub fn load() -> Self {
|
||||
if let Ok(conf) = confy::load::<Conf>(SNIFFNET_LOWERCASE, Self::FILE_NAME) {
|
||||
conf
|
||||
} else {
|
||||
let _ = confy::store(SNIFFNET_LOWERCASE, Self::FILE_NAME, Conf::default())
|
||||
.log_err(location!());
|
||||
let _ = Conf::default().store();
|
||||
Conf::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
pub struct SizeTuple(pub f32, pub f32);
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct ConfigWindow {
|
||||
pub position: PositionTuple,
|
||||
pub size: SizeTuple,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct ExportPcap {
|
||||
pub(crate) enabled: bool,
|
||||
pub(crate) file_name: String,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Filters {
|
||||
pub(crate) expanded: bool,
|
||||
pub(crate) bpf: String,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use crate::{Language, StyleType};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Settings {
|
||||
pub color_gradient: GradientType,
|
||||
pub language: Language,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct ConfigDevice {
|
||||
pub device_name: String,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
/// Used to contain the notifications configuration set by the user
|
||||
#[derive(Clone, Serialize, Deserialize, Copy, PartialEq, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Notifications {
|
||||
pub volume: u8,
|
||||
pub data_notification: DataNotification,
|
||||
@@ -32,6 +33,7 @@ pub enum Notification {
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug, Copy)]
|
||||
#[serde(default)]
|
||||
pub struct DataNotification {
|
||||
/// Data representation
|
||||
pub data_repr: DataRepr,
|
||||
@@ -101,6 +103,7 @@ pub fn from(value: &str, existing: Option<Self>) -> Self {
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug, Copy)]
|
||||
#[serde(default)]
|
||||
pub struct FavoriteNotification {
|
||||
/// Flag to determine if this notification is enabled
|
||||
pub notify_on_favorite: bool,
|
||||
|
||||
Reference in New Issue
Block a user