From e70ea981ad1c9a836bd9e105067e2c926ec20ee8 Mon Sep 17 00:00:00 2001 From: Dave Patrick Caberto Date: Mon, 24 Jul 2023 11:05:36 +0800 Subject: [PATCH] refactor: use gtk to open containing folder --- build-aux/io.github.seadve.Kooha.Devel.json | 1 - src/application.rs | 34 +++------------------ 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/build-aux/io.github.seadve.Kooha.Devel.json b/build-aux/io.github.seadve.Kooha.Devel.json index bda9cc72..b4dccd9d 100644 --- a/build-aux/io.github.seadve.Kooha.Devel.json +++ b/build-aux/io.github.seadve.Kooha.Devel.json @@ -14,7 +14,6 @@ "--socket=fallback-x11", "--socket=pulseaudio", "--socket=wayland", - "--talk-name=org.freedesktop.FileManager1", "--env=RUST_BACKTRACE=1", "--env=RUST_LOG=kooha=debug", "--env=G_MESSAGES_DEBUG=none", diff --git a/src/application.rs b/src/application.rs index 106bded9..13d6a6eb 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,5 +1,4 @@ use adw::subclass::prelude::*; -use anyhow::{Context, Result}; use gettextrs::gettext; use gtk::{ gio, @@ -169,7 +168,10 @@ impl Application { let uri = param.unwrap().get::().unwrap(); utils::spawn(async move { - if let Err(err) = show_items(&[&uri], "").await { + if let Err(err) = gtk::FileLauncher::new(Some(&gio::File::for_uri(&uri))) + .open_containing_folder_future(obj.main_window().as_ref()) + .await + { tracing::warn!("Failed to show items: {:?}", err); obj.try_show_uri(&uri).await; @@ -221,31 +223,3 @@ impl Default for Application { Self::new() } } - -/// Shows items in the default file manager. -async fn show_items(uris: &[&str], startup_id: &str) -> Result<()> { - let connection = gio::bus_get_future(gio::BusType::Session) - .await - .context("Failed to get session bus")?; - - connection - .call_future( - Some("org.freedesktop.FileManager1"), - "/org/freedesktop/FileManager1", - "org.freedesktop.FileManager1", - "ShowItems", - Some(&(uris, startup_id).to_variant()), - None, - gio::DBusCallFlags::NONE, - -1, - ) - .await - .with_context(|| { - format!( - "Failed to invoke org.freedesktop.FileManager1.ShowItems with uris: {:?}", - &uris - ) - })?; - - Ok(()) -}