feat: change default_folder path of system backgrounds based on distribution
NixOS is not a Linux distribution that is compliant with the "File Hierarchy System." The top-level directory `/usr` does not exist on NixOS. So on NixOS, we won't find any backgrounds in the `/usr/share/backgrounds/` directory. Instead, what one usually finds in `/usr/share` on FHS-compliant distributions, on NixOS, it is found in the `/run/current-system/sw/share` directory. So, check if we are on NixOS or a NixOS-like distribution by checking the `/etc/os-release` file. If we are on such distribution, use the `/run/current-system/sw/share/backgrounds/` directory. Otherwise, use the `/usr/share/backgrounds/` directory for getting system backgrounds.
This commit is contained in:
parent
78ba1212da
commit
2e2898b31f
1 changed files with 24 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
||||||
use cosmic_bg_config::Source;
|
use cosmic_bg_config::Source;
|
||||||
use cosmic_settings_wallpaper as wallpaper;
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::io::Read;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
const NAME: &str = "com.system76.CosmicSettings.Wallpaper";
|
const NAME: &str = "com.system76.CosmicSettings.Wallpaper";
|
||||||
|
|
@ -107,7 +108,29 @@ impl Config {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn default_folder() -> &'static Path {
|
pub fn default_folder() -> &'static Path {
|
||||||
Path::new("/usr/share/backgrounds/")
|
let is_nixos_like: bool = match std::fs::File::open("/etc/os-release") {
|
||||||
|
Ok(mut file) => {
|
||||||
|
let mut os_release_contents = String::new();
|
||||||
|
let _ = file.read_to_string(&mut os_release_contents);
|
||||||
|
|
||||||
|
// While only want to match for distributions that are either
|
||||||
|
// NixOS or are based on NixOS.
|
||||||
|
if os_release_contents.contains("ID=nixos")
|
||||||
|
|| os_release_contents.contains("ID_LIKE=nixos")
|
||||||
|
{
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if is_nixos_like {
|
||||||
|
Path::new("/run/current-system/sw/share/backgrounds/")
|
||||||
|
} else {
|
||||||
|
Path::new("/usr/share/backgrounds/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the current background folder
|
/// Sets the current background folder
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue