2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2011-06-11 00:21:35 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2011-09-12 14:17:09 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-10-25 18:53:10 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const St = imports.gi.St;
|
2011-04-04 21:20:44 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2011-08-24 13:08:34 -04:00
|
|
|
const Soup = imports.gi.Soup;
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2011-01-11 16:42:34 -05:00
|
|
|
const Config = imports.misc.config;
|
2012-01-18 19:55:20 -05:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2011-09-10 17:10:50 -04:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2011-09-12 14:17:09 -04:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2011-01-11 16:42:34 -05:00
|
|
|
|
2011-09-12 14:16:03 -04:00
|
|
|
const API_VERSION = 1;
|
|
|
|
|
2009-10-25 18:53:10 -04:00
|
|
|
const ExtensionState = {
|
|
|
|
ENABLED: 1,
|
|
|
|
DISABLED: 2,
|
|
|
|
ERROR: 3,
|
2011-06-22 21:56:24 -04:00
|
|
|
OUT_OF_DATE: 4,
|
2011-06-27 22:27:56 -04:00
|
|
|
DOWNLOADING: 5,
|
2011-10-25 14:38:25 -04:00
|
|
|
INITIALIZED: 6,
|
2011-06-22 21:56:24 -04:00
|
|
|
|
|
|
|
// Used as an error state for operations on unknown extensions,
|
|
|
|
// should never be in a real extensionMeta object.
|
|
|
|
UNINSTALLED: 99
|
2009-10-25 18:53:10 -04:00
|
|
|
};
|
|
|
|
|
2011-09-12 14:16:03 -04: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 13:08:34 -04: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 15:30:02 -04: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();
|
|
|
|
|
2011-05-25 15:34:33 -04:00
|
|
|
// Arrays of uuids
|
|
|
|
var enabledExtensions;
|
2012-01-30 20:58:29 -05:00
|
|
|
// Contains the order that extensions were enabled in.
|
|
|
|
const extensionOrder = [];
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2011-06-11 00:21:35 -04: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-08-18 07:56:22 -04:00
|
|
|
const ENABLED_EXTENSIONS_KEY = 'enabled-extensions';
|
|
|
|
|
2011-09-12 14:16:03 -04:00
|
|
|
function installExtensionFromUUID(uuid, version_tag) {
|
2011-09-12 14:17:09 -04:00
|
|
|
let params = { uuid: uuid,
|
|
|
|
version_tag: version_tag,
|
2011-09-12 14:16:03 -04:00
|
|
|
shell_version: Config.PACKAGE_VERSION,
|
|
|
|
api_version: API_VERSION.toString() };
|
|
|
|
|
2011-09-12 14:17:09 -04:00
|
|
|
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);
|
2011-07-05 14:40:48 -04:00
|
|
|
|
2011-09-12 14:16:03 -04:00
|
|
|
_httpSession.queue_message(message,
|
2011-08-24 13:08:34 -04:00
|
|
|
function(session, message) {
|
2011-09-12 14:17:09 -04: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 13:08:34 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-10 17:10:50 -04:00
|
|
|
function uninstallExtensionFromUUID(uuid) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
2011-09-10 17:10:50 -04:00
|
|
|
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
|
2012-01-30 20:58:29 -05:00
|
|
|
if (extension.type != ExtensionUtils.ExtensionType.PER_USER)
|
2011-09-10 17:10:50 -04:00
|
|
|
return false;
|
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.UNINSTALLED;
|
|
|
|
_signals.emit('extension-state-changed', extension);
|
2011-09-10 17:10:50 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
delete ExtensionUtils.extensions[uuid];
|
2011-09-10 17:10:50 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
FileUtils.recursivelyDeleteDir(Gio.file_new_for_path(extension.path));
|
2011-09-10 17:10:50 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:08:34 -04: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 });
|
2012-01-18 19:55:20 -05:00
|
|
|
let dir = ExtensionUtils.userExtensionsDir.get_child(uuid);
|
2011-08-24 13:08:34 -04:00
|
|
|
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-10 22:35:41 -04: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);
|
|
|
|
}
|
|
|
|
|
2012-01-18 19:55:20 -05:00
|
|
|
loadExtension(dir, ExtensionUtils.ExtensionType.PER_USER, true);
|
2011-08-24 13:08:34 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-22 21:56:24 -04:00
|
|
|
function disableExtension(uuid) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
2011-06-22 21:56:24 -04:00
|
|
|
return;
|
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
if (extension.state != ExtensionState.ENABLED)
|
2011-06-22 21:56:24 -04:00
|
|
|
return;
|
|
|
|
|
2011-10-14 18:06:03 -04: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 {
|
2012-02-08 12:48:05 -05:00
|
|
|
ExtensionUtils.extensions[uuid].stateObj.disable();
|
2011-10-14 18:06:03 -04:00
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 21:56:24 -04:00
|
|
|
try {
|
2012-02-08 12:48:05 -05:00
|
|
|
extension.stateObj.disable();
|
2011-06-22 21:56:24 -04:00
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-14 18:06:03 -04:00
|
|
|
for (let i = 0; i < order.length; i++) {
|
|
|
|
let uuid = order[i];
|
|
|
|
try {
|
2012-02-08 12:48:05 -05:00
|
|
|
ExtensionUtils.extensions[uuid].stateObj.enable();
|
2011-10-14 18:06:03 -04:00
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 14:43:51 -04:00
|
|
|
extensionOrder.splice(orderIdx, 1);
|
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.DISABLED;
|
|
|
|
_signals.emit('extension-state-changed', extension);
|
2011-06-22 21:56:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableExtension(uuid) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
2011-10-25 14:38:25 -04:00
|
|
|
return;
|
|
|
|
|
2012-02-08 12:48:05 -05:00
|
|
|
if (extension.state == ExtensionState.INITIALIZED)
|
|
|
|
initExtension(uuid);
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
if (extension.state != ExtensionState.DISABLED)
|
2011-06-22 21:56:24 -04:00
|
|
|
return;
|
|
|
|
|
2011-10-14 18:06:03 -04:00
|
|
|
extensionOrder.push(uuid);
|
|
|
|
|
2011-06-22 21:56:24 -04:00
|
|
|
try {
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.stateObj.enable();
|
2011-06-22 21:56:24 -04:00
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.ENABLED;
|
|
|
|
_signals.emit('extension-state-changed', extension);
|
2011-06-22 21:56:24 -04:00
|
|
|
}
|
|
|
|
|
2011-07-05 14:40:48 -04:00
|
|
|
function logExtensionError(uuid, message, state) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!extension.errors)
|
|
|
|
extension.errors = [];
|
|
|
|
|
|
|
|
extension.errors.push(message);
|
2011-06-22 21:41:30 -04:00
|
|
|
global.logError('Extension "%s" had error: %s'.format(uuid, message));
|
2011-07-05 14:40:48 -04:00
|
|
|
state = state || ExtensionState.ERROR;
|
2011-06-27 22:21:02 -04:00
|
|
|
_signals.emit('extension-state-changed', { uuid: uuid,
|
|
|
|
error: message,
|
2011-07-05 14:40:48 -04:00
|
|
|
state: state });
|
2011-06-22 21:41:30 -04:00
|
|
|
}
|
|
|
|
|
2011-10-25 14:38:25 -04:00
|
|
|
function loadExtension(dir, type, enabled) {
|
2011-06-22 21:41:30 -04:00
|
|
|
let uuid = dir.get_basename();
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension;
|
2010-10-18 11:41:39 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
if (ExtensionUtils.extensions[uuid] != undefined) {
|
2012-04-06 14:03:51 -04:00
|
|
|
global.logError('Extension "%s" is already loaded'.format(uuid));
|
|
|
|
return;
|
2009-10-25 18:53:10 -04:00
|
|
|
}
|
|
|
|
|
2012-01-18 19:55:20 -05:00
|
|
|
try {
|
2012-01-30 20:58:29 -05:00
|
|
|
extension = ExtensionUtils.createExtensionObject(uuid, dir, type);
|
2012-01-18 19:55:20 -05:00
|
|
|
} catch(e) {
|
|
|
|
logExtensionError(uuid, e.message);
|
2009-10-25 18:53:10 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to error, we set success as the last step
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.ERROR;
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
if (ExtensionUtils.isOutOfDate(extension)) {
|
2011-07-05 14:40:48 -04:00
|
|
|
logExtensionError(uuid, 'extension is not compatible with current GNOME Shell and/or GJS version', ExtensionState.OUT_OF_DATE);
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.OUT_OF_DATE;
|
2011-07-05 14:40:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-08 12:48:05 -05:00
|
|
|
if (enabled) {
|
|
|
|
initExtension(uuid);
|
|
|
|
if (extension.state == ExtensionState.DISABLED)
|
|
|
|
enableExtension(uuid);
|
|
|
|
} else {
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.INITIALIZED;
|
2011-10-25 14:38:25 -04:00
|
|
|
}
|
|
|
|
|
2012-02-08 12:48:05 -05:00
|
|
|
_signals.emit('extension-state-changed', extension);
|
|
|
|
global.log('Loaded extension ' + uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
function initExtension(uuid) {
|
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
let dir = extension.dir;
|
|
|
|
|
|
|
|
if (!extension)
|
|
|
|
throw new Error("Extension was not properly created. Call loadExtension first");
|
|
|
|
|
2009-10-25 18:53:10 -04:00
|
|
|
let extensionJs = dir.get_child('extension.js');
|
|
|
|
if (!extensionJs.query_exists(null)) {
|
2011-06-22 21:41:30 -04:00
|
|
|
logExtensionError(uuid, 'Missing extension.js');
|
2009-10-25 18:53:10 -04: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-22 21:41:30 -04:00
|
|
|
logExtensionError(uuid, 'Stylesheet parse error: ' + e);
|
2009-10-25 18:53:10 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let extensionModule;
|
2011-06-22 21:56:24 -04:00
|
|
|
let extensionState = null;
|
2009-10-25 18:53:10 -04:00
|
|
|
try {
|
2012-01-30 20:58:29 -05:00
|
|
|
ExtensionUtils.installImporter(extension);
|
|
|
|
extensionModule = extension.imports.extension;
|
2009-10-25 18:53:10 -04:00
|
|
|
} catch (e) {
|
|
|
|
if (stylesheetPath != null)
|
|
|
|
theme.unload_stylesheet(stylesheetPath);
|
2012-01-18 19:44:30 -05:00
|
|
|
logExtensionError(uuid, '' + e);
|
2009-10-25 18:53:10 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-06-22 21:56:24 -04:00
|
|
|
|
|
|
|
if (!extensionModule.init) {
|
|
|
|
logExtensionError(uuid, 'missing \'init\' function');
|
2009-10-25 18:53:10 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2009-10-25 18:53:10 -04:00
|
|
|
try {
|
2012-01-30 20:58:29 -05:00
|
|
|
extensionState = extensionModule.init(extension);
|
2009-10-25 18:53:10 -04:00
|
|
|
} catch (e) {
|
|
|
|
if (stylesheetPath != null)
|
|
|
|
theme.unload_stylesheet(stylesheetPath);
|
2011-06-22 21:41:30 -04:00
|
|
|
logExtensionError(uuid, 'Failed to evaluate init function:' + e);
|
2009-10-25 18:53:10 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-06-22 21:56:24 -04:00
|
|
|
|
|
|
|
if (!extensionState)
|
|
|
|
extensionState = extensionModule;
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.stateObj = extensionState;
|
2011-06-22 21:56:24 -04:00
|
|
|
|
|
|
|
if (!extensionState.enable) {
|
|
|
|
logExtensionError(uuid, 'missing \'enable\' function');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!extensionState.disable) {
|
|
|
|
logExtensionError(uuid, 'missing \'disable\' function');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
extension.state = ExtensionState.DISABLED;
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2012-01-30 20:58:29 -05:00
|
|
|
_signals.emit('extension-loaded', uuid);
|
2009-10-25 18:53:10 -04:00
|
|
|
}
|
|
|
|
|
2011-06-22 21:56:24 -04: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 18:53:10 -04:00
|
|
|
function init() {
|
2012-01-18 19:55:20 -05:00
|
|
|
ExtensionUtils.init();
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2011-06-22 21:56:24 -04:00
|
|
|
global.settings.connect('changed::' + ENABLED_EXTENSIONS_KEY, onEnabledExtensionsChanged);
|
2011-08-18 07:56:22 -04:00
|
|
|
enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2009-10-25 18:53:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadExtensions() {
|
2012-01-18 19:55:20 -05:00
|
|
|
ExtensionUtils.scanExtensions(function(uuid, dir, type) {
|
|
|
|
let enabled = enabledExtensions.indexOf(uuid) != -1;
|
|
|
|
loadExtension(dir, type, enabled);
|
|
|
|
});
|
2009-10-25 18:53:10 -04:00
|
|
|
}
|
2011-09-12 14:17:09 -04:00
|
|
|
|
2011-11-20 10:32:59 -05:00
|
|
|
const InstallExtensionDialog = new Lang.Class({
|
|
|
|
Name: 'InstallExtensionDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
2011-09-12 14:17:09 -04:00
|
|
|
|
|
|
|
_init: function(uuid, version_tag, name) {
|
2011-11-20 10:32:59 -05:00
|
|
|
this.parent({ styleClass: 'extension-dialog' });
|
2011-09-12 14:17:09 -04:00
|
|
|
|
|
|
|
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) {
|
2012-03-01 09:53:48 -05:00
|
|
|
let state = { uuid: this._uuid,
|
|
|
|
state: ExtensionState.DOWNLOADING,
|
|
|
|
error: '' };
|
2011-09-12 14:17:09 -04:00
|
|
|
|
2012-03-01 09:53:48 -05:00
|
|
|
_signals.emit('extension-state-changed', state);
|
2011-09-12 14:17:09 -04:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2011-11-20 10:32:59 -05:00
|
|
|
});
|