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_settings_wallpaper as wallpaper;
|
||||
use std::collections::VecDeque;
|
||||
use std::env;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ const CURRENT_FOLDER: &str = "current-folder";
|
|||
const CUSTOM_COLORS: &str = "custom-colors";
|
||||
const CUSTOM_IMAGES: &str = "custom-images";
|
||||
const RECENT_FOLDERS: &str = "recent-folders";
|
||||
const BACKGROUNDS_DIR: &'static str = "backgrounds";
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Config {
|
||||
|
|
@ -100,37 +102,27 @@ impl Config {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn current_folder(&self) -> &Path {
|
||||
pub fn current_folder(&self) -> PathBuf {
|
||||
self.current_folder
|
||||
.as_deref()
|
||||
.clone()
|
||||
.unwrap_or(Self::default_folder())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn default_folder() -> &'static Path {
|
||||
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);
|
||||
pub fn default_folder() -> PathBuf {
|
||||
if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS") {
|
||||
if let Some(data_dirs) = data_dirs.to_str() {
|
||||
let data_dirs = data_dirs.split(":");
|
||||
|
||||
// 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
|
||||
for data_dir in data_dirs {
|
||||
let potential_path = PathBuf::from(data_dir).join(BACKGROUNDS_DIR);
|
||||
if let Ok(true) = &potential_path.try_exists() {
|
||||
return potential_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ impl page::Page<crate::pages::Message> for Page {
|
|||
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 (service_config, displays) = wallpaper::config().await;
|
||||
|
|
@ -490,9 +490,7 @@ impl Page {
|
|||
|
||||
let entry = match self.selection.active {
|
||||
Choice::Slideshow => {
|
||||
match self
|
||||
.config_wallpaper_entry(output, self.config.current_folder().to_path_buf())
|
||||
{
|
||||
match self.config_wallpaper_entry(output, self.config.current_folder()) {
|
||||
Some(entry) => entry,
|
||||
None => return,
|
||||
}
|
||||
|
|
@ -588,7 +586,7 @@ impl Page {
|
|||
if self.config.current_folder.is_some() {
|
||||
let _ = self.config.set_current_folder(None);
|
||||
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)
|
||||
});
|
||||
} else {
|
||||
|
|
@ -968,7 +966,7 @@ impl Page {
|
|||
if let Choice::Wallpaper(_) | Choice::Slideshow = self.selection.active {
|
||||
let folder = self.config.current_folder();
|
||||
for (id, recent) in self.config.recent_folders().iter().enumerate() {
|
||||
if recent == folder {
|
||||
if &folder == recent {
|
||||
self.categories.selected = Some(Category::RecentFolder(id));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ use cosmic_settings_page as page;
|
|||
use slab::Slab;
|
||||
use slotmap::Key;
|
||||
use std::borrow::Cow;
|
||||
use std::{io, mem};
|
||||
use std::str::FromStr;
|
||||
use std::{io, mem};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ShortcutMessage {
|
||||
|
|
@ -535,7 +535,7 @@ impl Model {
|
|||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
||||
let prev_binding = mem::replace(&mut shortcut.binding, new_binding.clone());
|
||||
|
||||
|
||||
shortcut.is_saved = true;
|
||||
shortcut.input.clear();
|
||||
|
||||
|
|
@ -544,7 +544,7 @@ impl Model {
|
|||
}
|
||||
|
||||
let action = model.action.clone();
|
||||
|
||||
|
||||
if shortcut.is_default {
|
||||
self.config_add(Action::Disable, prev_binding);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue