2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2011-06-11 04:21:35 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2011-09-12 18:17:09 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-10-25 22:53:10 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const St = imports.gi.St;
|
2011-04-05 01:20:44 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2011-08-24 17:08:34 +00:00
|
|
|
const Soup = imports.gi.Soup;
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2011-01-11 21:42:34 +00:00
|
|
|
const Config = imports.misc.config;
|
2011-09-10 21:10:50 +00:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2011-09-12 18:17:09 +00:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2011-01-11 21:42:34 +00:00
|
|
|
|
2011-09-12 18:16:03 +00:00
|
|
|
const API_VERSION = 1;
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
const ExtensionState = {
|
|
|
|
ENABLED: 1,
|
|
|
|
DISABLED: 2,
|
|
|
|
ERROR: 3,
|
2011-06-23 01:56:24 +00:00
|
|
|
OUT_OF_DATE: 4,
|
2011-06-28 02:27:56 +00:00
|
|
|
DOWNLOADING: 5,
|
2011-10-25 18:38:25 +00:00
|
|
|
INITIALIZED: 6,
|
2011-06-23 01:56:24 +00:00
|
|
|
|
|
|
|
// Used as an error state for operations on unknown extensions,
|
|
|
|
// should never be in a real extensionMeta object.
|
|
|
|
UNINSTALLED: 99
|
2009-10-25 22:53:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const ExtensionType = {
|
|
|
|
SYSTEM: 1,
|
|
|
|
PER_USER: 2
|
|
|
|
};
|
|
|
|
|
2011-09-12 18:16:03 +00:00
|
|
|
const REPOSITORY_URL_BASE = 'https://extensions.gnome.org';
|
|
|
|
const REPOSITORY_URL_DOWNLOAD = REPOSITORY_URL_BASE + '/download-extension/%s.shell-extension.zip';
|
|
|
|
const REPOSITORY_URL_INFO = REPOSITORY_URL_BASE + '/extension-info/';
|
|
|
|
|
2011-08-24 17:08:34 +00:00
|
|
|
const _httpSession = new Soup.SessionAsync();
|
|
|
|
|
|
|
|
// The unfortunate state of gjs, gobject-introspection and libsoup
|
|
|
|
// means that I have to do a hack to add a feature.
|
|
|
|
// See: https://bugzilla.gnome.org/show_bug.cgi?id=655189 for context.
|
|
|
|
|
|
|
|
if (Soup.Session.prototype.add_feature != null)
|
|
|
|
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
|
|
|
|
|
2011-09-12 19:30:02 +00:00
|
|
|
function _getCertFile() {
|
|
|
|
let localCert = GLib.build_filenamev([global.userdatadir, 'extensions.gnome.org.crt']);
|
|
|
|
if (GLib.file_test(localCert, GLib.FileTest.EXISTS))
|
|
|
|
return localCert;
|
|
|
|
else
|
|
|
|
return Config.SHELL_SYSTEM_CA_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_httpSession.ssl_ca_file = _getCertFile();
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
// Maps uuid -> metadata object
|
|
|
|
const extensionMeta = {};
|
|
|
|
// Maps uuid -> importer object (extension directory tree)
|
|
|
|
const extensions = {};
|
2011-06-23 01:56:24 +00:00
|
|
|
// Maps uuid -> extension state object (returned from init())
|
|
|
|
const extensionStateObjs = {};
|
2011-10-14 22:06:03 +00:00
|
|
|
// Contains the order that extensions were enabled in.
|
|
|
|
const extensionOrder = [];
|
2011-10-14 21:58:23 +00:00
|
|
|
|
2011-05-25 19:34:33 +00:00
|
|
|
// Arrays of uuids
|
|
|
|
var enabledExtensions;
|
2009-10-25 22:53:10 +00:00
|
|
|
// GFile for user extensions
|
|
|
|
var userExtensionsDir = null;
|
|
|
|
|
2011-06-11 04:21:35 +00:00
|
|
|
// We don't really have a class to add signals on. So, create
|
|
|
|
// a simple dummy object, add the signal methods, and export those
|
|
|
|
// publically.
|
|
|
|
var _signals = {};
|
|
|
|
Signals.addSignalMethods(_signals);
|
|
|
|
|
|
|
|
const connect = Lang.bind(_signals, _signals.connect);
|
|
|
|
const disconnect = Lang.bind(_signals, _signals.disconnect);
|
|
|
|
|
2011-06-23 01:41:30 +00:00
|
|
|
// UUID => Array of error messages
|
|
|
|
var errors = {};
|
|
|
|
|
2011-08-18 11:56:22 +00:00
|
|
|
const ENABLED_EXTENSIONS_KEY = 'enabled-extensions';
|
|
|
|
|
2011-01-11 21:42:34 +00:00
|
|
|
/**
|
|
|
|
* versionCheck:
|
|
|
|
* @required: an array of versions we're compatible with
|
|
|
|
* @current: the version we have
|
|
|
|
*
|
|
|
|
* Check if a component is compatible for an extension.
|
|
|
|
* @required is an array, and at least one version must match.
|
|
|
|
* @current must be in the format <major>.<minor>.<point>.<micro>
|
|
|
|
* <micro> is always ignored
|
|
|
|
* <point> is ignored if <minor> is even (so you can target the
|
|
|
|
* whole stable release)
|
|
|
|
* <minor> and <major> must match
|
|
|
|
* Each target version must be at least <major> and <minor>
|
|
|
|
*/
|
|
|
|
function versionCheck(required, current) {
|
|
|
|
let currentArray = current.split('.');
|
|
|
|
let major = currentArray[0];
|
|
|
|
let minor = currentArray[1];
|
|
|
|
let point = currentArray[2];
|
|
|
|
for (let i = 0; i < required.length; i++) {
|
|
|
|
let requiredArray = required[i].split('.');
|
|
|
|
if (requiredArray[0] == major &&
|
|
|
|
requiredArray[1] == minor &&
|
|
|
|
(requiredArray[2] == point ||
|
|
|
|
(requiredArray[2] == undefined && parseInt(minor) % 2 == 0)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-12 18:16:03 +00:00
|
|
|
function installExtensionFromUUID(uuid, version_tag) {
|
2011-09-12 18:17:09 +00:00
|
|
|
let params = { uuid: uuid,
|
|
|
|
version_tag: version_tag,
|
2011-09-12 18:16:03 +00:00
|
|
|
shell_version: Config.PACKAGE_VERSION,
|
|
|
|
api_version: API_VERSION.toString() };
|
|
|
|
|
2011-09-12 18:17:09 +00:00
|
|
|
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);
|
2011-07-05 18:40:48 +00:00
|
|
|
|
2011-09-12 18:16:03 +00:00
|
|
|
_httpSession.queue_message(message,
|
2011-08-24 17:08:34 +00:00
|
|
|
function(session, message) {
|
2011-09-12 18:17:09 +00:00
|
|
|
let info = JSON.parse(message.response_body.data);
|
|
|
|
let dialog = new InstallExtensionDialog(uuid, version_tag, info.name);
|
|
|
|
dialog.open(global.get_current_time());
|
2011-08-24 17:08:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:10:50 +00:00
|
|
|
function uninstallExtensionFromUUID(uuid) {
|
|
|
|
let meta = extensionMeta[uuid];
|
|
|
|
if (!meta)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Try to disable it -- if it's ERROR'd, we can't guarantee that,
|
|
|
|
// but it will be removed on next reboot, and hopefully nothing
|
|
|
|
// broke too much.
|
|
|
|
disableExtension(uuid);
|
|
|
|
|
|
|
|
// Don't try to uninstall system extensions
|
|
|
|
if (meta.type != ExtensionType.PER_USER)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
meta.state = ExtensionState.UNINSTALLED;
|
|
|
|
_signals.emit('extension-state-changed', meta);
|
|
|
|
|
|
|
|
delete extensionMeta[uuid];
|
|
|
|
|
|
|
|
// Importers are marked as PERMANENT, so we can't do this.
|
|
|
|
// delete extensions[uuid];
|
|
|
|
extensions[uuid] = undefined;
|
|
|
|
|
|
|
|
delete extensionStateObjs[uuid];
|
|
|
|
delete errors[uuid];
|
|
|
|
|
|
|
|
FileUtils.recursivelyDeleteDir(Gio.file_new_for_path(meta.path));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-24 17:08:34 +00:00
|
|
|
function gotExtensionZipFile(session, message, uuid) {
|
|
|
|
if (message.status_code != Soup.KnownStatusCode.OK) {
|
|
|
|
logExtensionError(uuid, 'downloading extension: ' + message.status_code);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: use a GFile mkstemp-type method once one exists
|
|
|
|
let fd, tmpzip;
|
|
|
|
try {
|
|
|
|
[fd, tmpzip] = GLib.file_open_tmp('XXXXXX.shell-extension.zip');
|
|
|
|
} catch (e) {
|
|
|
|
logExtensionError(uuid, 'tempfile: ' + e.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let stream = new Gio.UnixOutputStream({ fd: fd });
|
|
|
|
let dir = userExtensionsDir.get_child(uuid);
|
|
|
|
Shell.write_soup_message_to_stream(stream, message);
|
|
|
|
stream.close(null);
|
|
|
|
let [success, pid] = GLib.spawn_async(null,
|
|
|
|
['unzip', '-uod', dir.get_path(), '--', tmpzip],
|
|
|
|
null,
|
|
|
|
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
logExtensionError(uuid, 'extract: could not extract');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function(pid, status) {
|
|
|
|
GLib.spawn_close_pid(pid);
|
2011-09-11 02:35:41 +00:00
|
|
|
|
|
|
|
// Add extension to 'enabled-extensions' for the user, always...
|
|
|
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
|
|
|
if (enabledExtensions.indexOf(uuid) == -1) {
|
|
|
|
enabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
}
|
|
|
|
|
2011-08-24 17:08:34 +00:00
|
|
|
loadExtension(dir, true, ExtensionType.PER_USER);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
function disableExtension(uuid) {
|
|
|
|
let meta = extensionMeta[uuid];
|
|
|
|
if (!meta)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (meta.state != ExtensionState.ENABLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let extensionState = extensionStateObjs[uuid];
|
|
|
|
|
2011-10-14 22:06:03 +00:00
|
|
|
// "Rebase" the extension order by disabling and then enabling extensions
|
|
|
|
// in order to help prevent conflicts.
|
|
|
|
|
|
|
|
// Example:
|
|
|
|
// order = [A, B, C, D, E]
|
|
|
|
// user disables C
|
|
|
|
// this should: disable E, disable D, disable C, enable D, enable E
|
|
|
|
|
|
|
|
let orderIdx = extensionOrder.indexOf(uuid);
|
|
|
|
let order = extensionOrder.slice(orderIdx + 1);
|
|
|
|
let orderReversed = order.slice().reverse();
|
|
|
|
|
|
|
|
for (let i = 0; i < orderReversed.length; i++) {
|
|
|
|
let uuid = orderReversed[i];
|
|
|
|
try {
|
|
|
|
extensionStateObjs[uuid].disable();
|
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
try {
|
|
|
|
extensionState.disable();
|
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-14 22:06:03 +00:00
|
|
|
for (let i = 0; i < order.length; i++) {
|
|
|
|
let uuid = order[i];
|
|
|
|
try {
|
|
|
|
extensionStateObjs[uuid].enable();
|
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 18:43:51 +00:00
|
|
|
extensionOrder.splice(orderIdx, 1);
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
meta.state = ExtensionState.DISABLED;
|
2011-06-28 02:21:02 +00:00
|
|
|
_signals.emit('extension-state-changed', meta);
|
2011-06-23 01:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableExtension(uuid) {
|
|
|
|
let meta = extensionMeta[uuid];
|
2011-10-25 18:38:25 +00:00
|
|
|
if (!meta)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (meta.state == ExtensionState.INITIALIZED) {
|
|
|
|
loadExtension(meta.dir, meta.type, true);
|
2011-06-23 01:56:24 +00:00
|
|
|
return;
|
2011-10-14 21:58:23 +00:00
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
|
|
|
if (meta.state != ExtensionState.DISABLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let extensionState = extensionStateObjs[uuid];
|
|
|
|
|
2011-10-14 22:06:03 +00:00
|
|
|
extensionOrder.push(uuid);
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
try {
|
|
|
|
extensionState.enable();
|
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.state = ExtensionState.ENABLED;
|
2011-06-28 02:21:02 +00:00
|
|
|
_signals.emit('extension-state-changed', meta);
|
2011-06-23 01:56:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-05 18:40:48 +00:00
|
|
|
function logExtensionError(uuid, message, state) {
|
2011-06-23 01:41:30 +00:00
|
|
|
if (!errors[uuid]) errors[uuid] = [];
|
|
|
|
errors[uuid].push(message);
|
|
|
|
global.logError('Extension "%s" had error: %s'.format(uuid, message));
|
2011-07-05 18:40:48 +00:00
|
|
|
state = state || ExtensionState.ERROR;
|
2011-06-28 02:21:02 +00:00
|
|
|
_signals.emit('extension-state-changed', { uuid: uuid,
|
|
|
|
error: message,
|
2011-07-05 18:40:48 +00:00
|
|
|
state: state });
|
2011-06-23 01:41:30 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 18:38:25 +00:00
|
|
|
function loadExtension(dir, type, enabled) {
|
2009-10-25 22:53:10 +00:00
|
|
|
let info;
|
2011-06-23 01:41:30 +00:00
|
|
|
let uuid = dir.get_basename();
|
2009-10-25 22:53:10 +00:00
|
|
|
|
|
|
|
let metadataFile = dir.get_child('metadata.json');
|
|
|
|
if (!metadataFile.query_exists(null)) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Missing metadata.json');
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:13:07 +00:00
|
|
|
let metadataContents;
|
|
|
|
try {
|
|
|
|
metadataContents = Shell.get_file_contents_utf8_sync(metadataFile.get_path());
|
|
|
|
} catch (e) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Failed to load metadata.json: ' + e);
|
2011-03-31 20:13:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-25 22:53:10 +00:00
|
|
|
let meta;
|
|
|
|
try {
|
|
|
|
meta = JSON.parse(metadataContents);
|
|
|
|
} catch (e) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Failed to parse metadata.json: ' + e);
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-23 01:41:30 +00:00
|
|
|
|
2011-01-11 21:42:34 +00:00
|
|
|
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
|
|
|
for (let i = 0; i < requiredProperties.length; i++) {
|
2009-10-25 22:53:10 +00:00
|
|
|
let prop = requiredProperties[i];
|
|
|
|
if (!meta[prop]) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'missing "' + prop + '" property in metadata.json');
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 15:41:39 +00:00
|
|
|
|
2011-06-23 01:41:30 +00:00
|
|
|
if (extensions[uuid] != undefined) {
|
2011-09-30 21:30:47 +00:00
|
|
|
logExtensionError(uuid, 'extension already loaded');
|
2010-10-18 15:41:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
// Encourage people to add this
|
|
|
|
if (!meta['url']) {
|
2011-06-23 01:41:30 +00:00
|
|
|
global.log('Warning: Missing "url" property in metadata.json');
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 01:41:30 +00:00
|
|
|
if (uuid != meta.uuid) {
|
|
|
|
logExtensionError(uuid, 'uuid "' + meta.uuid + '" from metadata.json does not match directory name "' + uuid + '"');
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
extensionMeta[uuid] = meta;
|
|
|
|
meta.type = type;
|
2011-10-25 18:38:25 +00:00
|
|
|
meta.dir = dir;
|
2011-06-23 01:56:24 +00:00
|
|
|
meta.path = dir.get_path();
|
2011-06-28 02:21:02 +00:00
|
|
|
meta.error = '';
|
2009-10-25 22:53:10 +00:00
|
|
|
|
|
|
|
// Default to error, we set success as the last step
|
2011-06-23 01:56:24 +00:00
|
|
|
meta.state = ExtensionState.ERROR;
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2011-07-05 18:40:48 +00:00
|
|
|
if (!versionCheck(meta['shell-version'], Config.PACKAGE_VERSION) ||
|
|
|
|
(meta['js-version'] && !versionCheck(meta['js-version'], Config.GJS_VERSION))) {
|
|
|
|
logExtensionError(uuid, 'extension is not compatible with current GNOME Shell and/or GJS version', ExtensionState.OUT_OF_DATE);
|
|
|
|
meta.state = ExtensionState.OUT_OF_DATE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-25 18:38:25 +00:00
|
|
|
if (!enabled) {
|
|
|
|
meta.state = ExtensionState.INITIALIZED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
let extensionJs = dir.get_child('extension.js');
|
|
|
|
if (!extensionJs.query_exists(null)) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Missing extension.js');
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let stylesheetPath = null;
|
|
|
|
let themeContext = St.ThemeContext.get_for_stage(global.stage);
|
|
|
|
let theme = themeContext.get_theme();
|
|
|
|
let stylesheetFile = dir.get_child('stylesheet.css');
|
|
|
|
if (stylesheetFile.query_exists(null)) {
|
|
|
|
try {
|
|
|
|
theme.load_stylesheet(stylesheetFile.get_path());
|
|
|
|
} catch (e) {
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Stylesheet parse error: ' + e);
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let extensionModule;
|
2011-06-23 01:56:24 +00:00
|
|
|
let extensionState = null;
|
2009-10-25 22:53:10 +00:00
|
|
|
try {
|
|
|
|
global.add_extension_importer('imports.ui.extensionSystem.extensions', meta.uuid, dir.get_path());
|
|
|
|
extensionModule = extensions[meta.uuid].extension;
|
|
|
|
} catch (e) {
|
|
|
|
if (stylesheetPath != null)
|
|
|
|
theme.unload_stylesheet(stylesheetPath);
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, e);
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
|
|
|
if (!extensionModule.init) {
|
|
|
|
logExtensionError(uuid, 'missing \'init\' function');
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
try {
|
2011-06-23 01:56:24 +00:00
|
|
|
extensionState = extensionModule.init(meta);
|
2009-10-25 22:53:10 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (stylesheetPath != null)
|
|
|
|
theme.unload_stylesheet(stylesheetPath);
|
2011-06-23 01:41:30 +00:00
|
|
|
logExtensionError(uuid, 'Failed to evaluate init function:' + e);
|
2009-10-25 22:53:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
|
|
|
if (!extensionState)
|
|
|
|
extensionState = extensionModule;
|
|
|
|
extensionStateObjs[uuid] = extensionState;
|
|
|
|
|
|
|
|
if (!extensionState.enable) {
|
|
|
|
logExtensionError(uuid, 'missing \'enable\' function');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!extensionState.disable) {
|
|
|
|
logExtensionError(uuid, 'missing \'disable\' function');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.state = ExtensionState.DISABLED;
|
|
|
|
|
2011-10-14 21:58:23 +00:00
|
|
|
enableExtension(uuid);
|
2011-06-11 04:21:35 +00:00
|
|
|
|
|
|
|
_signals.emit('extension-loaded', meta.uuid);
|
2011-06-28 02:21:02 +00:00
|
|
|
_signals.emit('extension-state-changed', meta);
|
2009-10-25 22:53:10 +00:00
|
|
|
global.log('Loaded extension ' + meta.uuid);
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
function onEnabledExtensionsChanged() {
|
|
|
|
let newEnabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
|
|
|
|
|
|
|
// Find and enable all the newly enabled extensions: UUIDs found in the
|
|
|
|
// new setting, but not in the old one.
|
|
|
|
newEnabledExtensions.filter(function(uuid) {
|
|
|
|
return enabledExtensions.indexOf(uuid) == -1;
|
|
|
|
}).forEach(function(uuid) {
|
|
|
|
enableExtension(uuid);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Find and disable all the newly disabled extensions: UUIDs found in the
|
|
|
|
// old setting, but not in the new one.
|
|
|
|
enabledExtensions.filter(function(item) {
|
|
|
|
return newEnabledExtensions.indexOf(item) == -1;
|
|
|
|
}).forEach(function(uuid) {
|
|
|
|
disableExtension(uuid);
|
|
|
|
});
|
|
|
|
|
|
|
|
enabledExtensions = newEnabledExtensions;
|
|
|
|
}
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
function init() {
|
2010-05-04 11:24:06 +00:00
|
|
|
let userExtensionsPath = GLib.build_filenamev([global.userdatadir, 'extensions']);
|
2009-10-25 22:53:10 +00:00
|
|
|
userExtensionsDir = Gio.file_new_for_path(userExtensionsPath);
|
|
|
|
try {
|
2011-08-26 21:33:52 +00:00
|
|
|
if (!userExtensionsDir.query_exists(null))
|
|
|
|
userExtensionsDir.make_directory_with_parents(null);
|
2009-10-25 22:53:10 +00:00
|
|
|
} catch (e) {
|
2010-05-13 19:46:04 +00:00
|
|
|
global.logError('' + e);
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 01:56:24 +00:00
|
|
|
global.settings.connect('changed::' + ENABLED_EXTENSIONS_KEY, onEnabledExtensionsChanged);
|
2011-08-18 11:56:22 +00:00
|
|
|
enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _loadExtensionsIn(dir, type) {
|
2011-03-02 13:39:07 +00:00
|
|
|
let fileEnum;
|
2009-10-25 22:53:10 +00:00
|
|
|
let file, info;
|
2011-03-02 13:39:07 +00:00
|
|
|
try {
|
|
|
|
fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
} catch (e) {
|
|
|
|
global.logError('' + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-25 22:53:10 +00:00
|
|
|
while ((info = fileEnum.next_file(null)) != null) {
|
|
|
|
let fileType = info.get_file_type();
|
|
|
|
if (fileType != Gio.FileType.DIRECTORY)
|
|
|
|
continue;
|
|
|
|
let name = info.get_name();
|
|
|
|
let child = dir.get_child(name);
|
2011-08-18 11:56:22 +00:00
|
|
|
let enabled = enabledExtensions.indexOf(name) != -1;
|
2011-10-25 18:38:25 +00:00
|
|
|
loadExtension(child, type, enabled);
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
|
|
|
fileEnum.close(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadExtensions() {
|
|
|
|
let systemDataDirs = GLib.get_system_data_dirs();
|
|
|
|
for (let i = 0; i < systemDataDirs.length; i++) {
|
|
|
|
let dirPath = systemDataDirs[i] + '/gnome-shell/extensions';
|
|
|
|
let dir = Gio.file_new_for_path(dirPath);
|
|
|
|
if (dir.query_exists(null))
|
|
|
|
_loadExtensionsIn(dir, ExtensionType.SYSTEM);
|
|
|
|
}
|
2011-10-14 21:57:46 +00:00
|
|
|
_loadExtensionsIn(userExtensionsDir, ExtensionType.PER_USER);
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
2011-09-12 18:17:09 +00:00
|
|
|
|
|
|
|
function InstallExtensionDialog(uuid, version_tag, name) {
|
|
|
|
this._init(uuid, version_tag, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
InstallExtensionDialog.prototype = {
|
|
|
|
__proto__: ModalDialog.ModalDialog.prototype,
|
|
|
|
|
|
|
|
_init: function(uuid, version_tag, name) {
|
|
|
|
ModalDialog.ModalDialog.prototype._init.call(this, { styleClass: 'extension-dialog' });
|
|
|
|
|
|
|
|
this._uuid = uuid;
|
|
|
|
this._version_tag = version_tag;
|
|
|
|
this._name = name;
|
|
|
|
|
|
|
|
this.setButtons([{ label: _("Cancel"),
|
|
|
|
action: Lang.bind(this, this._onCancelButtonPressed),
|
|
|
|
key: Clutter.Escape
|
|
|
|
},
|
|
|
|
{ label: _("Install"),
|
|
|
|
action: Lang.bind(this, this._onInstallButtonPressed)
|
|
|
|
}]);
|
|
|
|
|
|
|
|
let message = _("Download and install '%s' from extensions.gnome.org?").format(name);
|
|
|
|
|
|
|
|
this._descriptionLabel = new St.Label({ text: message });
|
|
|
|
|
|
|
|
this.contentLayout.add(this._descriptionLabel,
|
|
|
|
{ y_fill: true,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCancelButtonPressed: function(button, event) {
|
|
|
|
this.close(global.get_current_time());
|
|
|
|
|
|
|
|
// Even though the extension is already "uninstalled", send through
|
|
|
|
// a state-changed signal for any users who want to know if the install
|
|
|
|
// went through correctly -- using proper async DBus would block more
|
|
|
|
// traditional clients like the plugin
|
|
|
|
let meta = { uuid: this._uuid,
|
|
|
|
state: ExtensionState.UNINSTALLED,
|
|
|
|
error: '' };
|
|
|
|
|
|
|
|
_signals.emit('extension-state-changed', meta);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onInstallButtonPressed: function(button, event) {
|
|
|
|
let meta = { uuid: this._uuid,
|
|
|
|
state: ExtensionState.DOWNLOADING,
|
|
|
|
error: '' };
|
|
|
|
|
|
|
|
extensionMeta[this._uuid] = meta;
|
|
|
|
|
|
|
|
_signals.emit('extension-state-changed', meta);
|
|
|
|
|
|
|
|
let params = { version_tag: this._version_tag,
|
|
|
|
shell_version: Config.PACKAGE_VERSION,
|
|
|
|
api_version: API_VERSION.toString() };
|
|
|
|
|
|
|
|
let url = REPOSITORY_URL_DOWNLOAD.format(this._uuid);
|
|
|
|
let message = Soup.form_request_new_from_hash('GET', url, params);
|
|
|
|
|
|
|
|
_httpSession.queue_message(message,
|
|
|
|
Lang.bind(this, function(session, message) {
|
|
|
|
gotExtensionZipFile(session, message, this._uuid);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.close(global.get_current_time());
|
|
|
|
}
|
|
|
|
};
|