From 48b8ce9455b8a4caaad6f8b599fc75c2fc59063d Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Sat, 5 Feb 2022 13:26:33 -0800 Subject: [PATCH] window: Use path instead of URI for "Open With" Fixes an issue where paths with spaces or anything else encoded within the URI could not be opened externally. --- src/widgets/image_view.rs | 2 +- src/window.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index 6ad74c7..1b2fba9 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -371,7 +371,7 @@ impl LpImageView { Ok(()) } - fn current_page(&self) -> Option { + pub fn current_page(&self) -> Option { let carousel = &self.imp().carousel; let pos = carousel.position().round() as u32; if carousel.n_pages() > 0 { diff --git a/src/window.rs b/src/window.rs index bfebcb7..762e99f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -274,10 +274,10 @@ impl LpWindow { if let Some(file) = imp .image_view - .uri() - .map(|u| u.trim_start_matches("file://").to_string()) - .map(|u| std::fs::File::open(u).ok()) - .flatten() + .current_page() + .and_then(|p| p.file()) + .and_then(|f| f.peek_path()) + .and_then(|p| std::fs::File::open(p).ok()) { ctx.spawn_local(clone!(@weak self as win => async move { if let Err(e) = @@ -287,7 +287,7 @@ impl LpWindow { } })); } else { - log::error!("No URI for current image.") + log::error!("Could not load a path for the current image.") } }