Implement gnome-extensions:// protocol.

Add a simple protocol to install extensions.
Currently supports gnome-extensions://install?uuid=name@name.com
This commit is contained in:
Evan Welsh 2021-02-20 10:15:46 -08:00
parent fcb70ff654
commit 9a63beca91
No known key found for this signature in database
GPG key ID: 091203D0E8238805
2 changed files with 48 additions and 1 deletions

View file

@ -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;

View file

@ -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();