rework config system

This commit is contained in:
galister
2024-04-04 22:46:39 +09:00
parent 2d0f733c67
commit e3ae9a9890
7 changed files with 431 additions and 263 deletions

View File

@@ -1,7 +1,6 @@
use dbus::{blocking::Connection, channel::MatchingReceiver, message::MatchRule};
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::{
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
mpsc, Arc,
@@ -10,8 +9,6 @@ use std::{
};
use crate::{
config::def_true,
config_io,
overlays::toast::{Toast, ToastTopic},
state::AppState,
};
@@ -238,29 +235,3 @@ struct XsoMessage {
sourceApp: Option<Arc<str>>,
alwaysShow: Option<bool>,
}
#[derive(Deserialize, Serialize)]
pub struct NotifiConf {
#[serde(default = "def_true")]
pub notifications_enabled: bool,
#[serde(default = "def_true")]
pub notifications_sound_enabled: bool,
}
fn get_config_path() -> PathBuf {
let mut path = config_io::get_conf_d_path();
path.push("notifications.yaml");
path
}
pub fn save_notifications(app: &mut AppState) -> anyhow::Result<()> {
let conf = NotifiConf {
notifications_enabled: app.session.config.notifications_enabled,
notifications_sound_enabled: app.session.config.notifications_sound_enabled,
};
let yaml = serde_yaml::to_string(&conf)?;
std::fs::write(get_config_path(), yaml)?;
Ok(())
}