Feat: Lädt Konfigurationsdatei aus systemweitem Pfad, wenn Programm als Root ausgeführt wird
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
//! und beim Programmstart automatisch geladen.
|
||||
|
||||
use crate::program;
|
||||
use crate::sudo::is_run_as_root;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
@@ -128,10 +129,19 @@ pub fn get_config() -> &'static AppConfig {
|
||||
|
||||
/// Lädt die Konfiguration aus der Konfigurationsdatei.
|
||||
fn load_config() -> AppConfig {
|
||||
#[cfg(target_os = "linux")]
|
||||
if is_run_as_root() {
|
||||
return confy::load_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME)).unwrap_or_default();
|
||||
}
|
||||
confy::load(&*program::program_name(), CONFIG_NAME).unwrap_or_default()
|
||||
}
|
||||
|
||||
// /// Speichert die übergebene Konfiguration in der Konfigurationsdatei.
|
||||
// fn save_config(config: AppConfig) {
|
||||
// #[cfg(target_os = "linux")]
|
||||
// if is_run_as_root() {
|
||||
// confy::store_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME), config).unwrap();
|
||||
// return;
|
||||
// }
|
||||
// confy::store(&*program::program_name(), CONFIG_NAME, config).unwrap();
|
||||
// }
|
||||
Reference in New Issue
Block a user