summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Welsh <contact@evanwelsh.com>2021-02-20 10:15:46 -0800
committerEvan Welsh <contact@evanwelsh.com>2021-02-20 11:07:36 -0800
commit9a63beca91871787eaba200bb4a600b57fc7c7e4 (patch)
tree47641bd4a9651434eef2c935c06b08ff54765ffc
parentfcb70ff6540ed89bf2491145cbe8024b17ce32d7 (diff)
downloadgnome-shell-wip/ewlsh/protocol.tar.gz
Implement gnome-extensions:// protocol.wip/ewlsh/protocol
Add a simple protocol to install extensions. Currently supports gnome-extensions://install?uuid=name@name.com
-rw-r--r--subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in1
-rw-r--r--subprojects/extensions-app/js/main.js48
2 files changed, 48 insertions, 1 deletions
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 a935780b7..3a1d4d961 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 d4b6ec79f..a691cac93 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();