2012-01-19 02:21:56 +00:00
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Gettext = imports.gettext;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Pango = imports.gi.Pango;
|
2012-05-04 21:23:08 +00:00
|
|
|
const Format = imports.format;
|
2012-01-19 02:21:56 +00:00
|
|
|
|
|
|
|
const _ = Gettext.gettext;
|
|
|
|
|
|
|
|
const Config = imports.misc.config;
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
|
|
|
2013-10-24 21:51:58 +00:00
|
|
|
const GnomeShellIface = '<node> \
|
|
|
|
<interface name="org.gnome.Shell.Extensions"> \
|
|
|
|
<signal name="ExtensionStatusChanged"> \
|
|
|
|
<arg type="s" name="uuid"/> \
|
|
|
|
<arg type="i" name="state"/> \
|
|
|
|
<arg type="s" name="error"/> \
|
|
|
|
</signal> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2012-01-19 02:21:56 +00:00
|
|
|
|
|
|
|
const GnomeShellProxy = Gio.DBusProxy.makeProxyWrapper(GnomeShellIface);
|
|
|
|
|
|
|
|
function stripPrefix(string, prefix) {
|
|
|
|
if (string.slice(0, prefix.length) == prefix)
|
|
|
|
return string.slice(prefix.length);
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Application = new Lang.Class({
|
|
|
|
Name: 'Application',
|
|
|
|
_init: function() {
|
|
|
|
GLib.set_prgname('gnome-shell-extension-prefs');
|
|
|
|
this.application = new Gtk.Application({
|
|
|
|
application_id: 'org.gnome.shell.ExtensionPrefs',
|
|
|
|
flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE
|
|
|
|
});
|
|
|
|
|
|
|
|
this.application.connect('activate', Lang.bind(this, this._onActivate));
|
|
|
|
this.application.connect('command-line', Lang.bind(this, this._onCommandLine));
|
|
|
|
this.application.connect('startup', Lang.bind(this, this._onStartup));
|
|
|
|
|
|
|
|
this._extensionPrefsModules = {};
|
|
|
|
|
|
|
|
this._extensionIters = {};
|
2013-02-28 13:50:56 +00:00
|
|
|
this._startupUuid = null;
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildModel: function() {
|
|
|
|
this._model = new Gtk.ListStore();
|
|
|
|
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_extensionAvailable: function(uuid) {
|
2012-01-31 01:58:29 +00:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
if (!extension)
|
2012-01-19 02:21:56 +00:00
|
|
|
return false;
|
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
if (ExtensionUtils.isOutOfDate(extension))
|
2012-01-19 02:21:56 +00:00
|
|
|
return false;
|
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
if (!extension.dir.get_child('prefs.js').query_exists(null))
|
2012-01-19 02:21:56 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setExtensionInsensitive: function(layout, cell, model, iter, data) {
|
|
|
|
let uuid = model.get_value(iter, 0);
|
2012-02-13 14:22:55 +00:00
|
|
|
cell.set_sensitive(this._extensionAvailable(uuid));
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
_getExtensionPrefsModule: function(extension) {
|
|
|
|
let uuid = extension.metadata.uuid;
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
if (this._extensionPrefsModules.hasOwnProperty(uuid))
|
|
|
|
return this._extensionPrefsModules[uuid];
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
ExtensionUtils.installImporter(extension);
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
let prefsModule = extension.imports.prefs;
|
|
|
|
prefsModule.init(extension.metadata);
|
|
|
|
|
|
|
|
this._extensionPrefsModules[uuid] = prefsModule;
|
2012-01-19 02:21:56 +00:00
|
|
|
return prefsModule;
|
|
|
|
},
|
|
|
|
|
|
|
|
_selectExtension: function(uuid) {
|
|
|
|
if (!this._extensionAvailable(uuid))
|
|
|
|
return;
|
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
2012-01-19 02:21:56 +00:00
|
|
|
let widget;
|
|
|
|
|
|
|
|
try {
|
2012-01-31 01:58:29 +00:00
|
|
|
let prefsModule = this._getExtensionPrefsModule(extension);
|
|
|
|
widget = prefsModule.buildPrefsWidget();
|
2012-01-19 02:21:56 +00:00
|
|
|
} catch (e) {
|
2012-01-31 01:58:29 +00:00
|
|
|
widget = this._buildErrorUI(extension, e);
|
2012-01-19 02:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the current prefs widget, if it exists
|
|
|
|
if (this._extensionPrefsBin.get_child())
|
|
|
|
this._extensionPrefsBin.get_child().destroy();
|
|
|
|
|
|
|
|
this._extensionPrefsBin.add(widget);
|
|
|
|
this._extensionSelector.set_active_iter(this._extensionIters[uuid]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_extensionSelected: function() {
|
|
|
|
let [success, iter] = this._extensionSelector.get_active_iter();
|
|
|
|
if (!success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let uuid = this._model.get_value(iter, 0);
|
|
|
|
this._selectExtension(uuid);
|
|
|
|
},
|
|
|
|
|
2012-01-31 01:58:29 +00:00
|
|
|
_buildErrorUI: function(extension, exc) {
|
2012-01-19 02:21:56 +00:00
|
|
|
let box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
|
|
|
|
let label = new Gtk.Label({
|
2012-01-31 01:58:29 +00:00
|
|
|
label: _("There was an error loading the preferences dialog for %s:").format(extension.metadata.name)
|
2012-01-19 02:21:56 +00:00
|
|
|
});
|
|
|
|
box.add(label);
|
|
|
|
|
|
|
|
let errortext = '';
|
|
|
|
errortext += exc;
|
|
|
|
errortext += '\n\n';
|
|
|
|
errortext += 'Stack trace:\n';
|
|
|
|
|
|
|
|
// Indent stack trace.
|
|
|
|
errortext += exc.stack.split('\n').map(function(line) {
|
|
|
|
return ' ' + line;
|
|
|
|
}).join('\n');
|
|
|
|
|
|
|
|
let scroll = new Gtk.ScrolledWindow({ vexpand: true });
|
|
|
|
let buffer = new Gtk.TextBuffer({ text: errortext });
|
|
|
|
let textview = new Gtk.TextView({ buffer: buffer });
|
|
|
|
textview.override_font(Pango.font_description_from_string('monospace'));
|
|
|
|
scroll.add(textview);
|
|
|
|
box.add(scroll);
|
|
|
|
|
|
|
|
box.show_all();
|
|
|
|
return box;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildUI: function(app) {
|
|
|
|
this._window = new Gtk.ApplicationWindow({ application: app,
|
|
|
|
window_position: Gtk.WindowPosition.CENTER,
|
2012-02-22 23:52:08 +00:00
|
|
|
title: _("GNOME Shell Extension Preferences") });
|
2012-01-19 02:21:56 +00:00
|
|
|
|
|
|
|
this._window.set_size_request(600, 400);
|
|
|
|
|
|
|
|
let vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
|
|
|
|
this._window.add(vbox);
|
|
|
|
|
|
|
|
let toolbar = new Gtk.Toolbar();
|
|
|
|
toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
|
|
|
|
vbox.add(toolbar);
|
|
|
|
let toolitem;
|
|
|
|
|
2012-08-06 03:15:17 +00:00
|
|
|
let label = new Gtk.Label({ label: '<b>' + _("Extension") + '</b>',
|
2012-01-19 02:21:56 +00:00
|
|
|
use_markup: true });
|
|
|
|
toolitem = new Gtk.ToolItem({ child: label });
|
|
|
|
toolbar.add(toolitem);
|
|
|
|
|
|
|
|
this._extensionSelector = new Gtk.ComboBox({ model: this._model,
|
|
|
|
margin_left: 8,
|
|
|
|
hexpand: true });
|
|
|
|
this._extensionSelector.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
|
|
|
|
|
|
|
|
let renderer = new Gtk.CellRendererText();
|
|
|
|
this._extensionSelector.pack_start(renderer, true);
|
|
|
|
this._extensionSelector.add_attribute(renderer, 'text', 1);
|
2012-10-07 20:15:07 +00:00
|
|
|
this._extensionSelector.set_cell_data_func(renderer, Lang.bind(this, this._setExtensionInsensitive));
|
2012-01-19 02:21:56 +00:00
|
|
|
this._extensionSelector.connect('changed', Lang.bind(this, this._extensionSelected));
|
|
|
|
|
|
|
|
toolitem = new Gtk.ToolItem({ child: this._extensionSelector });
|
|
|
|
toolitem.set_expand(true);
|
|
|
|
toolbar.add(toolitem);
|
|
|
|
|
|
|
|
this._extensionPrefsBin = new Gtk.Frame();
|
|
|
|
vbox.add(this._extensionPrefsBin);
|
|
|
|
|
|
|
|
let label = new Gtk.Label({
|
|
|
|
label: _("Select an extension to configure using the combobox above."),
|
|
|
|
vexpand: true
|
|
|
|
});
|
|
|
|
|
|
|
|
this._extensionPrefsBin.add(label);
|
|
|
|
|
|
|
|
this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
|
|
|
|
this._shellProxy.connectSignal('ExtensionStatusChanged', Lang.bind(this, function(proxy, senderName, [uuid, state, error]) {
|
2012-01-31 01:58:29 +00:00
|
|
|
if (ExtensionUtils.extensions[uuid] !== undefined)
|
2012-01-19 02:21:56 +00:00
|
|
|
this._scanExtensions();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._window.show_all();
|
|
|
|
},
|
|
|
|
|
|
|
|
_scanExtensions: function() {
|
2012-06-04 21:14:18 +00:00
|
|
|
let finder = new ExtensionUtils.ExtensionFinder();
|
|
|
|
finder.connect('extension-found', Lang.bind(this, this._extensionFound));
|
|
|
|
finder.scanExtensions();
|
2013-11-04 15:07:44 +00:00
|
|
|
this._extensionsLoaded();
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
_extensionFound: function(finder, extension) {
|
2012-06-04 21:14:18 +00:00
|
|
|
let iter = this._model.append();
|
2012-06-04 22:25:51 +00:00
|
|
|
this._model.set(iter, [0, 1], [extension.uuid, extension.metadata.name]);
|
2012-07-17 00:39:19 +00:00
|
|
|
this._extensionIters[extension.uuid] = iter;
|
2012-06-04 21:14:18 +00:00
|
|
|
},
|
|
|
|
|
2013-02-28 13:50:56 +00:00
|
|
|
_extensionsLoaded: function() {
|
|
|
|
if (this._startupUuid && this._extensionAvailable(this._startupUuid))
|
|
|
|
this._selectExtension(this._startupUuid);
|
|
|
|
this._startupUuid = null;
|
|
|
|
},
|
2012-06-04 21:14:18 +00:00
|
|
|
|
2012-01-19 02:21:56 +00:00
|
|
|
_onActivate: function() {
|
|
|
|
this._window.present();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStartup: function(app) {
|
|
|
|
this._buildModel();
|
|
|
|
this._buildUI(app);
|
|
|
|
this._scanExtensions();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCommandLine: function(app, commandLine) {
|
|
|
|
app.activate();
|
|
|
|
let args = commandLine.get_arguments();
|
|
|
|
if (args.length) {
|
|
|
|
let uuid = args[0];
|
|
|
|
|
|
|
|
// Strip off "extension:///" prefix which fakes a URI, if it exists
|
|
|
|
uuid = stripPrefix(uuid, "extension:///");
|
|
|
|
|
2013-02-28 13:50:56 +00:00
|
|
|
if (this._extensionAvailable(uuid))
|
|
|
|
this._selectExtension(uuid);
|
|
|
|
else
|
|
|
|
this._startupUuid = uuid;
|
2012-01-19 02:21:56 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function initEnvironment() {
|
|
|
|
// Monkey-patch in a "global" object that fakes some Shell utilities
|
|
|
|
// that ExtensionUtils depends on.
|
|
|
|
window.global = {
|
|
|
|
log: function() {
|
|
|
|
print([].join.call(arguments, ', '));
|
|
|
|
},
|
|
|
|
|
|
|
|
logError: function(s) {
|
2012-05-10 01:37:42 +00:00
|
|
|
log('ERROR: ' + s);
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
userdatadir: GLib.build_filenamev([GLib.get_user_data_dir(), 'gnome-shell'])
|
|
|
|
};
|
|
|
|
|
|
|
|
String.prototype.format = Format.format;
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(argv) {
|
|
|
|
initEnvironment();
|
|
|
|
|
|
|
|
Gettext.bindtextdomain(Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
|
|
|
|
Gettext.textdomain(Config.GETTEXT_PACKAGE);
|
|
|
|
|
|
|
|
let app = new Application();
|
|
|
|
app.application.run(argv);
|
|
|
|
}
|