diff --git a/README.md b/README.md index a0aa40b3..e6584c32 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 770b8ca4..8e1ee5b7 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 26f00bce..905af21c 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 4548ae10..1678d53e 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -25,7 +25,6 @@ namespace EasySSH { public Gtk.Menu menu { get; private set; } private Gtk.Clipboard clipboard; private Gtk.Clipboard primary_selection; - private string default_filemanager = ""; private SearchToolbar search_toolbar; private Gtk.Grid grid; private Gtk.Revealer search_revealer; @@ -127,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 }; @@ -154,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"); @@ -198,9 +200,8 @@ namespace EasySSH { () => { save_settings (); return false; - }); - - get_default_filemanager (); + } + ); sourcelist.host_edit_clicked.connect ((name) => { sourcelist.edit_conn(name); @@ -227,41 +228,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; @@ -464,12 +430,29 @@ namespace EasySSH { void action_select_all () { current_terminal.select_all (); } + void action_open_in_files () { - if(default_filemanager == "") { + // FIXME: Getting the file manager is not working if sandboxed so disabling at the moment + if (Xdp.Portal.running_under_sandbox ()) { return; } - var command = "sftp://" + current_terminal.host.username + "@" + current_terminal.host.host + ":" + current_terminal.host.port; - Process.spawn_command_line_async (default_filemanager + " " + command); + + if (current_terminal != null) { + // 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_dir ()); + } else { + 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, path, 0); + } catch (Error e) { + warning (e.message); + } + } } void action_search () { @@ -584,4 +567,4 @@ namespace EasySSH { } } -} \ No newline at end of file +}