Skip to content

Commit

Permalink
refactor: use gtk to open containing folder
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Jul 24, 2023
1 parent a9d8ac6 commit e70ea98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
1 change: 0 additions & 1 deletion build-aux/io.github.seadve.Kooha.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 4 additions & 30 deletions src/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use adw::subclass::prelude::*;
use anyhow::{Context, Result};
use gettextrs::gettext;
use gtk::{
gio,
Expand Down Expand Up @@ -169,7 +168,10 @@ impl Application {
let uri = param.unwrap().get::<String>().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;
Expand Down Expand Up @@ -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(())
}

0 comments on commit e70ea98

Please sign in to comment.