1515 * with this program. If not, see http://www.gnu.org/licenses/.
1616 */
1717
18+ [DBus (name = " org.freedesktop.portal.OpenURI" )]
19+ public interface FDODesktopPortal : Object {
20+ public abstract string open_file (string parent_window , UnixInputStream fd , HashTable<string, Variant > options ) throws GLib .Error ;
21+ }
22+
1823public class AppEditor.DesktopApp : Object {
1924 public const char DEFAULT_LIST_SEPARATOR = ' ;' ;
2025 public const string LOCAL_APP_NAME_PREFIX = " appeditor-local-application-" ;
@@ -36,6 +41,7 @@ public class AppEditor.DesktopApp : Object {
3641 public DesktopAppInfo info { get ; construct set ; }
3742
3843 private static Icon default_icon;
44+ private static FDODesktopPortal ? desktop_portal = null ;
3945
4046 static construct {
4147 default_icon = new ThemedIcon (DEFAULT_ICON_NAME );
@@ -53,13 +59,39 @@ public class AppEditor.DesktopApp : Object {
5359 Object (info: info);
5460 }
5561
56- public void open_default_handler (Gdk . Screen ? screen) throws Error {
62+ private static FDODesktopPortal ? get_desktop_portal () throws Error {
63+ if (desktop_portal == null ) {
64+ try {
65+ desktop_portal = Bus . get_proxy_sync (
66+ BusType . SESSION ,
67+ " org.freedesktop.portal.Desktop" ,
68+ " /org/freedesktop/portal/desktop"
69+ );
70+ } catch (Error e) {
71+ throw e;
72+ }
73+ }
74+
75+ return desktop_portal;
76+ }
77+
78+ public void open_default_handler () throws Error {
79+ // Gtk.show_uri_on_window does not seem to fully work in a Flatpak environment
80+ // so instead we directly call the freedesktop OpenURI DBus interface instead.
5781 var file = File . new_for_path (info. get_filename ());
82+ InputStream ios = file. read ();
83+ var stream = new UnixInputStream (((UnixInputStream )ios). get_fd (), true );
5884 try {
59- Gtk . show_uri (screen, file. get_uri (), Gtk . get_current_event_time ());
85+ var portal = get_desktop_portal ();
86+ if (portal != null ) {
87+ portal. open_file (" " , stream, new GLib .HashTable<string, GLib . Variant > (null , null ));
88+ }
6089 } catch (Error e) {
90+ stream. close ();
6191 throw e;
6292 }
93+
94+ stream. close ();
6395 }
6496
6597 public bool get_only_local () {
0 commit comments