use serde default to allow deserializing missing Conf fields

This commit is contained in:
GyulyVGC
2025-08-29 17:40:05 +02:00
parent 8591aed644
commit 0348eff5ec
7 changed files with 10 additions and 2 deletions

View File

@@ -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()
}
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -3,6 +3,7 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
#[serde(default)]
pub struct ConfigDevice {
pub device_name: String,
}

View File

@@ -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,