fix(wallpapers): iterate XDG_DATA_DIRS when loading backgrounds
This commit is contained in:
parent
af75e4832a
commit
93215f8f2d
3 changed files with 21 additions and 31 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::env;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
|
@ -14,6 +15,7 @@ const CURRENT_FOLDER: &str = "current-folder";
|
||||||
const CUSTOM_COLORS: &str = "custom-colors";
|
const CUSTOM_COLORS: &str = "custom-colors";
|
||||||
const CUSTOM_IMAGES: &str = "custom-images";
|
const CUSTOM_IMAGES: &str = "custom-images";
|
||||||
const RECENT_FOLDERS: &str = "recent-folders";
|
const RECENT_FOLDERS: &str = "recent-folders";
|
||||||
|
const BACKGROUNDS_DIR: &'static str = "backgrounds";
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -100,37 +102,27 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn current_folder(&self) -> &Path {
|
pub fn current_folder(&self) -> PathBuf {
|
||||||
self.current_folder
|
self.current_folder
|
||||||
.as_deref()
|
.clone()
|
||||||
.unwrap_or(Self::default_folder())
|
.unwrap_or(Self::default_folder())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn default_folder() -> &'static Path {
|
pub fn default_folder() -> PathBuf {
|
||||||
let is_nixos_like: bool = match std::fs::File::open("/etc/os-release") {
|
if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS") {
|
||||||
Ok(mut file) => {
|
if let Some(data_dirs) = data_dirs.to_str() {
|
||||||
let mut os_release_contents = String::new();
|
let data_dirs = data_dirs.split(":");
|
||||||
let _ = file.read_to_string(&mut os_release_contents);
|
|
||||||
|
|
||||||
// While only want to match for distributions that are either
|
for data_dir in data_dirs {
|
||||||
// NixOS or are based on NixOS.
|
let potential_path = PathBuf::from(data_dir).join(BACKGROUNDS_DIR);
|
||||||
if os_release_contents.contains("ID=nixos")
|
if let Ok(true) = &potential_path.try_exists() {
|
||||||
|| os_release_contents.contains("ID_LIKE=nixos")
|
return potential_path;
|
||||||
{
|
}
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if is_nixos_like {
|
|
||||||
Path::new("/run/current-system/sw/share/backgrounds/")
|
|
||||||
} else {
|
|
||||||
Path::new("/usr/share/backgrounds/")
|
|
||||||
}
|
}
|
||||||
|
PathBuf::from("/usr/share").join(BACKGROUNDS_DIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the current background folder
|
/// Sets the current background folder
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_folder = self.config.current_folder().to_owned();
|
let current_folder = self.config.current_folder();
|
||||||
|
|
||||||
let (task, on_enter_handle) = Task::future(async move {
|
let (task, on_enter_handle) = Task::future(async move {
|
||||||
let (service_config, displays) = wallpaper::config().await;
|
let (service_config, displays) = wallpaper::config().await;
|
||||||
|
|
@ -490,9 +490,7 @@ impl Page {
|
||||||
|
|
||||||
let entry = match self.selection.active {
|
let entry = match self.selection.active {
|
||||||
Choice::Slideshow => {
|
Choice::Slideshow => {
|
||||||
match self
|
match self.config_wallpaper_entry(output, self.config.current_folder()) {
|
||||||
.config_wallpaper_entry(output, self.config.current_folder().to_path_buf())
|
|
||||||
{
|
|
||||||
Some(entry) => entry,
|
Some(entry) => entry,
|
||||||
None => return,
|
None => return,
|
||||||
}
|
}
|
||||||
|
|
@ -588,7 +586,7 @@ impl Page {
|
||||||
if self.config.current_folder.is_some() {
|
if self.config.current_folder.is_some() {
|
||||||
let _ = self.config.set_current_folder(None);
|
let _ = self.config.set_current_folder(None);
|
||||||
task = cosmic::task::future(async move {
|
task = cosmic::task::future(async move {
|
||||||
let folder = change_folder(Config::default_folder().to_owned()).await;
|
let folder = change_folder(Config::default_folder()).await;
|
||||||
Message::ChangeFolder(folder)
|
Message::ChangeFolder(folder)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -968,7 +966,7 @@ impl Page {
|
||||||
if let Choice::Wallpaper(_) | Choice::Slideshow = self.selection.active {
|
if let Choice::Wallpaper(_) | Choice::Slideshow = self.selection.active {
|
||||||
let folder = self.config.current_folder();
|
let folder = self.config.current_folder();
|
||||||
for (id, recent) in self.config.recent_folders().iter().enumerate() {
|
for (id, recent) in self.config.recent_folders().iter().enumerate() {
|
||||||
if recent == folder {
|
if &folder == recent {
|
||||||
self.categories.selected = Some(Category::RecentFolder(id));
|
self.categories.selected = Some(Category::RecentFolder(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ use cosmic_settings_page as page;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
use slotmap::Key;
|
use slotmap::Key;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::{io, mem};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::{io, mem};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum ShortcutMessage {
|
pub enum ShortcutMessage {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue