Skip to content

Commit

Permalink
* Fix opening the text editor in Flatpak environment
Browse files Browse the repository at this point in the history
* Include GLib tarball in the repo
* Change the release date
  • Loading branch information
donadigo committed Dec 18, 2021
1 parent cc1c4b7 commit 6af82e3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
4 changes: 2 additions & 2 deletions com.github.donadigo.appeditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"sources": [
{
"type": "archive",
"url": "https://download.gnome.org/sources/glib/2.70/glib-2.70.0.tar.xz",
"path": "external/glib-2.70.0.tar.xz",
"sha256": "200d7df811c5ba634afbf109f14bb40ba7fde670e89389885da14e27c0840742"
},
{
"type": "patch",
"path": "glib-appinfo.patch"
"path": "external/glib-appinfo.patch"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion data/com.github.donadigo.appeditor.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</screenshot>
</screenshots>
<releases>
<release version="1.1.2" date="2021-12-12">
<release version="1.1.2" date="2021-12-18">
<description>
<p>This release makes AppEditor available on elementary OS 6.0.</p>
<p>New translations:</p>
Expand Down
Binary file added external/glib-2.70.0.tar.xz
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/AppInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public class AppEditor.AppInfoView : Gtk.Box {

private void on_open_source_button_clicked () {
try {
desktop_app.open_default_handler (get_screen ());
desktop_app.open_default_handler ();
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Could Not Open This Entry"),
Expand Down
36 changes: 34 additions & 2 deletions src/DesktopApp.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* with this program. If not, see http://www.gnu.org/licenses/.
*/

[DBus (name = "org.freedesktop.portal.OpenURI")]
public interface FDODesktopPortal : Object {
public abstract string open_file (string parent_window, UnixInputStream fd, HashTable<string, Variant> options) throws GLib.Error;
}

public class AppEditor.DesktopApp : Object {
public const char DEFAULT_LIST_SEPARATOR = ';';
public const string LOCAL_APP_NAME_PREFIX = "appeditor-local-application-";
Expand All @@ -36,6 +41,7 @@ public class AppEditor.DesktopApp : Object {
public DesktopAppInfo info { get; construct set; }

private static Icon default_icon;
private static FDODesktopPortal? desktop_portal = null;

static construct {
default_icon = new ThemedIcon (DEFAULT_ICON_NAME);
Expand All @@ -53,13 +59,39 @@ public class AppEditor.DesktopApp : Object {
Object (info: info);
}

public void open_default_handler (Gdk.Screen? screen) throws Error {
private static FDODesktopPortal? get_desktop_portal () throws Error {
if (desktop_portal == null) {
try {
desktop_portal = Bus.get_proxy_sync (
BusType.SESSION,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop"
);
} catch (Error e) {
throw e;
}
}

return desktop_portal;
}

public void open_default_handler () throws Error {
// Gtk.show_uri_on_window does not seem to fully work in a Flatpak environment
// so instead we directly call the freedesktop OpenURI DBus interface instead.
var file = File.new_for_path (info.get_filename ());
InputStream ios = file.read ();
var stream = new UnixInputStream (((UnixInputStream)ios).get_fd (), true);
try {
Gtk.show_uri (screen, file.get_uri (), Gtk.get_current_event_time ());
var portal = get_desktop_portal ();
if (portal != null) {
portal.open_file ("", stream, new GLib.HashTable<string, GLib.Variant> (null, null));
}
} catch (Error e) {
stream.close ();
throw e;
}

stream.close ();
}

public bool get_only_local () {
Expand Down

0 comments on commit 6af82e3

Please sign in to comment.