2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported init connect disconnect */
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2020-01-26 17:47:24 -05:00
|
|
|
const { GLib, Gio, GObject, Shell, St } = imports.gi;
|
2011-06-11 00:21:35 -04:00
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2020-01-26 18:59:19 -05:00
|
|
|
const ExtensionDownloader = imports.ui.extensionDownloader;
|
2012-01-18 19:55:20 -05:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2019-07-07 17:38:27 -04:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-09-01 08:42:53 -04:00
|
|
|
const Main = imports.ui.main;
|
2020-01-26 17:47:24 -05:00
|
|
|
const MessageTray = imports.ui.messageTray;
|
2011-09-12 14:16:03 -04:00
|
|
|
|
2019-07-07 17:38:27 -04:00
|
|
|
const { ExtensionState, ExtensionType } = ExtensionUtils;
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2011-08-18 07:56:22 -04:00
|
|
|
const ENABLED_EXTENSIONS_KEY = 'enabled-extensions';
|
2018-01-17 07:43:11 -05:00
|
|
|
const DISABLED_EXTENSIONS_KEY = 'disabled-extensions';
|
2015-12-14 17:52:38 -05:00
|
|
|
const DISABLE_USER_EXTENSIONS_KEY = 'disable-user-extensions';
|
2014-02-18 12:10:22 -05:00
|
|
|
const EXTENSION_DISABLE_VERSION_CHECK_KEY = 'disable-extension-version-validation';
|
2011-08-18 07:56:22 -04:00
|
|
|
|
2020-01-26 18:59:19 -05:00
|
|
|
const UPDATE_CHECK_TIMEOUT = 24 * 60 * 60; // 1 day in seconds
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
var ExtensionManager = class {
|
|
|
|
constructor() {
|
2019-09-11 14:15:04 -04:00
|
|
|
this._initialized = false;
|
2019-03-06 19:45:45 -05:00
|
|
|
this._enabled = false;
|
2020-01-26 17:47:24 -05:00
|
|
|
this._updateNotified = false;
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2019-07-07 18:01:11 -04:00
|
|
|
this._extensions = new Map();
|
2020-05-07 07:54:24 -04:00
|
|
|
this._unloadedExtensions = new Map();
|
2019-03-06 19:45:45 -05:00
|
|
|
this._enabledExtensions = [];
|
|
|
|
this._extensionOrder = [];
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2019-11-25 15:20:02 -05: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 10:10:34 -05:00
|
|
|
log('Failed to create file %s: %s'.format(disableFilename, e.message));
|
2019-11-25 15:20:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 60, () => {
|
2019-11-25 16:54:44 -05:00
|
|
|
disableFile.delete(null);
|
2019-11-25 15:20:02 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
|
2020-01-22 09:09:05 -05:00
|
|
|
this._installExtensionUpdates();
|
2019-03-06 19:45:45 -05:00
|
|
|
this._sessionUpdated();
|
2020-01-26 18:59:19 -05:00
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, UPDATE_CHECK_TIMEOUT, () => {
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
});
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2020-03-11 15:09:11 -04:00
|
|
|
get updatesSupported() {
|
|
|
|
const appSys = Shell.AppSystem.get_default();
|
|
|
|
return appSys.lookup_app('org.gnome.Extensions.desktop') !== null;
|
|
|
|
}
|
|
|
|
|
2019-07-07 18:01:11 -04:00
|
|
|
lookup(uuid) {
|
|
|
|
return this._extensions.get(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
getUuids() {
|
|
|
|
return [...this._extensions.keys()];
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_callExtensionDisable(uuid) {
|
2019-07-07 18:01:11 -04:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2011-10-14 18:06:03 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
if (extension.state != ExtensionState.ENABLED)
|
|
|
|
return;
|
2011-10-14 18:06:03 -04:00
|
|
|
|
2019-03-06 19:45:45 -05: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-19 20:20:08 -04:00
|
|
|
let otherUuid = orderReversed[i];
|
2019-03-06 19:45:45 -05:00
|
|
|
try {
|
2019-08-19 20:20:08 -04:00
|
|
|
this.lookup(otherUuid).stateObj.disable();
|
2019-03-06 19:45:45 -05:00
|
|
|
} catch (e) {
|
2019-08-19 20:20:08 -04:00
|
|
|
this.logExtensionError(otherUuid, e);
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 18:06:03 -04:00
|
|
|
try {
|
2019-03-06 19:45:45 -05:00
|
|
|
extension.stateObj.disable();
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2019-03-06 19:45:45 -05:00
|
|
|
this.logExtensionError(uuid, e);
|
2011-10-14 18:06:03 -04:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:10:56 -04: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-06 19:45:45 -05:00
|
|
|
for (let i = 0; i < order.length; i++) {
|
2019-08-19 20:20:08 -04:00
|
|
|
let otherUuid = order[i];
|
2019-03-06 19:45:45 -05:00
|
|
|
try {
|
2019-08-19 20:20:08 -04:00
|
|
|
this.lookup(otherUuid).stateObj.enable();
|
2019-03-06 19:45:45 -05:00
|
|
|
} catch (e) {
|
2019-08-19 20:20:08 -04:00
|
|
|
this.logExtensionError(otherUuid, e);
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
|
|
|
}
|
2012-06-04 18:42:42 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
this._extensionOrder.splice(orderIdx, 1);
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
if (extension.state != ExtensionState.ERROR) {
|
|
|
|
extension.state = ExtensionState.DISABLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
2011-10-14 18:06:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_callExtensionEnable(uuid) {
|
2019-09-11 14:24:17 -04:00
|
|
|
if (!Main.sessionMode.allowExtensions)
|
|
|
|
return;
|
|
|
|
|
2019-07-07 18:01:11 -04:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
if (extension.state == ExtensionState.INITIALIZED)
|
2019-07-07 20:53:32 -04:00
|
|
|
this._callExtensionInit(uuid);
|
2011-10-25 14:38:25 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
if (extension.state != ExtensionState.DISABLED)
|
|
|
|
return;
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2020-02-14 10:10:34 -05:00
|
|
|
let stylesheetNames = ['%s.css'.format(global.session_mode), 'stylesheet.css'];
|
2019-03-06 19:45:45 -05: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 08:55:04 -04:00
|
|
|
this.logExtensionError(uuid, e);
|
2019-03-06 19:45:45 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-10-14 18:06:03 -04:00
|
|
|
|
2018-08-03 11:46:27 -04:00
|
|
|
try {
|
2019-03-06 19:45:45 -05:00
|
|
|
extension.stateObj.enable();
|
|
|
|
extension.state = ExtensionState.ENABLED;
|
2019-09-09 10:07:32 -04:00
|
|
|
this._extensionOrder.push(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
this.emit('extension-state-changed', extension);
|
2018-08-03 11:46:27 -04:00
|
|
|
} catch (e) {
|
2019-03-06 19:45:45 -05:00
|
|
|
if (extension.stylesheet) {
|
|
|
|
theme.unload_stylesheet(extension.stylesheet);
|
|
|
|
delete extension.stylesheet;
|
|
|
|
}
|
|
|
|
this.logExtensionError(uuid, e);
|
2013-02-05 12:45:21 -05:00
|
|
|
}
|
2012-06-04 18:42:42 -04:00
|
|
|
}
|
|
|
|
|
2018-01-17 07:43:11 -05:00
|
|
|
enableExtension(uuid) {
|
2019-07-07 18:01:11 -04:00
|
|
|
if (!this._extensions.has(uuid))
|
2018-01-17 07:43:11 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2018-01-17 07:43:11 -05: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 07:43:11 -05:00
|
|
|
if (!enabledExtensions.includes(uuid)) {
|
|
|
|
enabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
disableExtension(uuid) {
|
2019-07-07 18:01:11 -04:00
|
|
|
if (!this._extensions.has(uuid))
|
2018-01-17 07:43:11 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
2018-01-17 07:43:11 -05:00
|
|
|
let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY);
|
|
|
|
|
2018-01-17 07:43:11 -05:00
|
|
|
if (enabledExtensions.includes(uuid)) {
|
|
|
|
enabledExtensions = enabledExtensions.filter(item => item !== uuid);
|
|
|
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
}
|
|
|
|
|
2018-01-17 07:43:11 -05:00
|
|
|
if (!disabledExtensions.includes(uuid)) {
|
|
|
|
disabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(DISABLED_EXTENSIONS_KEY, disabledExtensions);
|
|
|
|
}
|
|
|
|
|
2018-01-17 07:43:11 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:04:03 -04: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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-22 08:45:15 -05:00
|
|
|
notifyExtensionUpdate(uuid) {
|
|
|
|
let extension = this.lookup(uuid);
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extension.hasUpdate = true;
|
|
|
|
this.emit('extension-state-changed', extension);
|
2020-01-26 17:47:24 -05: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 08:45:15 -05:00
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
logExtensionError(uuid, error) {
|
2019-07-07 18:01:11 -04:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
if (!extension)
|
|
|
|
return;
|
2012-01-30 20:58:29 -05:00
|
|
|
|
2020-02-14 10:10:34 -05:00
|
|
|
let message = error.toString();
|
2012-06-28 22:00:45 -04:00
|
|
|
|
2019-07-08 06:21:10 -04:00
|
|
|
extension.error = message;
|
2019-03-06 19:45:45 -05:00
|
|
|
extension.state = ExtensionState.ERROR;
|
|
|
|
if (!extension.errors)
|
|
|
|
extension.errors = [];
|
|
|
|
extension.errors.push(message);
|
2012-01-30 20:58:29 -05:00
|
|
|
|
2020-02-14 10:10:34 -05:00
|
|
|
logError(error, 'Extension %s'.format(uuid));
|
2020-05-10 14:21:03 -04:00
|
|
|
this._updateCanChange(extension);
|
2019-07-08 06:21:10 -04:00
|
|
|
this.emit('extension-state-changed', extension);
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
2011-06-22 21:41:30 -04:00
|
|
|
|
2019-07-07 17:38:27 -04:00
|
|
|
createExtensionObject(uuid, dir, type) {
|
|
|
|
let metadataFile = dir.get_child('metadata.json');
|
2019-08-19 20:51:42 -04:00
|
|
|
if (!metadataFile.query_exists(null))
|
2019-07-07 17:38:27 -04:00
|
|
|
throw new Error('Missing metadata.json');
|
|
|
|
|
2019-01-31 09:08:00 -05:00
|
|
|
let metadataContents, success_;
|
2019-07-07 17:38:27 -04:00
|
|
|
try {
|
2019-01-31 09:08:00 -05:00
|
|
|
[success_, metadataContents] = metadataFile.load_contents(null);
|
2019-07-07 17:38:27 -04:00
|
|
|
if (metadataContents instanceof Uint8Array)
|
|
|
|
metadataContents = imports.byteArray.toString(metadataContents);
|
|
|
|
} catch (e) {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new Error('Failed to load metadata.json: %s'.format(e.toString()));
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
let meta;
|
|
|
|
try {
|
|
|
|
meta = JSON.parse(metadataContents);
|
|
|
|
} catch (e) {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new Error('Failed to parse metadata.json: %s'.format(e.toString()));
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
|
|
|
for (let i = 0; i < requiredProperties.length; i++) {
|
|
|
|
let prop = requiredProperties[i];
|
2019-08-19 20:51:42 -04:00
|
|
|
if (!meta[prop])
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new Error('missing "%s" property in metadata.json'.format(prop));
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (uuid != meta.uuid)
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new Error('uuid "%s" from metadata.json does not match directory name "%s"'.format(meta.uuid, uuid));
|
2019-07-07 17:38:27 -04: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 08:45:15 -05:00
|
|
|
hasUpdate: false,
|
2019-08-20 17:43:54 -04:00
|
|
|
canChange: false,
|
2019-07-07 17:38:27 -04:00
|
|
|
};
|
2019-07-07 18:01:11 -04:00
|
|
|
this._extensions.set(uuid, extension);
|
2019-07-07 17:38:27 -04:00
|
|
|
|
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
2020-05-07 07:54:24 -04: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-06 19:45:45 -05:00
|
|
|
loadExtension(extension) {
|
|
|
|
// Default to error, we set success as the last step
|
|
|
|
extension.state = ExtensionState.ERROR;
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
let checkVersion = !global.settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY);
|
2014-02-18 12:10:22 -05:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
if (checkVersion && ExtensionUtils.isOutOfDate(extension)) {
|
|
|
|
extension.state = ExtensionState.OUT_OF_DATE;
|
2020-05-07 07:54:24 -04: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 14:21:03 -05:00
|
|
|
} else {
|
2019-03-06 19:45:45 -05:00
|
|
|
let enabled = this._enabledExtensions.includes(extension.uuid);
|
|
|
|
if (enabled) {
|
2019-07-07 20:53:32 -04:00
|
|
|
if (!this._callExtensionInit(extension.uuid))
|
2019-03-06 19:45:45 -05:00
|
|
|
return;
|
|
|
|
if (extension.state == ExtensionState.DISABLED)
|
2019-07-07 20:53:32 -04:00
|
|
|
this._callExtensionEnable(extension.uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
} else {
|
|
|
|
extension.state = ExtensionState.INITIALIZED;
|
|
|
|
}
|
2020-05-07 07:54:24 -04:00
|
|
|
|
|
|
|
this._unloadedExtensions.delete(extension.uuid);
|
2012-11-26 14:21:03 -05:00
|
|
|
}
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2018-12-04 03:31:27 -05:00
|
|
|
this._updateCanChange(extension);
|
2019-03-06 19:45:45 -05:00
|
|
|
this.emit('extension-state-changed', extension);
|
2011-10-25 14:38:25 -04:00
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
unloadExtension(extension) {
|
2020-05-07 07:54:24 -04:00
|
|
|
const { uuid, type } = extension;
|
|
|
|
|
2019-03-06 19:45:45 -05: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 07:54:24 -04:00
|
|
|
this._callExtensionDisable(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
|
|
|
|
extension.state = ExtensionState.UNINSTALLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
|
2020-05-07 07:54:24 -04: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-06 19:45:45 -05:00
|
|
|
return true;
|
2017-05-17 17:51:49 -04:00
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
reloadExtension(oldExtension) {
|
|
|
|
// Grab the things we'll need to pass to createExtensionObject
|
|
|
|
// to reload it.
|
2019-09-12 11:19:51 -04:00
|
|
|
let { uuid, dir, type } = oldExtension;
|
2012-08-23 21:37:50 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
// Then unload the old extension.
|
|
|
|
this.unloadExtension(oldExtension);
|
2012-02-08 12:48:05 -05:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
// Now, recreate the extension and load it.
|
|
|
|
let newExtension;
|
|
|
|
try {
|
2019-07-07 17:38:27 -04:00
|
|
|
newExtension = this.createExtensionObject(uuid, dir, type);
|
2019-03-06 19:45:45 -05:00
|
|
|
} catch (e) {
|
|
|
|
this.logExtensionError(uuid, e);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-08 12:48:05 -05:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
this.loadExtension(newExtension);
|
2017-05-17 18:03:28 -04:00
|
|
|
}
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_callExtensionInit(uuid) {
|
2019-09-11 14:24:17 -04:00
|
|
|
if (!Main.sessionMode.allowExtensions)
|
2019-09-12 06:40:46 -04:00
|
|
|
return false;
|
2019-09-11 14:24:17 -04:00
|
|
|
|
2019-07-07 18:01:11 -04:00
|
|
|
let extension = this.lookup(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
if (!extension)
|
2019-09-11 08:23:44 -04:00
|
|
|
throw new Error("Extension was not properly created. Call createExtensionObject first");
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2019-09-11 08:36:18 -04:00
|
|
|
let dir = extension.dir;
|
2019-03-06 19:45:45 -05: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-22 21:56:24 -04:00
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
ExtensionUtils.installImporter(extension);
|
2013-10-25 09:28:11 -04:00
|
|
|
try {
|
2019-03-06 19:45:45 -05:00
|
|
|
extensionModule = extension.imports.extension;
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2019-03-06 19:45:45 -05:00
|
|
|
this.logExtensionError(uuid, e);
|
2013-10-25 09:28:11 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-06 19:45:45 -05: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 18:53:10 -04:00
|
|
|
}
|
2011-06-22 21:56:24 -04:00
|
|
|
|
2018-12-04 03:31:27 -05:00
|
|
|
_getModeExtensions() {
|
2019-03-06 19:45:45 -05:00
|
|
|
if (Array.isArray(Main.sessionMode.enabledExtensions))
|
2018-12-04 03:31:27 -05: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 07:43:11 -05:00
|
|
|
let changeKey = isMode
|
|
|
|
? DISABLE_USER_EXTENSIONS_KEY
|
|
|
|
: ENABLED_EXTENSIONS_KEY;
|
|
|
|
|
2018-12-04 03:31:27 -05:00
|
|
|
extension.canChange =
|
|
|
|
!hasError &&
|
2018-01-17 07:43:11 -05:00
|
|
|
global.settings.is_writable(changeKey) &&
|
2018-12-04 03:31:27 -05:00
|
|
|
(isMode || !modeOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getEnabledExtensions() {
|
|
|
|
let extensions = this._getModeExtensions();
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2018-01-17 07:43:11 -05:00
|
|
|
if (!global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY))
|
|
|
|
extensions = extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY));
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2018-01-17 07:43:11 -05: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 12:10:22 -05:00
|
|
|
}
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2018-12-04 03:31:27 -05:00
|
|
|
_onUserExtensionsEnabledChanged() {
|
|
|
|
this._onEnabledExtensionsChanged();
|
|
|
|
this._onSettingsWritableChanged();
|
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05: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.
|
2020-04-03 19:52:29 -04:00
|
|
|
newEnabledExtensions
|
|
|
|
.filter(uuid => !this._enabledExtensions.includes(uuid))
|
|
|
|
.forEach(uuid => this._callExtensionEnable(uuid));
|
2019-03-06 19:45:45 -05:00
|
|
|
|
|
|
|
// Find and disable all the newly disabled extensions: UUIDs found in the
|
|
|
|
// old setting, but not in the new one.
|
2020-04-03 19:52:29 -04:00
|
|
|
this._extensionOrder
|
|
|
|
.filter(uuid => !newEnabledExtensions.includes(uuid))
|
|
|
|
.reverse().forEach(uuid => this._callExtensionDisable(uuid));
|
2019-03-06 19:45:45 -05:00
|
|
|
|
|
|
|
this._enabledExtensions = newEnabledExtensions;
|
|
|
|
}
|
|
|
|
|
2018-12-04 03:31:27 -05:00
|
|
|
_onSettingsWritableChanged() {
|
2019-07-07 18:01:11 -04:00
|
|
|
for (let extension of this._extensions.values()) {
|
2018-12-04 03:31:27 -05:00
|
|
|
this._updateCanChange(extension);
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
_onVersionValidationChanged() {
|
2018-11-19 06:26:16 -05:00
|
|
|
// Disabling extensions modifies the order array, so use a copy
|
|
|
|
let extensionOrder = this._extensionOrder.slice();
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2018-11-19 06:26:16 -05: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 14:24:17 -04:00
|
|
|
});
|
2018-11-19 06:26:16 -05: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 08:42:53 -04:00
|
|
|
}
|
|
|
|
|
2020-01-22 09:09:05 -05:00
|
|
|
_installExtensionUpdates() {
|
2020-03-11 15:09:11 -04:00
|
|
|
if (!this.updatesSupported)
|
|
|
|
return;
|
|
|
|
|
2020-01-22 09:09:05 -05: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 11:45:22 -04: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 09:09:05 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
_loadExtensions() {
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('changed::%s'.format(ENABLED_EXTENSIONS_KEY),
|
2019-03-06 19:45:45 -05:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('changed::%s'.format(DISABLED_EXTENSIONS_KEY),
|
2018-01-17 07:43:11 -05:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('changed::%s'.format(DISABLE_USER_EXTENSIONS_KEY),
|
2018-12-04 03:31:27 -05:00
|
|
|
this._onUserExtensionsEnabledChanged.bind(this));
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('changed::%s'.format(EXTENSION_DISABLE_VERSION_CHECK_KEY),
|
2019-03-06 19:45:45 -05:00
|
|
|
this._onVersionValidationChanged.bind(this));
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('writable-changed::%s'.format(ENABLED_EXTENSIONS_KEY),
|
2018-12-04 03:31:27 -05:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2020-02-14 10:10:34 -05:00
|
|
|
global.settings.connect('writable-changed::%s'.format(DISABLED_EXTENSIONS_KEY),
|
2018-01-17 07:43:11 -05:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2019-03-06 19:45:45 -05:00
|
|
|
|
|
|
|
this._enabledExtensions = this._getEnabledExtensions();
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2019-07-07 17:38:27 -04: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 18:01:11 -04:00
|
|
|
let existing = this.lookup(uuid);
|
2019-07-07 17:38:27 -04:00
|
|
|
if (existing) {
|
2020-02-14 10:10:34 -05:00
|
|
|
log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, dir.get_path()));
|
2019-07-07 17:38:27 -04: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 10:10:34 -05:00
|
|
|
logError(e, 'Could not load extension %s'.format(uuid));
|
2019-07-07 17:38:27 -04:00
|
|
|
return;
|
|
|
|
}
|
2019-03-06 19:45:45 -05:00
|
|
|
this.loadExtension(extension);
|
2012-09-01 08:42:53 -04:00
|
|
|
});
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_enableAllExtensions() {
|
2019-03-06 19:45:45 -05:00
|
|
|
if (this._enabled)
|
|
|
|
return;
|
|
|
|
|
2019-09-11 14:15:04 -04:00
|
|
|
if (!this._initialized) {
|
2019-03-06 19:45:45 -05:00
|
|
|
this._loadExtensions();
|
2019-09-11 14:15:04 -04:00
|
|
|
this._initialized = true;
|
2019-03-06 19:45:45 -05:00
|
|
|
} else {
|
|
|
|
this._enabledExtensions.forEach(uuid => {
|
2019-07-07 20:53:32 -04:00
|
|
|
this._callExtensionEnable(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this._enabled = true;
|
2012-09-01 08:42:53 -04:00
|
|
|
}
|
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_disableAllExtensions() {
|
2019-03-06 19:45:45 -05:00
|
|
|
if (!this._enabled)
|
|
|
|
return;
|
|
|
|
|
2019-09-11 14:15:04 -04:00
|
|
|
if (this._initialized) {
|
2019-03-06 19:45:45 -05:00
|
|
|
this._extensionOrder.slice().reverse().forEach(uuid => {
|
2019-07-07 20:53:32 -04:00
|
|
|
this._callExtensionDisable(uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this._enabled = false;
|
2012-11-29 10:09:21 -05:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2019-03-06 19:45:45 -05: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 14:18:20 -04:00
|
|
|
// Take care of added or removed sessionMode extensions
|
|
|
|
this._onEnabledExtensionsChanged();
|
2019-07-07 20:53:32 -04:00
|
|
|
this._enableAllExtensions();
|
2019-03-06 19:45:45 -05:00
|
|
|
} else {
|
2019-07-07 20:53:32 -04:00
|
|
|
this._disableAllExtensions();
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(ExtensionManager.prototype);
|
2020-01-26 17:47:24 -05: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();
|
|
|
|
}
|
|
|
|
});
|