[gnome-shell/wip/ewlsh/protocol] Implement gnome-extensions:// protocol.




commit 9a63beca91871787eaba200bb4a600b57fc7c7e4
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Feb 20 10:15:46 2021 -0800

    Implement gnome-extensions:// protocol.
    
    Add a simple protocol to install extensions.
    Currently supports gnome-extensions://install?uuid=name name com

 .../data/org.gnome.Extensions.desktop.in.in        |  1 +
 subprojects/extensions-app/js/main.js              | 48 +++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in 
b/subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in
index a935780b7d..3a1d4d9617 100644
--- a/subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in
+++ b/subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in
@@ -5,6 +5,7 @@ Name=Extensions
 Icon=@app_id@
 Comment=Configure GNOME Shell Extensions
 Exec=@bindir@/@prgname@
+MimeType=x-scheme-handler/gnome-extensions;
 DBusActivatable=true
 Categories=GNOME;GTK;Utility;
 OnlyShowIn=GNOME;
diff --git a/subprojects/extensions-app/js/main.js b/subprojects/extensions-app/js/main.js
index d4b6ec79fd..a691cac930 100644
--- a/subprojects/extensions-app/js/main.js
+++ b/subprojects/extensions-app/js/main.js
@@ -41,7 +41,10 @@ var Application = GObject.registerClass(
 class Application extends Gtk.Application {
     _init() {
         GLib.set_prgname('gnome-extensions-app');
-        super._init({ application_id: Package.name });
+        super._init({
+            application_id: Package.name,
+            flags: Gio.ApplicationFlags.HANDLES_OPEN,
+        });
 
         this.connect('window-removed', (a, window) => window.run_dispose());
     }
@@ -55,6 +58,49 @@ class Application extends Gtk.Application {
         this._window.present();
     }
 
+    vfunc_open(files) {
+        this.activate();
+
+        let fileUris = files.map(f => f.get_uri());
+        if (fileUris.length !== 1)
+            return;
+
+        const [fileUri] = fileUris;
+
+        try {
+            const uri = GLib.Uri.parse(fileUri, GLib.UriFlags.NONE);
+
+            const scheme = uri.get_scheme();
+            const host = uri.get_host();
+            const params = GLib.Uri.parse_params(uri.get_query(), -1, ';', GLib.UriFlags.NONE);
+
+            if (scheme !== 'gnome-extensions') {
+                log(`Invalid protocol: ${scheme}`);
+                return;
+            }
+
+            if (host === 'install' && 'uuid' in params) {
+                const uuid = params['uuid'];
+                this._shellProxy.InstallRemoteExtensionRemote(uuid, (res, error) => {
+                    if (res.toString() === 'successful' && !error)
+                        log(`Installed ${uuid}`);
+
+                    if (!error)
+                        return;
+
+                    if (error.message.endsWith('404'))
+                        log(`Extension not found: ${uuid}`);
+                    else
+                        log(`Failed to install ${uuid}: ${error.message}`);
+                });
+            } else {
+                log(`Unsupported action or missing parameters: ${host}`);
+            }
+        } catch (e) {
+            logError(e, `Failed to open ${fileUri}`);
+        }
+    }
+
     vfunc_startup() {
         super.vfunc_startup();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]