From 3e69ba5b23c0b2d8bc25a5ec413cb6d664f27f92 Mon Sep 17 00:00:00 2001 From: Ryo Nakano <26003928+ryonakano@users.noreply.github.com> Date: Tue, 16 Nov 2021 22:41:04 +0900 Subject: [PATCH 1/8] Use AppInfo to get default filemanager --- src/MainWindow.vala | 56 ++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 50edba1b6..02dd17e17 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -26,7 +26,6 @@ namespace EasySSH { private Gtk.Clipboard clipboard; private Gtk.Clipboard primary_selection; private EasySSH.Settings settings; - private string default_filemanager = ""; private SearchToolbar search_toolbar; private Gtk.Grid grid; private Gtk.Revealer search_revealer; @@ -203,9 +202,8 @@ namespace EasySSH { () => { save_settings (); return false; - }); - - get_default_filemanager (); + } + ); settings.notify["sync-ssh-config"].connect ( () => { @@ -237,41 +235,6 @@ namespace EasySSH { sourcelist.welcome_accounts.hide(); } - private void get_default_filemanager () { - var stdout = ""; - var stderr = ""; - var result = Process.spawn_command_line_sync ("xdg-mime query default inode/directory", - out stdout, - out stderr, - null); - if(result==false) { - print(stderr + "\n"); - return; - } - var filename = stdout; - - var res = Process.spawn_command_line_sync ("cat /usr/share/applications/" + filename, - out stdout, - out stderr, - null); - if(res==false) { - print(stderr + "\n"); - return; - } - var lines = stdout.split("\n"); - var filemanager = ""; - foreach (string line in lines) { - var split_line = line.split("="); - if(split_line[0] == "Exec") { - filemanager = split_line[1].replace("%U", ""); - break; - } - } - if(filemanager != "") { - default_filemanager = filemanager; - } - } - private TerminalBox? get_term_widget (Granite.Widgets.Tab tab) { if(Type.from_instance(tab.page).name() == "EasySSHConnection") { return null; @@ -468,11 +431,20 @@ namespace EasySSH { current_terminal.select_all (); } void action_open_in_files () { - if(default_filemanager == "") { + var default_filemanager = AppInfo.get_default_for_type ("inode/directory", true); + if (default_filemanager == null) { return; } - var command = "sftp://" + current_terminal.host.username + "@" + current_terminal.host.host + ":" + current_terminal.host.port; - Process.spawn_command_line_async (default_filemanager + " " + command); + + var uris = new List(); + uris.append (File.new_for_uri ("sftp://%s@%s:%s".printf ( + current_terminal.host.username, current_terminal.host.host, current_terminal.host.port + ))); + try { + default_filemanager.launch (uris, null); + } catch (Error e) { + warning (e.message); + } } void action_search () { From 37b691d701b99aed114df71ddb2e75e8ed8d735f Mon Sep 17 00:00:00 2001 From: Ryo Nakano <26003928+ryonakano@users.noreply.github.com> Date: Wed, 17 Nov 2021 13:40:16 +0900 Subject: [PATCH 2/8] Take no action if current_terminal is null --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 02dd17e17..d8edfb785 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -432,7 +432,7 @@ namespace EasySSH { } void action_open_in_files () { var default_filemanager = AppInfo.get_default_for_type ("inode/directory", true); - if (default_filemanager == null) { + if (default_filemanager == null || current_terminal == null) { return; } From 3927fa3874480baa6771f825be350c1422d80402 Mon Sep 17 00:00:00 2001 From: Ryo Nakano <26003928+ryonakano@users.noreply.github.com> Date: Wed, 17 Nov 2021 18:58:26 +0900 Subject: [PATCH 3/8] Use Gtk.show_uri_on_window instead --- src/MainWindow.vala | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d8edfb785..8552d43aa 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -431,17 +431,10 @@ namespace EasySSH { current_terminal.select_all (); } void action_open_in_files () { - var default_filemanager = AppInfo.get_default_for_type ("inode/directory", true); - if (default_filemanager == null || current_terminal == null) { - return; - } - - var uris = new List(); - uris.append (File.new_for_uri ("sftp://%s@%s:%s".printf ( - current_terminal.host.username, current_terminal.host.host, current_terminal.host.port - ))); try { - default_filemanager.launch (uris, null); + Gtk.show_uri_on_window (this, "sftp://%s@%s:%s".printf ( + current_terminal.host.username, current_terminal.host.host, current_terminal.host.port + ), 0); } catch (Error e) { warning (e.message); } From 021ee36570c3aeba5af2c7d7598190a16f3b8e3b Mon Sep 17 00:00:00 2001 From: Ryo Nakano <26003928+ryonakano@users.noreply.github.com> Date: Mon, 29 Nov 2021 08:58:34 +0900 Subject: [PATCH 4/8] Have a null check --- src/MainWindow.vala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d50432e50..bde475c00 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -427,13 +427,16 @@ namespace EasySSH { void action_select_all () { current_terminal.select_all (); } + void action_open_in_files () { - try { - Gtk.show_uri_on_window (this, "sftp://%s@%s:%s".printf ( - current_terminal.host.username, current_terminal.host.host, current_terminal.host.port - ), 0); - } catch (Error e) { - warning (e.message); + if (current_terminal != null) { + try { + Gtk.show_uri_on_window (this, "sftp://%s@%s:%s".printf ( + current_terminal.host.username, current_terminal.host.host, current_terminal.host.port + ), 0); + } catch (Error e) { + warning (e.message); + } } } From 32aac3b4ebf853fd5a8cfbffe7f13ac57f9e6a5e Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 27 May 2023 12:58:21 +0900 Subject: [PATCH 5/8] Enable file manager option only when running natively This option is not working in Flatpak in main branch anyways, so just enable on unsandboxed environment and make the code much simpler. --- README.md | 1 + com.github.muriloventuroso.easyssh.yml | 10 +++++++++ meson.build | 3 ++- src/MainWindow.vala | 30 ++++++++++++++++---------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a0aa40b37..e6584c32a 100755 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ If you want to hack on and build EasySSH yourself, you'll need the following dep - libgranite-dev (>= 6.0.0) - libvte-2.91-dev - libjson-glib-dev +- libportal-dev - meson - valac - gpg diff --git a/com.github.muriloventuroso.easyssh.yml b/com.github.muriloventuroso.easyssh.yml index 770b8ca46..8e1ee5b7a 100644 --- a/com.github.muriloventuroso.easyssh.yml +++ b/com.github.muriloventuroso.easyssh.yml @@ -21,6 +21,16 @@ modules: - type: archive url: https://download.gnome.org/sources/vte/0.70/vte-0.70.1.tar.xz sha256: 1f4601cbfea5302b96902208c8f185e5b18b259b5358bc93cf392bf59871c5b6 + - name: libportal + buildsystem: meson + config-opts: + - '-Dbackends=gtk3' + - '-Ddocs=false' + - '-Dtests=false' + sources: + - type: archive + url: https://github.com/flatpak/libportal/releases/download/0.6/libportal-0.6.tar.xz + sha256: 88a12c3ba71bc31acff7238c280de697d609cebc50830c3766776ec35abc6566 - name: easyssh buildsystem: meson sources: diff --git a/meson.build b/meson.build index 26f00bce1..905af21cd 100755 --- a/meson.build +++ b/meson.build @@ -34,6 +34,7 @@ dependencies = [ dependency('gtk+-3.0'), dependency('granite', version: '>=6.0.0'), dependency('json-glib-1.0'), + dependency('libportal'), dependency('vte-2.91', version: '>0.52'), dependency('gee-0.8'), meson.get_compiler('c').find_library('m', required : false) @@ -74,4 +75,4 @@ executable( meson.add_install_script('meson/post_install.py') subdir('data') -subdir('po') \ No newline at end of file +subdir('po') diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bde475c00..c3496f19b 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -126,14 +126,6 @@ namespace EasySSH { app.set_accels_for_action (ACTION_PREFIX + action, action_accelerators[action].to_array ()); } - var open_in_file_manager_menuitem = new Gtk.MenuItem () { - action_name = ACTION_PREFIX + ACTION_OPEN_IN_FILES - }; - var open_in_file_manager_menuitem_label = new Granite.AccelLabel.from_action_name ( - _("Show in File Browser"), open_in_file_manager_menuitem.action_name - ); - open_in_file_manager_menuitem.add (open_in_file_manager_menuitem_label); - var copy_menuitem = new Gtk.MenuItem () { action_name = ACTION_PREFIX + ACTION_COPY }; @@ -153,13 +145,24 @@ namespace EasySSH { select_all_menuitem.add (select_all_menuitem_label); menu = new Gtk.Menu (); - menu.append (open_in_file_manager_menuitem); - menu.append (new Gtk.SeparatorMenuItem ()); menu.append (copy_menuitem); menu.append (paste_menuitem); menu.append (select_all_menuitem); menu.insert_action_group ("win", actions); + // Getting the file manager is not working if sandboxed so don't expose that menu + if (!Xdp.Portal.running_under_sandbox ()) { + var open_in_file_manager_menuitem = new Gtk.MenuItem () { + action_name = ACTION_PREFIX + ACTION_OPEN_IN_FILES + }; + var open_in_file_manager_menuitem_label = new Granite.AccelLabel.from_action_name ( + _("Show in File Browser"), open_in_file_manager_menuitem.action_name + ); + open_in_file_manager_menuitem.add (open_in_file_manager_menuitem_label); + menu.prepend (new Gtk.SeparatorMenuItem ()); + menu.prepend (open_in_file_manager_menuitem); + } + weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default (); default_theme.add_resource_path ("/com/github/muriloventuroso/easyssh"); @@ -429,6 +432,11 @@ namespace EasySSH { } void action_open_in_files () { + // FIXME: Getting the file manager is not working if sandboxed so disabling at the moment + if (!Xdp.Portal.running_under_sandbox ()) { + return; + } + if (current_terminal != null) { try { Gtk.show_uri_on_window (this, "sftp://%s@%s:%s".printf ( @@ -552,4 +560,4 @@ namespace EasySSH { } } -} \ No newline at end of file +} From 04eda49ac8561452fd5f1bb7abda5742a8e3ff2a Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 27 May 2023 13:37:42 +0900 Subject: [PATCH 6/8] Use ftp path only when it's not local --- src/MainWindow.vala | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index c3496f19b..ab9c49049 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -438,10 +438,17 @@ namespace EasySSH { } if (current_terminal != null) { - try { - Gtk.show_uri_on_window (this, "sftp://%s@%s:%s".printf ( + // FIXME: Looks like we don't have data internally where is current working directory... + string dir; + if (current_terminal.host.local) { + dir = GLib.Environment.get_current_dir (); + } else { + dir = "sftp://%s@%s:%s".printf ( current_terminal.host.username, current_terminal.host.host, current_terminal.host.port - ), 0); + ); + } + try { + Gtk.show_uri_on_window (this, dir, 0); } catch (Error e) { warning (e.message); } From aefe6de8dc0389ddafec1a51644693c50e8b6410 Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 27 May 2023 13:55:05 +0900 Subject: [PATCH 7/8] Fix oops --- src/MainWindow.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ab9c49049..1004c0414 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -433,22 +433,22 @@ namespace EasySSH { void action_open_in_files () { // FIXME: Getting the file manager is not working if sandboxed so disabling at the moment - if (!Xdp.Portal.running_under_sandbox ()) { + if (Xdp.Portal.running_under_sandbox ()) { return; } if (current_terminal != null) { // FIXME: Looks like we don't have data internally where is current working directory... - string dir; + string path; if (current_terminal.host.local) { - dir = GLib.Environment.get_current_dir (); + path = "file://%s".printf (GLib.Environment.get_current_path ()); } else { - dir = "sftp://%s@%s:%s".printf ( + path = "sftp://%s@%s:%s".printf ( current_terminal.host.username, current_terminal.host.host, current_terminal.host.port ); } try { - Gtk.show_uri_on_window (this, dir, 0); + Gtk.show_uri_on_window (this, path, 0); } catch (Error e) { warning (e.message); } From ee0458b3bcec4fe9727d8b0b5a194b1f0163c436 Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 27 May 2023 13:57:04 +0900 Subject: [PATCH 8/8] Fix wrong replacement --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 1004c0414..1678d53e3 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -441,7 +441,7 @@ namespace EasySSH { // FIXME: Looks like we don't have data internally where is current working directory... string path; if (current_terminal.host.local) { - path = "file://%s".printf (GLib.Environment.get_current_path ()); + path = "file://%s".printf (GLib.Environment.get_current_dir ()); } else { path = "sftp://%s@%s:%s".printf ( current_terminal.host.username, current_terminal.host.host, current_terminal.host.port