dbusServices/extensions: Take over prefs dialog from app
As outlined earlier, in order to turn the Extensions app into a properly sandboxed application, we need to split out the extension prefs dialog and move it elsewhere. With "elsewhere" being the new Extensions D-Bus service, effectively turning it into a shell extensions portal. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1106
This commit is contained in:

committed by
Florian Müllner

parent
91b7474d5a
commit
34e85342d8
@ -1,7 +1,9 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported ExtensionsService */
|
||||
|
||||
const { Gio, GLib } = imports.gi;
|
||||
const { Gdk, Gio, GLib, GObject, Gtk } = imports.gi;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
|
||||
const { loadInterfaceXML } = imports.misc.fileUtils;
|
||||
const { ServiceImplementation } = imports.dbusService;
|
||||
@ -108,10 +110,25 @@ var ExtensionsService = class extends ServiceImplementation {
|
||||
}
|
||||
|
||||
OpenExtensionPrefsAsync(params, invocation) {
|
||||
this._proxy.OpenExtensionPrefsRemote(...params, (res, error) => {
|
||||
const [uuid, parentWindow_, options] = params;
|
||||
|
||||
this._proxy.GetExtensionInfoRemote(uuid, (res, error) => {
|
||||
if (this._handleError(invocation, error))
|
||||
return;
|
||||
|
||||
const [serialized] = res;
|
||||
const extension = ExtensionUtils.deserializeExtension(serialized);
|
||||
|
||||
const window = new ExtensionPrefsDialog(extension);
|
||||
|
||||
if (options.modal)
|
||||
window.modal = options.modal.get_boolean();
|
||||
|
||||
window.connect('destroy', () => this.release());
|
||||
this.hold();
|
||||
|
||||
window.show();
|
||||
|
||||
invocation.return_value(null);
|
||||
});
|
||||
}
|
||||
@ -125,3 +142,124 @@ var ExtensionsService = class extends ServiceImplementation {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var ExtensionPrefsDialog = GObject.registerClass({
|
||||
GTypeName: 'ExtensionPrefsDialog',
|
||||
Template: 'resource:///org/gnome/Shell/Extensions/ui/extension-prefs-dialog.ui',
|
||||
InternalChildren: [
|
||||
'headerBar',
|
||||
'stack',
|
||||
'expander',
|
||||
'expanderArrow',
|
||||
'revealer',
|
||||
'errorView',
|
||||
],
|
||||
}, class ExtensionPrefsDialog extends Gtk.Window {
|
||||
_init(extension) {
|
||||
super._init();
|
||||
|
||||
this._uuid = extension.uuid;
|
||||
this._url = extension.metadata.url || '';
|
||||
|
||||
this._headerBar.title = extension.metadata.name;
|
||||
|
||||
this._actionGroup = new Gio.SimpleActionGroup();
|
||||
this.insert_action_group('win', this._actionGroup);
|
||||
|
||||
this._initActions();
|
||||
this._addCustomStylesheet();
|
||||
|
||||
this._gesture = new Gtk.GestureMultiPress({
|
||||
widget: this._expander,
|
||||
button: 0,
|
||||
exclusive: true,
|
||||
});
|
||||
|
||||
this._gesture.connect('released', (gesture, nPress) => {
|
||||
if (nPress === 1)
|
||||
this._revealer.reveal_child = !this._revealer.reveal_child;
|
||||
});
|
||||
|
||||
this._revealer.connect('notify::reveal-child', () => {
|
||||
this._expanderArrow.icon_name = this._revealer.reveal_child
|
||||
? 'pan-down-symbolic'
|
||||
: 'pan-end-symbolic';
|
||||
});
|
||||
|
||||
try {
|
||||
ExtensionUtils.installImporter(extension);
|
||||
|
||||
// give extension prefs access to their own extension object
|
||||
ExtensionUtils.getCurrentExtension = () => extension;
|
||||
|
||||
const prefsModule = extension.imports.prefs;
|
||||
prefsModule.init(extension.metadata);
|
||||
|
||||
const widget = prefsModule.buildPrefsWidget();
|
||||
this._stack.add(widget);
|
||||
this._stack.visible_child = widget;
|
||||
} catch (e) {
|
||||
this._setError(e);
|
||||
}
|
||||
}
|
||||
|
||||
_setError(exc) {
|
||||
this._errorView.buffer.text = `${exc}\n\nStack trace:\n`;
|
||||
// Indent stack trace.
|
||||
this._errorView.buffer.text +=
|
||||
exc.stack.split('\n').map(line => ` ${line}`).join('\n');
|
||||
|
||||
// markdown for pasting in gitlab issues
|
||||
let lines = [
|
||||
`The settings of extension ${this._uuid} had an error:`,
|
||||
'```',
|
||||
`${exc}`,
|
||||
'```',
|
||||
'',
|
||||
'Stack trace:',
|
||||
'```',
|
||||
exc.stack.replace(/\n$/, ''), // stack without trailing newline
|
||||
'```',
|
||||
'',
|
||||
];
|
||||
this._errorMarkdown = lines.join('\n');
|
||||
this._actionGroup.lookup('copy-error').enabled = true;
|
||||
}
|
||||
|
||||
_initActions() {
|
||||
let action;
|
||||
|
||||
action = new Gio.SimpleAction({
|
||||
name: 'copy-error',
|
||||
enabled: false,
|
||||
});
|
||||
action.connect('activate', () => {
|
||||
const clipboard = Gtk.Clipboard.get_default(this.get_display());
|
||||
clipboard.set_text(this._errorMarkdown, -1);
|
||||
});
|
||||
this._actionGroup.add_action(action);
|
||||
|
||||
action = new Gio.SimpleAction({
|
||||
name: 'show-url',
|
||||
enabled: this._url !== '',
|
||||
});
|
||||
action.connect('activate', () => {
|
||||
Gio.AppInfo.launch_default_for_uri(this._url,
|
||||
this.get_display().get_app_launch_context());
|
||||
});
|
||||
this._actionGroup.add_action(action);
|
||||
}
|
||||
|
||||
_addCustomStylesheet() {
|
||||
let provider = new Gtk.CssProvider();
|
||||
let uri = 'resource:///org/gnome/Shell/Extensions/css/application.css';
|
||||
try {
|
||||
provider.load_from_file(Gio.File.new_for_uri(uri));
|
||||
} catch (e) {
|
||||
logError(e, 'Failed to add application style');
|
||||
}
|
||||
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
|
||||
provider,
|
||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user