settings tab buttons; autorestart
This commit is contained in:
54
wlx-common/src/config_io.rs
Normal file
54
wlx-common/src/config_io.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use log::error;
|
||||
use std::{path::PathBuf, sync::LazyLock};
|
||||
|
||||
pub enum ConfigRoot {
|
||||
Generic,
|
||||
#[allow(dead_code)]
|
||||
WayVR,
|
||||
}
|
||||
|
||||
const FALLBACK_CONFIG_PATH: &str = "/tmp/wlxoverlay";
|
||||
|
||||
static CONFIG_ROOT_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
if let Some(mut dir) = xdg::BaseDirectories::new().get_config_home() {
|
||||
dir.push("wlxoverlay");
|
||||
return dir;
|
||||
}
|
||||
//Return fallback config path
|
||||
error!("Err: Failed to find config path, using {FALLBACK_CONFIG_PATH}");
|
||||
PathBuf::from(FALLBACK_CONFIG_PATH)
|
||||
});
|
||||
|
||||
pub fn get_config_root() -> PathBuf {
|
||||
CONFIG_ROOT_PATH.clone()
|
||||
}
|
||||
|
||||
impl ConfigRoot {
|
||||
pub fn get_conf_d_path(&self) -> PathBuf {
|
||||
get_config_root().join(match self {
|
||||
Self::Generic => "conf.d",
|
||||
Self::WayVR => "wayvr.conf.d",
|
||||
})
|
||||
}
|
||||
|
||||
// Make sure config directory is present and return root config path
|
||||
pub fn ensure_dir(&self) -> PathBuf {
|
||||
let path = get_config_root();
|
||||
let _ = std::fs::create_dir(&path);
|
||||
|
||||
let path_conf_d = self.get_conf_d_path();
|
||||
let _ = std::fs::create_dir(path_conf_d);
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_file_path(filename: &str) -> PathBuf {
|
||||
get_config_root().join(filename)
|
||||
}
|
||||
|
||||
pub fn load(filename: &str) -> Option<String> {
|
||||
let path = get_config_file_path(filename);
|
||||
log::info!("Loading config: {}", path.to_string_lossy());
|
||||
|
||||
std::fs::read_to_string(path).ok()
|
||||
}
|
||||
@@ -17,6 +17,7 @@ pub trait DashInterface<T> {
|
||||
fn desktop_finder<'a>(&'a mut self, data: &'a mut T) -> &'a mut DesktopFinder;
|
||||
fn general_config<'a>(&'a mut self, data: &'a mut T) -> &'a mut GeneralConfig;
|
||||
fn config_changed(&mut self, data: &mut T);
|
||||
fn restart(&mut self, data: &mut T);
|
||||
}
|
||||
|
||||
pub type BoxDashInterface<T> = Box<dyn DashInterface<T>>;
|
||||
|
||||
@@ -180,4 +180,6 @@ impl DashInterface<()> for DashInterfaceEmulated {
|
||||
}
|
||||
|
||||
fn config_changed(&mut self, _: &mut ()) {}
|
||||
|
||||
fn restart(&mut self, data: &mut ()) {}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod audio;
|
||||
pub mod cache_dir;
|
||||
pub mod common;
|
||||
pub mod config;
|
||||
pub mod config_io;
|
||||
pub mod dash_interface;
|
||||
pub mod dash_interface_emulated;
|
||||
pub mod desktop_finder;
|
||||
|
||||
Reference in New Issue
Block a user