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",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
"cosmic-settings-daemon",
|
"cosmic-settings-daemon",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"iced_futures",
|
"iced_futures",
|
||||||
"known-folders",
|
"known-folders",
|
||||||
|
|
@ -1318,7 +1318,7 @@ dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
"csscolorparser",
|
"csscolorparser",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"palette",
|
"palette",
|
||||||
"ron",
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -1518,13 +1518,34 @@ dependencies = [
|
||||||
"crypto-common",
|
"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]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "6.0.0"
|
version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||||
dependencies = [
|
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]]
|
[[package]]
|
||||||
|
|
@ -1535,7 +1556,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"option-ext",
|
"option-ext",
|
||||||
"redox_users",
|
"redox_users 0.5.2",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -3610,6 +3631,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"dirs 5.0.1",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"i18n-embed",
|
"i18n-embed",
|
||||||
|
|
@ -4793,6 +4815,17 @@ dependencies = [
|
||||||
"bitflags 2.10.0",
|
"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]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ i18n-embed-fl = "0.10"
|
||||||
# Misc utilities
|
# Misc utilities
|
||||||
open = "5.3.2"
|
open = "5.3.2"
|
||||||
rust-embed = "8.8.0"
|
rust-embed = "8.8.0"
|
||||||
|
dirs = "5.0"
|
||||||
image = "0.25.9"
|
image = "0.25.9"
|
||||||
clap = { version = "4.5.54", features = ["derive"] }
|
clap = { version = "4.5.54", features = ["derive"] }
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
|
|
|
||||||
|
|
@ -75,9 +75,19 @@ impl cosmic::Application for Noctua {
|
||||||
|
|
||||||
let mut model = AppModel::new(config.clone());
|
let mut model = AppModel::new(config.clone());
|
||||||
|
|
||||||
// Use CLI arguments from `flags` to open initial file or folder.
|
|
||||||
let Flags::Args(args) = flags;
|
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);
|
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>> {
|
fn update(&mut self, message: Self::Message) -> Task<Action<Self::Message>> {
|
||||||
match &message {
|
match &message {
|
||||||
// Handle nav bar toggle.
|
// Handle nav bar toggle. I think this is ugly but it works.
|
||||||
AppMessage::ToggleNavBar => {
|
AppMessage::ToggleNavBar => {
|
||||||
self.config.nav_bar_visible = !self.config.nav_bar_visible;
|
self.config.nav_bar_visible = !self.config.nav_bar_visible;
|
||||||
self.core.nav_bar_set_toggled(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.
|
// Zoom.
|
||||||
Key::Character("+") | Key::Character("=") => Some(ZoomIn),
|
Key::Character("+" |"=") => Some(ZoomIn),
|
||||||
Key::Character("-") => Some(ZoomOut),
|
Key::Character("-") => Some(ZoomOut),
|
||||||
Key::Character("1") => Some(ZoomReset),
|
Key::Character("1") => Some(ZoomReset),
|
||||||
Key::Character(ch) if ch.eq_ignore_ascii_case("f") => Some(ZoomFit),
|
Key::Character(ch) if ch.eq_ignore_ascii_case("f") => Some(ZoomFit),
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ pub struct AppConfig {
|
||||||
impl Default for AppConfig {
|
impl Default for AppConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// TODO: Use xdg dir for picture
|
default_image_dir: dirs::picture_dir().or_else(dirs::home_dir),
|
||||||
default_image_dir: Some(PathBuf::from("~/Pictures")),
|
|
||||||
nav_bar_visible: false,
|
nav_bar_visible: false,
|
||||||
context_drawer_visible: false,
|
context_drawer_visible: false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue