2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported init connect disconnect */
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2020-01-26 22:47:24 +00:00
|
|
|
const { GLib, Gio, GObject, Shell, St } = imports.gi;
|
2011-06-11 04:21:35 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2020-01-26 23:59:19 +00:00
|
|
|
const ExtensionDownloader = imports.ui.extensionDownloader;
|
2012-01-19 00:55:20 +00:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2019-07-07 21:38:27 +00:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-09-01 12:42:53 +00:00
|
|
|
const Main = imports.ui.main;
|
2020-01-26 22:47:24 +00:00
|
|
|
const MessageTray = imports.ui.messageTray;
|
2011-09-12 18:16:03 +00:00
|
|
|
|
2019-07-07 21:38:27 +00:00
|
|
|
const { ExtensionState, ExtensionType } = ExtensionUtils;
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2011-08-18 11:56:22 +00:00
|
|
|
const ENABLED_EXTENSIONS_KEY = 'enabled-extensions';
|
2018-01-17 12:43:11 +00:00
|
|
|
const DISABLED_EXTENSIONS_KEY = 'disabled-extensions';
|
2015-12-14 22:52:38 +00:00
|
|
|
const DISABLE_USER_EXTENSIONS_KEY = 'disable-user-extensions';
|
2014-02-18 17:10:22 +00:00
|
|
|
const EXTENSION_DISABLE_VERSION_CHECK_KEY = 'disable-extension-version-validation';
|
2011-08-18 11:56:22 +00:00
|
|
|
|
2020-01-26 23:59:19 +00:00
|
|
|
const UPDATE_CHECK_TIMEOUT = 24 * 60 * 60; // 1 day in seconds
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
var ExtensionManager = class {
|
|
|
|
constructor() {
|
2019-09-11 18:15:04 +00:00
|
|
|
this._initialized = false;
|
2019-03-07 00:45:45 +00:00
|
|
|
this._enabled = false;
|
2020-01-26 22:47:24 +00:00
|
|
|
this._updateNotified = false;
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2019-07-07 22:01:11 +00:00
|
|
|
this._extensions = new Map();
|
2020-05-07 11:54:24 +00:00
|
|
|
this._unloadedExtensions = new Map();
|
2019-03-07 00:45:45 +00:00
|
|
|
this._enabledExtensions = [];
|
|
|
|
this._extensionOrder = [];
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2019-11-25 20:20:02 +00:00
|
|
|
// The following file should exist for a period of time when extensions
|
|
|
|
// are enabled after start. If it exists, then the systemd unit will
|
|
|
|
// disable extensions should gnome-shell crash.
|
|
|
|
// Should the file already exist from a previous login, then this is OK.
|
|
|
|
let disableFilename = GLib.build_filenamev([GLib.get_user_runtime_dir(), 'gnome-shell-disable-extensions']);
|
|
|
|
let disableFile = Gio.File.new_for_path(disableFilename);
|
|
|
|
try {
|
|
|
|
disableFile.create(Gio.FileCreateFlags.REPLACE_DESTINATION, null);
|
|
|
|
} catch (e) {
|
2020-02-14 15:10:34 +00:00
|
|
|
log('Failed to create file %s: %s'.format(disableFilename, e.message));
|
2019-11-25 20:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 60, () => {
|
2019-11-25 21:54:44 +00:00
|
|
|
disableFile.delete(null);
|
2019-11-25 20:20:02 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
|
2020-01-22 14:09:05 +00:00
|
|
|
this._installExtensionUpdates();
|
2019-03-07 00:45:45 +00:00
|
|
|
this._sessionUpdated();
|
2020-01-26 23:59:19 +00:00
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, UPDATE_CHECK_TIMEOUT, () => {
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
});
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2020-03-11 19:09:11 +00:00
|
|
|
get updatesSupported() {
|
|
|
|
const appSys = Shell.AppSystem.get_default();
|
|
|
|
return appSys.lookup_app('org.gnome.Extensions.desktop') !== null;
|
|
|
|
}
|
|
|
|
|
2019-07-07 22:01:11 +00:00
|
|
|
lookup(uuid) {
|
|
|
|
return this._extensions.get(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
getUuids() {
|
|
|
|
return [...this._extensions.keys()];
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 00:53:32 +00:00
|
|
|
_callExtensionDisable(uuid) {
|
2019-07-07 22:01:11 +00:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2011-10-14 22:06:03 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
if (extension.state != ExtensionState.ENABLED)
|
|
|
|
return;
|
2011-10-14 22:06:03 +00:00
|
|
|
|
2019-03-07 00:45:45 +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 = this._extensionOrder.indexOf(uuid);
|
|
|
|
let order = this._extensionOrder.slice(orderIdx + 1);
|
|
|
|
let orderReversed = order.slice().reverse();
|
|
|
|
|
|
|
|
for (let i = 0; i < orderReversed.length; i++) {
|
2019-08-20 00:20:08 +00:00
|
|
|
let otherUuid = orderReversed[i];
|
2019-03-07 00:45:45 +00:00
|
|
|
try {
|
2019-08-20 00:20:08 +00:00
|
|
|
this.lookup(otherUuid).stateObj.disable();
|
2019-03-07 00:45:45 +00:00
|
|
|
} catch (e) {
|
2019-08-20 00:20:08 +00:00
|
|
|
this.logExtensionError(otherUuid, e);
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 22:06:03 +00:00
|
|
|
try {
|
2019-03-07 00:45:45 +00:00
|
|
|
extension.stateObj.disable();
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2019-03-07 00:45:45 +00:00
|
|
|
this.logExtensionError(uuid, e);
|
2011-10-14 22:06:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 18:10:56 +00:00
|
|
|
if (extension.stylesheet) {
|
|
|
|
let theme = St.ThemeContext.get_for_stage(global.stage).get_theme();
|
|
|
|
theme.unload_stylesheet(extension.stylesheet);
|
|
|
|
delete extension.stylesheet;
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
for (let i = 0; i < order.length; i++) {
|
2019-08-20 00:20:08 +00:00
|
|
|
let otherUuid = order[i];
|
2019-03-07 00:45:45 +00:00
|
|
|
try {
|
2019-08-20 00:20:08 +00:00
|
|
|
this.lookup(otherUuid).stateObj.enable();
|
2019-03-07 00:45:45 +00:00
|
|
|
} catch (e) {
|
2019-08-20 00:20:08 +00:00
|
|
|
this.logExtensionError(otherUuid, e);
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-04 22:42:42 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
this._extensionOrder.splice(orderIdx, 1);
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
if (extension.state != ExtensionState.ERROR) {
|
|
|
|
extension.state = ExtensionState.DISABLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
2011-10-14 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 00:53:32 +00:00
|
|
|
_callExtensionEnable(uuid) {
|
2019-09-11 18:24:17 +00:00
|
|
|
if (!Main.sessionMode.allowExtensions)
|
|
|
|
return;
|
|
|
|
|
2019-07-07 22:01:11 +00:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
if (extension.state == ExtensionState.INITIALIZED)
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionInit(uuid);
|
2011-10-25 18:38:25 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
if (extension.state != ExtensionState.DISABLED)
|
|
|
|
return;
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2020-02-14 15:10:34 +00:00
|
|
|
let stylesheetNames = ['%s.css'.format(global.session_mode), 'stylesheet.css'];
|
2019-03-07 00:45:45 +00:00
|
|
|
let theme = St.ThemeContext.get_for_stage(global.stage).get_theme();
|
|
|
|
for (let i = 0; i < stylesheetNames.length; i++) {
|
|
|
|
try {
|
|
|
|
let stylesheetFile = extension.dir.get_child(stylesheetNames[i]);
|
|
|
|
theme.load_stylesheet(stylesheetFile);
|
|
|
|
extension.stylesheet = stylesheetFile;
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND))
|
|
|
|
continue; // not an error
|
2019-09-11 12:55:04 +00:00
|
|
|
this.logExtensionError(uuid, e);
|
2019-03-07 00:45:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-10-14 22:06:03 +00:00
|
|
|
|
2018-08-03 15:46:27 +00:00
|
|
|
try {
|
2019-03-07 00:45:45 +00:00
|
|
|
extension.stateObj.enable();
|
|
|
|
extension.state = ExtensionState.ENABLED;
|
2019-09-09 14:07:32 +00:00
|
|
|
this._extensionOrder.push(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
this.emit('extension-state-changed', extension);
|
2018-08-03 15:46:27 +00:00
|
|
|
} catch (e) {
|
2019-03-07 00:45:45 +00:00
|
|
|
if (extension.stylesheet) {
|
|
|
|
theme.unload_stylesheet(extension.stylesheet);
|
|
|
|
delete extension.stylesheet;
|
|
|
|
}
|
|
|
|
this.logExtensionError(uuid, e);
|
2013-02-05 17:45:21 +00:00
|
|
|
}
|
2012-06-04 22:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
enableExtension(uuid) {
|
2019-07-07 22:01:11 +00:00
|
|
|
if (!this._extensions.has(uuid))
|
2018-01-17 12:43:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2018-01-17 12:43:11 +00:00
|
|
|
let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY);
|
|
|
|
|
|
|
|
if (disabledExtensions.includes(uuid)) {
|
|
|
|
disabledExtensions = disabledExtensions.filter(item => item !== uuid);
|
|
|
|
global.settings.set_strv(DISABLED_EXTENSIONS_KEY, disabledExtensions);
|
|
|
|
}
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
if (!enabledExtensions.includes(uuid)) {
|
|
|
|
enabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
disableExtension(uuid) {
|
2019-07-07 22:01:11 +00:00
|
|
|
if (!this._extensions.has(uuid))
|
2018-01-17 12:43:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2018-01-17 12:43:11 +00:00
|
|
|
let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY);
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
if (enabledExtensions.includes(uuid)) {
|
|
|
|
enabledExtensions = enabledExtensions.filter(item => item !== uuid);
|
|
|
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
}
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
if (!disabledExtensions.includes(uuid)) {
|
|
|
|
disabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(DISABLED_EXTENSIONS_KEY, disabledExtensions);
|
|
|
|
}
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-01 19:04:03 +00:00
|
|
|
openExtensionPrefs(uuid, parentWindow, options) {
|
|
|
|
const extension = this.lookup(uuid);
|
|
|
|
if (!extension || !extension.hasPrefs)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Gio.DBus.session.call(
|
|
|
|
'org.gnome.Shell.Extensions',
|
|
|
|
'/org/gnome/Shell/Extensions',
|
|
|
|
'org.gnome.Shell.Extensions',
|
|
|
|
'OpenExtensionPrefs',
|
|
|
|
new GLib.Variant('(ssa{sv})', [uuid, parentWindow, options]),
|
|
|
|
null,
|
|
|
|
Gio.DBusCallFlags.NONE,
|
|
|
|
-1,
|
|
|
|
null,
|
|
|
|
(conn, res) => conn.call_finish(res));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:45:15 +00:00
|
|
|
notifyExtensionUpdate(uuid) {
|
|
|
|
let extension = this.lookup(uuid);
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extension.hasUpdate = true;
|
|
|
|
this.emit('extension-state-changed', extension);
|
2020-01-26 22:47:24 +00:00
|
|
|
|
|
|
|
if (!this._updateNotified) {
|
|
|
|
this._updateNotified = true;
|
|
|
|
|
|
|
|
let source = new ExtensionUpdateSource();
|
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
|
|
|
let notification = new MessageTray.Notification(source,
|
|
|
|
_('Extension Updates Available'),
|
|
|
|
_('Extension updates are ready to be installed.'));
|
|
|
|
source.showNotification(notification);
|
|
|
|
}
|
2020-01-22 13:45:15 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
logExtensionError(uuid, error) {
|
2019-07-07 22:01:11 +00:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2012-01-31 01:58:29 +00:00
|
|
|
|
2020-02-14 15:10:34 +00:00
|
|
|
let message = error.toString();
|
2012-06-29 02:00:45 +00:00
|
|
|
|
2019-07-08 10:21:10 +00:00
|
|
|
extension.error = message;
|
2019-03-07 00:45:45 +00:00
|
|
|
extension.state = ExtensionState.ERROR;
|
|
|
|
if (!extension.errors)
|
|
|
|
extension.errors = [];
|
|
|
|
extension.errors.push(message);
|
2012-01-31 01:58:29 +00:00
|
|
|
|
2020-02-14 15:10:34 +00:00
|
|
|
logError(error, 'Extension %s'.format(uuid));
|
2020-05-10 18:21:03 +00:00
|
|
|
this._updateCanChange(extension);
|
2019-07-08 10:21:10 +00:00
|
|
|
this.emit('extension-state-changed', extension);
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
2011-06-23 01:41:30 +00:00
|
|
|
|
2019-07-07 21:38:27 +00:00
|
|
|
createExtensionObject(uuid, dir, type) {
|
|
|
|
let metadataFile = dir.get_child('metadata.json');
|
2019-08-20 00:51:42 +00:00
|
|
|
if (!metadataFile.query_exists(null))
|
2019-07-07 21:38:27 +00:00
|
|
|
throw new Error('Missing metadata.json');
|
|
|
|
|
2019-01-31 14:08:00 +00:00
|
|
|
let metadataContents, success_;
|
2019-07-07 21:38:27 +00:00
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
[success_, metadataContents] = metadataFile.load_contents(null);
|
2019-07-07 21:38:27 +00:00
|
|
|
if (metadataContents instanceof Uint8Array)
|
|
|
|
metadataContents = imports.byteArray.toString(metadataContents);
|
|
|
|
} catch (e) {
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new Error('Failed to load metadata.json: %s'.format(e.toString()));
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
let meta;
|
|
|
|
try {
|
|
|
|
meta = JSON.parse(metadataContents);
|
|
|
|
} catch (e) {
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new Error('Failed to parse metadata.json: %s'.format(e.toString()));
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
|
|
|
for (let i = 0; i < requiredProperties.length; i++) {
|
|
|
|
let prop = requiredProperties[i];
|
2019-08-20 00:51:42 +00:00
|
|
|
if (!meta[prop])
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new Error('missing "%s" property in metadata.json'.format(prop));
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (uuid != meta.uuid)
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new Error('uuid "%s" from metadata.json does not match directory name "%s"'.format(meta.uuid, uuid));
|
2019-07-07 21:38:27 +00:00
|
|
|
|
|
|
|
let extension = {
|
|
|
|
metadata: meta,
|
|
|
|
uuid: meta.uuid,
|
|
|
|
type,
|
|
|
|
dir,
|
|
|
|
path: dir.get_path(),
|
|
|
|
error: '',
|
|
|
|
hasPrefs: dir.get_child('prefs.js').query_exists(null),
|
2020-01-22 13:45:15 +00:00
|
|
|
hasUpdate: false,
|
2019-08-20 21:43:54 +00:00
|
|
|
canChange: false,
|
2019-07-07 21:38:27 +00:00
|
|
|
};
|
2019-07-07 22:01:11 +00:00
|
|
|
this._extensions.set(uuid, extension);
|
2019-07-07 21:38:27 +00:00
|
|
|
|
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:54:24 +00:00
|
|
|
_canLoad(extension) {
|
|
|
|
if (!this._unloadedExtensions.has(extension.uuid))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const version = this._unloadedExtensions.get(extension.uuid);
|
|
|
|
return extension.metadata.version === version;
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
loadExtension(extension) {
|
|
|
|
// Default to error, we set success as the last step
|
|
|
|
extension.state = ExtensionState.ERROR;
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
let checkVersion = !global.settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY);
|
2014-02-18 17:10:22 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
if (checkVersion && ExtensionUtils.isOutOfDate(extension)) {
|
|
|
|
extension.state = ExtensionState.OUT_OF_DATE;
|
2020-05-07 11:54:24 +00:00
|
|
|
} else if (!this._canLoad(extension)) {
|
|
|
|
this.logExtensionError(extension.uuid, new Error(
|
|
|
|
'A different version was loaded previously. You need to log out for changes to take effect.'));
|
2012-11-26 19:21:03 +00:00
|
|
|
} else {
|
2019-03-07 00:45:45 +00:00
|
|
|
let enabled = this._enabledExtensions.includes(extension.uuid);
|
|
|
|
if (enabled) {
|
2019-07-08 00:53:32 +00:00
|
|
|
if (!this._callExtensionInit(extension.uuid))
|
2019-03-07 00:45:45 +00:00
|
|
|
return;
|
|
|
|
if (extension.state == ExtensionState.DISABLED)
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionEnable(extension.uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
} else {
|
|
|
|
extension.state = ExtensionState.INITIALIZED;
|
|
|
|
}
|
2020-05-07 11:54:24 +00:00
|
|
|
|
|
|
|
this._unloadedExtensions.delete(extension.uuid);
|
2012-11-26 19:21:03 +00:00
|
|
|
}
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2018-12-04 08:31:27 +00:00
|
|
|
this._updateCanChange(extension);
|
2019-03-07 00:45:45 +00:00
|
|
|
this.emit('extension-state-changed', extension);
|
2011-10-25 18:38:25 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
unloadExtension(extension) {
|
2020-05-07 11:54:24 +00:00
|
|
|
const { uuid, type } = extension;
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
// 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.
|
2020-05-07 11:54:24 +00:00
|
|
|
this._callExtensionDisable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
|
|
|
|
extension.state = ExtensionState.UNINSTALLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
|
2020-05-07 11:54:24 +00:00
|
|
|
// If we did install an importer, it is now cached and it's
|
|
|
|
// impossible to load a different version
|
|
|
|
if (type === ExtensionType.PER_USER && extension.imports)
|
|
|
|
this._unloadedExtensions.set(uuid, extension.metadata.version);
|
|
|
|
|
|
|
|
this._extensions.delete(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
return true;
|
2017-05-17 21:51:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
reloadExtension(oldExtension) {
|
|
|
|
// Grab the things we'll need to pass to createExtensionObject
|
|
|
|
// to reload it.
|
2019-09-12 15:19:51 +00:00
|
|
|
let { uuid, dir, type } = oldExtension;
|
2012-08-24 01:37:50 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
// Then unload the old extension.
|
|
|
|
this.unloadExtension(oldExtension);
|
2012-02-08 17:48:05 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
// Now, recreate the extension and load it.
|
|
|
|
let newExtension;
|
|
|
|
try {
|
2019-07-07 21:38:27 +00:00
|
|
|
newExtension = this.createExtensionObject(uuid, dir, type);
|
2019-03-07 00:45:45 +00:00
|
|
|
} catch (e) {
|
|
|
|
this.logExtensionError(uuid, e);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-08 17:48:05 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
this.loadExtension(newExtension);
|
2017-05-17 22:03:28 +00:00
|
|
|
}
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2019-07-08 00:53:32 +00:00
|
|
|
_callExtensionInit(uuid) {
|
2019-09-11 18:24:17 +00:00
|
|
|
if (!Main.sessionMode.allowExtensions)
|
2019-09-12 10:40:46 +00:00
|
|
|
return false;
|
2019-09-11 18:24:17 +00:00
|
|
|
|
2019-07-07 22:01:11 +00:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
if (!extension)
|
2019-09-11 12:23:44 +00:00
|
|
|
throw new Error("Extension was not properly created. Call createExtensionObject first");
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2019-09-11 12:36:18 +00:00
|
|
|
let dir = extension.dir;
|
2019-03-07 00:45:45 +00:00
|
|
|
let extensionJs = dir.get_child('extension.js');
|
|
|
|
if (!extensionJs.query_exists(null)) {
|
|
|
|
this.logExtensionError(uuid, new Error('Missing extension.js'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let extensionModule;
|
|
|
|
let extensionState = null;
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
ExtensionUtils.installImporter(extension);
|
2013-10-25 13:28:11 +00:00
|
|
|
try {
|
2019-03-07 00:45:45 +00:00
|
|
|
extensionModule = extension.imports.extension;
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2019-03-07 00:45:45 +00:00
|
|
|
this.logExtensionError(uuid, e);
|
2013-10-25 13:28:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-07 00:45:45 +00:00
|
|
|
|
|
|
|
if (extensionModule.init) {
|
|
|
|
try {
|
|
|
|
extensionState = extensionModule.init(extension);
|
|
|
|
} catch (e) {
|
|
|
|
this.logExtensionError(uuid, e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extensionState)
|
|
|
|
extensionState = extensionModule;
|
|
|
|
extension.stateObj = extensionState;
|
|
|
|
|
|
|
|
extension.state = ExtensionState.DISABLED;
|
|
|
|
this.emit('extension-loaded', uuid);
|
|
|
|
return true;
|
2009-10-25 22:53:10 +00:00
|
|
|
}
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2018-12-04 08:31:27 +00:00
|
|
|
_getModeExtensions() {
|
2019-03-07 00:45:45 +00:00
|
|
|
if (Array.isArray(Main.sessionMode.enabledExtensions))
|
2018-12-04 08:31:27 +00:00
|
|
|
return Main.sessionMode.enabledExtensions;
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateCanChange(extension) {
|
|
|
|
let hasError =
|
|
|
|
extension.state == ExtensionState.ERROR ||
|
|
|
|
extension.state == ExtensionState.OUT_OF_DATE;
|
|
|
|
|
|
|
|
let isMode = this._getModeExtensions().includes(extension.uuid);
|
|
|
|
let modeOnly = global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY);
|
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
let changeKey = isMode
|
|
|
|
? DISABLE_USER_EXTENSIONS_KEY
|
|
|
|
: ENABLED_EXTENSIONS_KEY;
|
|
|
|
|
2018-12-04 08:31:27 +00:00
|
|
|
extension.canChange =
|
|
|
|
!hasError &&
|
2018-01-17 12:43:11 +00:00
|
|
|
global.settings.is_writable(changeKey) &&
|
2018-12-04 08:31:27 +00:00
|
|
|
(isMode || !modeOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getEnabledExtensions() {
|
|
|
|
let extensions = this._getModeExtensions();
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
if (!global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY))
|
|
|
|
extensions = extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY));
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2018-01-17 12:43:11 +00:00
|
|
|
// filter out 'disabled-extensions' which takes precedence
|
|
|
|
let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY);
|
|
|
|
return extensions.filter(item => !disabledExtensions.includes(item));
|
2014-02-18 17:10:22 +00:00
|
|
|
}
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2018-12-04 08:31:27 +00:00
|
|
|
_onUserExtensionsEnabledChanged() {
|
|
|
|
this._onEnabledExtensionsChanged();
|
|
|
|
this._onSettingsWritableChanged();
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
_onEnabledExtensionsChanged() {
|
|
|
|
let newEnabledExtensions = this._getEnabledExtensions();
|
|
|
|
|
|
|
|
// Find and enable all the newly enabled extensions: UUIDs found in the
|
|
|
|
// new setting, but not in the old one.
|
|
|
|
newEnabledExtensions.filter(
|
|
|
|
uuid => !this._enabledExtensions.includes(uuid)
|
|
|
|
).forEach(uuid => {
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionEnable(uuid);
|
2012-09-01 12:42:53 +00:00
|
|
|
});
|
2019-03-07 00:45:45 +00:00
|
|
|
|
|
|
|
// Find and disable all the newly disabled extensions: UUIDs found in the
|
|
|
|
// old setting, but not in the new one.
|
2018-11-19 11:26:16 +00:00
|
|
|
this._extensionOrder.filter(
|
|
|
|
uuid => !newEnabledExtensions.includes(uuid)
|
|
|
|
).reverse().forEach(uuid => {
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionDisable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this._enabledExtensions = newEnabledExtensions;
|
|
|
|
}
|
|
|
|
|
2018-12-04 08:31:27 +00:00
|
|
|
_onSettingsWritableChanged() {
|
2019-07-07 22:01:11 +00:00
|
|
|
for (let extension of this._extensions.values()) {
|
2018-12-04 08:31:27 +00:00
|
|
|
this._updateCanChange(extension);
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
_onVersionValidationChanged() {
|
2018-11-19 11:26:16 +00:00
|
|
|
// Disabling extensions modifies the order array, so use a copy
|
|
|
|
let extensionOrder = this._extensionOrder.slice();
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2018-11-19 11:26:16 +00:00
|
|
|
// Disable enabled extensions in the reverse order first to avoid
|
|
|
|
// the "rebasing" done in _callExtensionDisable...
|
|
|
|
extensionOrder.slice().reverse().forEach(uuid => {
|
|
|
|
this._callExtensionDisable(uuid);
|
2019-09-11 18:24:17 +00:00
|
|
|
});
|
2018-11-19 11:26:16 +00:00
|
|
|
|
|
|
|
// ...and then reload and enable extensions in the correct order again.
|
|
|
|
[...this._extensions.values()].sort((a, b) => {
|
|
|
|
return extensionOrder.indexOf(a.uuid) - extensionOrder.indexOf(b.uuid);
|
|
|
|
}).forEach(extension => this.reloadExtension(extension));
|
2012-09-01 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:09:05 +00:00
|
|
|
_installExtensionUpdates() {
|
2020-03-11 19:09:11 +00:00
|
|
|
if (!this.updatesSupported)
|
|
|
|
return;
|
|
|
|
|
2020-01-22 14:09:05 +00:00
|
|
|
FileUtils.collectFromDatadirs('extension-updates', true, (dir, info) => {
|
|
|
|
let fileType = info.get_file_type();
|
|
|
|
if (fileType !== Gio.FileType.DIRECTORY)
|
|
|
|
return;
|
|
|
|
let uuid = info.get_name();
|
|
|
|
let extensionDir = Gio.File.new_for_path(
|
|
|
|
GLib.build_filenamev([global.userdatadir, 'extensions', uuid]));
|
|
|
|
|
2020-03-09 15:45:22 +00:00
|
|
|
try {
|
|
|
|
FileUtils.recursivelyDeleteDir(extensionDir, false);
|
|
|
|
FileUtils.recursivelyMoveDir(dir, extensionDir);
|
|
|
|
} catch (e) {
|
|
|
|
log('Failed to install extension updates for %s'.format(uuid));
|
|
|
|
} finally {
|
|
|
|
FileUtils.recursivelyDeleteDir(dir, true);
|
|
|
|
}
|
2020-01-22 14:09:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
_loadExtensions() {
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('changed::%s'.format(ENABLED_EXTENSIONS_KEY),
|
2019-03-07 00:45:45 +00:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('changed::%s'.format(DISABLED_EXTENSIONS_KEY),
|
2018-01-17 12:43:11 +00:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('changed::%s'.format(DISABLE_USER_EXTENSIONS_KEY),
|
2018-12-04 08:31:27 +00:00
|
|
|
this._onUserExtensionsEnabledChanged.bind(this));
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('changed::%s'.format(EXTENSION_DISABLE_VERSION_CHECK_KEY),
|
2019-03-07 00:45:45 +00:00
|
|
|
this._onVersionValidationChanged.bind(this));
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('writable-changed::%s'.format(ENABLED_EXTENSIONS_KEY),
|
2018-12-04 08:31:27 +00:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2020-02-14 15:10:34 +00:00
|
|
|
global.settings.connect('writable-changed::%s'.format(DISABLED_EXTENSIONS_KEY),
|
2018-01-17 12:43:11 +00:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2019-03-07 00:45:45 +00:00
|
|
|
|
|
|
|
this._enabledExtensions = this._getEnabledExtensions();
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2019-07-07 21:38:27 +00:00
|
|
|
let perUserDir = Gio.File.new_for_path(global.userdatadir);
|
|
|
|
FileUtils.collectFromDatadirs('extensions', true, (dir, info) => {
|
|
|
|
let fileType = info.get_file_type();
|
|
|
|
if (fileType != Gio.FileType.DIRECTORY)
|
|
|
|
return;
|
|
|
|
let uuid = info.get_name();
|
2019-07-07 22:01:11 +00:00
|
|
|
let existing = this.lookup(uuid);
|
2019-07-07 21:38:27 +00:00
|
|
|
if (existing) {
|
2020-02-14 15:10:34 +00:00
|
|
|
log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, dir.get_path()));
|
2019-07-07 21:38:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let extension;
|
|
|
|
let type = dir.has_prefix(perUserDir)
|
|
|
|
? ExtensionType.PER_USER
|
|
|
|
: ExtensionType.SYSTEM;
|
|
|
|
try {
|
|
|
|
extension = this.createExtensionObject(uuid, dir, type);
|
|
|
|
} catch (e) {
|
2020-02-14 15:10:34 +00:00
|
|
|
logError(e, 'Could not load extension %s'.format(uuid));
|
2019-07-07 21:38:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-03-07 00:45:45 +00:00
|
|
|
this.loadExtension(extension);
|
2012-09-01 12:42:53 +00:00
|
|
|
});
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 00:53:32 +00:00
|
|
|
_enableAllExtensions() {
|
2019-03-07 00:45:45 +00:00
|
|
|
if (this._enabled)
|
|
|
|
return;
|
|
|
|
|
2019-09-11 18:15:04 +00:00
|
|
|
if (!this._initialized) {
|
2019-03-07 00:45:45 +00:00
|
|
|
this._loadExtensions();
|
2019-09-11 18:15:04 +00:00
|
|
|
this._initialized = true;
|
2019-03-07 00:45:45 +00:00
|
|
|
} else {
|
|
|
|
this._enabledExtensions.forEach(uuid => {
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionEnable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this._enabled = true;
|
2012-09-01 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 00:53:32 +00:00
|
|
|
_disableAllExtensions() {
|
2019-03-07 00:45:45 +00:00
|
|
|
if (!this._enabled)
|
|
|
|
return;
|
|
|
|
|
2019-09-11 18:15:04 +00:00
|
|
|
if (this._initialized) {
|
2019-03-07 00:45:45 +00:00
|
|
|
this._extensionOrder.slice().reverse().forEach(uuid => {
|
2019-07-08 00:53:32 +00:00
|
|
|
this._callExtensionDisable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this._enabled = false;
|
2012-11-29 15:09:21 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
_sessionUpdated() {
|
|
|
|
// For now sessionMode.allowExtensions controls extensions from both the
|
|
|
|
// 'enabled-extensions' preference and the sessionMode.enabledExtensions
|
|
|
|
// property; it might make sense to make enabledExtensions independent
|
|
|
|
// from allowExtensions in the future
|
|
|
|
if (Main.sessionMode.allowExtensions) {
|
2019-09-11 18:18:20 +00:00
|
|
|
// Take care of added or removed sessionMode extensions
|
|
|
|
this._onEnabledExtensionsChanged();
|
2019-07-08 00:53:32 +00:00
|
|
|
this._enableAllExtensions();
|
2019-03-07 00:45:45 +00:00
|
|
|
} else {
|
2019-07-08 00:53:32 +00:00
|
|
|
this._disableAllExtensions();
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(ExtensionManager.prototype);
|
2020-01-26 22:47:24 +00:00
|
|
|
|
|
|
|
const ExtensionUpdateSource = GObject.registerClass(
|
|
|
|
class ExtensionUpdateSource extends MessageTray.Source {
|
|
|
|
_init() {
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
this._app = appSys.lookup_app('org.gnome.Extensions.desktop');
|
|
|
|
|
|
|
|
super._init(this._app.get_name());
|
|
|
|
}
|
|
|
|
|
|
|
|
getIcon() {
|
|
|
|
return this._app.app_info.get_icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
_createPolicy() {
|
|
|
|
return new MessageTray.NotificationApplicationPolicy(this._app.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this._app.activate();
|
|
|
|
Main.overview.hide();
|
|
|
|
Main.panel.closeCalendar();
|
|
|
|
}
|
|
|
|
});
|