fix(config): use XDG picture directory as default
Replace hardcoded \"~/Pictures\" with dirs::picture_dir() which resolves to the actual absolute path (e.g. /home/user/Pictures). The tilde (~) in paths is not automatically expanded by Rust's PathBuf, causing path.exists() to return false for \"~/Pictures\". Using dirs::picture_dir() provides: - Proper absolute path resolution - XDG Base Directory compliance - Fallback to home directory if Pictures doesn't exist Note: Users with existing config files need to delete ~/.config/cosmic/org.codeberg.wfx.Noctua/v1/default_image_dir to apply the new default."
This commit is contained in:
parent
afdee6b430
commit
e71a97a2cb
4 changed files with 53 additions and 10 deletions
41
Cargo.lock
generated
41
Cargo.lock
generated
|
|
@ -1229,7 +1229,7 @@ dependencies = [
|
|||
"atomicwrites",
|
||||
"cosmic-config-derive",
|
||||
"cosmic-settings-daemon",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"futures-util",
|
||||
"iced_futures",
|
||||
"known-folders",
|
||||
|
|
@ -1318,7 +1318,7 @@ dependencies = [
|
|||
"almost",
|
||||
"cosmic-config",
|
||||
"csscolorparser",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"palette",
|
||||
"ron",
|
||||
"serde",
|
||||
|
|
@ -1518,13 +1518,34 @@ dependencies = [
|
|||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
"dirs-sys 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users 0.4.6",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1535,7 +1556,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
|||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"redox_users 0.5.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
|
|
@ -3610,6 +3631,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"dirs 5.0.1",
|
||||
"env_logger",
|
||||
"futures-util",
|
||||
"i18n-embed",
|
||||
|
|
@ -4793,6 +4815,17 @@ dependencies = [
|
|||
"bitflags 2.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom 0.2.16",
|
||||
"libredox",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.2"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ i18n-embed-fl = "0.10"
|
|||
# Misc utilities
|
||||
open = "5.3.2"
|
||||
rust-embed = "8.8.0"
|
||||
dirs = "5.0"
|
||||
image = "0.25.9"
|
||||
clap = { version = "4.5.54", features = ["derive"] }
|
||||
env_logger = "0.11.8"
|
||||
|
|
|
|||
|
|
@ -75,9 +75,19 @@ impl cosmic::Application for Noctua {
|
|||
|
||||
let mut model = AppModel::new(config.clone());
|
||||
|
||||
// Use CLI arguments from `flags` to open initial file or folder.
|
||||
let Flags::Args(args) = flags;
|
||||
if let Some(path) = args.file {
|
||||
|
||||
// Determine initial path: CLI argument takes priority.
|
||||
// Fall back to configured default directory only if it exists.
|
||||
let initial_path = args.file.or_else(|| {
|
||||
config
|
||||
.default_image_dir
|
||||
.as_ref()
|
||||
.filter(|p| p.exists())
|
||||
.cloned()
|
||||
});
|
||||
|
||||
if let Some(path) = initial_path {
|
||||
document::file::open_initial_path(&mut model, path);
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +117,7 @@ impl cosmic::Application for Noctua {
|
|||
|
||||
fn update(&mut self, message: Self::Message) -> Task<Action<Self::Message>> {
|
||||
match &message {
|
||||
// Handle nav bar toggle.
|
||||
// Handle nav bar toggle. I think this is ugly but it works.
|
||||
AppMessage::ToggleNavBar => {
|
||||
self.config.nav_bar_visible = !self.config.nav_bar_visible;
|
||||
self.core.nav_bar_set_toggled(self.config.nav_bar_visible);
|
||||
|
|
@ -216,7 +226,7 @@ fn handle_key_press(key: Key, modifiers: Modifiers) -> Option<AppMessage> {
|
|||
}
|
||||
|
||||
// Zoom.
|
||||
Key::Character("+") | Key::Character("=") => Some(ZoomIn),
|
||||
Key::Character("+" |"=") => Some(ZoomIn),
|
||||
Key::Character("-") => Some(ZoomOut),
|
||||
Key::Character("1") => Some(ZoomReset),
|
||||
Key::Character(ch) if ch.eq_ignore_ascii_case("f") => Some(ZoomFit),
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ pub struct AppConfig {
|
|||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// TODO: Use xdg dir for picture
|
||||
default_image_dir: Some(PathBuf::from("~/Pictures")),
|
||||
default_image_dir: dirs::picture_dir().or_else(dirs::home_dir),
|
||||
nav_bar_visible: false,
|
||||
context_drawer_visible: false,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue