From add322dfe338d131a6b6e587482ad4ddf866c83d Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Thu, 30 Jan 2025 16:17:40 -0300 Subject: [PATCH] Add support for .flatpakref file handling --- build-aux/io.github.flattool.Warehouse.json | 300 ++++++++---------- data/io.github.flattool.Warehouse.desktop.in | 3 +- ....github.flattool.Warehouse.metainfo.xml.in | 2 + src/main.py | 36 ++- 4 files changed, 177 insertions(+), 164 deletions(-) diff --git a/build-aux/io.github.flattool.Warehouse.json b/build-aux/io.github.flattool.Warehouse.json index c04c1fd..4186ad9 100644 --- a/build-aux/io.github.flattool.Warehouse.json +++ b/build-aux/io.github.flattool.Warehouse.json @@ -1,164 +1,140 @@ { - "id" : "io.github.flattool.Warehouse", - "runtime" : "org.gnome.Platform", - "runtime-version" : "47", - "sdk" : "org.gnome.Sdk", - "command" : "warehouse", - "finish-args" : [ - "--share=ipc", - "--socket=fallback-x11", - "--device=dri", - "--socket=wayland", - "--talk-name=org.freedesktop.Flatpak", - "--filesystem=/var/lib/flatpak/:ro", - "--filesystem=~/.local/share/flatpak/:ro", - "--filesystem=~/.var/app/", - "--filesystem=host-etc" - ], - "cleanup" : [ - "/include", - "/lib/pkgconfig", - "/man", - "/share/doc", - "/share/gtk-doc", - "/share/man", - "/share/pkgconfig", - "*.la", - "*.a" - ], - "build-options" : { - "env" : { - "MOUNT_FUSE_PATH" : "../tmp/" - } - }, - "modules" : [ - { - "name" : "blueprint-compiler", - "buildsystem" : "meson", - "sources" : [ - { - "type" : "git", - "url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler", - "tag" : "v0.14.0" - } - ], - "cleanup" : [ - "*" - ] - }, - { - "name" : "libfuse", - "config-opts" : [ - "UDEV_RULES_PATH=/app/etc/udev/rules.d", - "INIT_D_PATH=/app/etc/init.d" - ], - "cleanup" : [ - "/bin/ulockmgr_server" - ], - "post-install" : [ - "install -m a+rx fusermount-wrapper.sh /app/bin/fusermount" - ], - "sources" : [ - { - "type" : "archive", - "url" : "https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz", - "sha256" : "d0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5" - }, - { - "type" : "patch", - "path" : "fuse-2.9.2-namespace-conflict-fix.patch" - }, - { - "type" : "patch", - "path" : "fuse-disable-sys-mount-under-flatpak.patch" - }, - { - "type" : "patch", - "path" : "fuse-2.9.2-closefrom.patch" - }, - { - "type" : "file", - "path" : "fusermount-wrapper.sh" - } - ] - }, - { - "name": "ostree", - "buildsystem": "autotools", - "config-opts": [ - "--disable-rofiles-fuse" - ], - "sources": [ - { - "type": "git", - "url": "https://github.com/ostreedev/ostree", - "tag": "v2024.9" - } - ] - }, - { - "name": "pyparsing", - "buildsystem": "simple", - "build-commands": [ - "pip3 install --prefix=/app --no-deps ./pyparsing-*.whl" - ], - "sources": [ - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl", - "sha256": "ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" - } - ] - }, - { - "name" : "flatpak", - "buildsystem" : "meson", - "config-opts" : [ - "-Ddocbook_docs=disabled", - "-Dseccomp=disabled", - "-Dsandboxed_triggers=false", - "-Dsystem_helper=disabled", - "-Dsystem_install_dir=/var/lib/flatpak", - "--sysconfdir=/var/run/host/etc", - "-Dman=disabled", - "-Dhttp_backend=curl", - "-Dsystemd=disabled", - "-Dtests=false" - ], - "cleanup" : [ - "/bin/flatpak-bisect", - "/bin/flatpak-coredumpctl", - "/etc/profile.d", - "/lib/systemd", - "/share/dbus-1/interfaces/org.freedesktop.*", - "/share/dbus-1/services/org.freedesktop.*", - "/share/flatpak/triggers", - "/share/gdm", - "/share/zsh" - ], - "post-install" : [ - "cp /usr/bin/update-mime-database /app/bin", - "cp /usr/bin/update-desktop-database /app/bin" - ], - "sources" : [ - { - "type" : "git", - "url" : "https://github.com/flatpak/flatpak.git", - "tag" : "1.15.6" - } - ] - }, - { - "name" : "warehouse", - "builddir" : true, - "buildsystem" : "meson", - "config-opts": [ "-Dprofile=development" ], - "sources" : [ - { - "type" : "dir", - "path" : ".." - } - ] - } - ] + "id": "io.github.flattool.Warehouse", + "runtime": "org.gnome.Platform", + "runtime-version": "47", + "sdk": "org.gnome.Sdk", + "command": "warehouse", + "finish-args": [ + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland", + "--talk-name=org.freedesktop.Flatpak", + "--filesystem=/var/lib/flatpak/:ro", + "--filesystem=~/.local/share/flatpak/:ro", + "--filesystem=~/.var/app/", + "--filesystem=host-etc", + "--filesystem=xdg-download:ro", + "--talk-name=org.freedesktop.FileManager1" + ], + "cleanup": ["/include", "/lib/pkgconfig", "/man", "/share/doc", "/share/gtk-doc", "/share/man", "/share/pkgconfig", "*.la", "*.a"], + "build-options": { + "env": { + "MOUNT_FUSE_PATH": "../tmp/" + } + }, + "modules": [ + { + "name": "blueprint-compiler", + "buildsystem": "meson", + "sources": [ + { + "type": "git", + "url": "https://gitlab.gnome.org/jwestman/blueprint-compiler", + "tag": "v0.14.0" + } + ], + "cleanup": ["*"] + }, + { + "name": "libfuse", + "config-opts": ["UDEV_RULES_PATH=/app/etc/udev/rules.d", "INIT_D_PATH=/app/etc/init.d"], + "cleanup": ["/bin/ulockmgr_server"], + "post-install": ["install -m a+rx fusermount-wrapper.sh /app/bin/fusermount"], + "sources": [ + { + "type": "archive", + "url": "https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz", + "sha256": "d0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5" + }, + { + "type": "patch", + "path": "fuse-2.9.2-namespace-conflict-fix.patch" + }, + { + "type": "patch", + "path": "fuse-disable-sys-mount-under-flatpak.patch" + }, + { + "type": "patch", + "path": "fuse-2.9.2-closefrom.patch" + }, + { + "type": "file", + "path": "fusermount-wrapper.sh" + } + ] + }, + { + "name": "ostree", + "buildsystem": "autotools", + "config-opts": ["--disable-rofiles-fuse"], + "sources": [ + { + "type": "git", + "url": "https://github.com/ostreedev/ostree", + "tag": "v2024.9" + } + ] + }, + { + "name": "pyparsing", + "buildsystem": "simple", + "build-commands": ["pip3 install --prefix=/app --no-deps ./pyparsing-*.whl"], + "sources": [ + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl", + "sha256": "ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" + } + ] + }, + { + "name": "flatpak", + "buildsystem": "meson", + "config-opts": [ + "-Ddocbook_docs=disabled", + "-Dseccomp=disabled", + "-Dsandboxed_triggers=false", + "-Dsystem_helper=disabled", + "-Dsystem_install_dir=/var/lib/flatpak", + "--sysconfdir=/var/run/host/etc", + "-Dman=disabled", + "-Dhttp_backend=curl", + "-Dsystemd=disabled", + "-Dtests=false" + ], + "cleanup": [ + "/bin/flatpak-bisect", + "/bin/flatpak-coredumpctl", + "/etc/profile.d", + "/lib/systemd", + "/share/dbus-1/interfaces/org.freedesktop.*", + "/share/dbus-1/services/org.freedesktop.*", + "/share/flatpak/triggers", + "/share/gdm", + "/share/zsh" + ], + "post-install": ["cp /usr/bin/update-mime-database /app/bin", "cp /usr/bin/update-desktop-database /app/bin"], + "sources": [ + { + "type": "git", + "url": "https://github.com/flatpak/flatpak.git", + "tag": "1.15.6" + } + ] + }, + { + "name": "warehouse", + "builddir": true, + "buildsystem": "meson", + "config-opts": ["-Dprofile=development"], + "sources": [ + { + "type": "dir", + "path": ".." + } + ] + } + ] } diff --git a/data/io.github.flattool.Warehouse.desktop.in b/data/io.github.flattool.Warehouse.desktop.in index 4fa9221..4c95f24 100644 --- a/data/io.github.flattool.Warehouse.desktop.in +++ b/data/io.github.flattool.Warehouse.desktop.in @@ -1,7 +1,7 @@ [Desktop Entry] # Translators: Do not translate the application name Name=Warehouse -Exec=warehouse +Exec=warehouse %F Icon=io.github.flattool.Warehouse Terminal=false Type=Application @@ -10,3 +10,4 @@ StartupNotify=true Keywords=flatpak Comment=Manage all things Flatpak X-Purism-FormFactor=Workstation;Mobile; +MimeType=application/vnd.flatpak.ref;application/vnd.flatpak;x-scheme-handler/flatpak; diff --git a/data/io.github.flattool.Warehouse.metainfo.xml.in b/data/io.github.flattool.Warehouse.metainfo.xml.in index 8676c1d..c4f029a 100644 --- a/data/io.github.flattool.Warehouse.metainfo.xml.in +++ b/data/io.github.flattool.Warehouse.metainfo.xml.in @@ -30,6 +30,8 @@ keyboard pointing touch + application/vnd.flatpak.ref + application/vnd.flatpak 330 diff --git a/src/main.py b/src/main.py index fc4d5d2..61f3806 100644 --- a/src/main.py +++ b/src/main.py @@ -44,7 +44,7 @@ class WarehouseApplication(Adw.Application): def __init__(self): super().__init__( application_id="io.github.flattool.Warehouse", - flags=Gio.ApplicationFlags.DEFAULT_FLAGS, + flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE | Gio.ApplicationFlags.HANDLES_OPEN, ) self.create_action("about", self.on_about_action) self.create_action("preferences", self.on_preferences_action) @@ -188,6 +188,40 @@ class WarehouseApplication(Adw.Application): win = WarehouseWindow(application=self) win.present() + def do_open(self, files, _n_files, _hint): + """Handle files opened from file manager or command line""" + win = self.props.active_window + if not win: + win = WarehouseWindow(application=self) + win.present() + + # Convert GFiles to file paths + file_list = [] + for gfile in files: + file_list.append(gfile) + + # Use existing file drop handler + win.on_file_drop(None, file_list, None, None) + + def do_command_line(self, command_line): + """Handle command line arguments""" + args = command_line.get_arguments() + + if len(args) > 1: # First arg is program name + files = [] + for path in args[1:]: + gfile = Gio.File.new_for_path(path) + if gfile.query_exists(): + files.append(gfile) + + if files: + self.open(files, "") + return 0 + + # No valid files, just activate normally + self.activate() + return 0 + def on_about_action(self, widget, _a): """Callback for the app.about action.""" about = Adw.AboutDialog(