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:
wfx 2026-01-14 20:54:42 +01:00
parent afdee6b430
commit e71a97a2cb
4 changed files with 53 additions and 10 deletions

View file

@ -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),

View file

@ -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,
}