2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2022-07-04 18:30:44 -04:00
|
|
|
/* exported init connect disconnect ExtensionManager */
|
2009-10-25 18:53:10 -04:00
|
|
|
|
2020-01-26 17:47:24 -05:00
|
|
|
const { GLib, Gio, GObject, Shell, St } = imports.gi;
|
2022-07-04 18:30:44 -04:00
|
|
|
const Signals = imports.misc.signals;
|
2011-06-11 00:21:35 -04:00
|
|
|
|
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
|
|
|
|
|
2022-07-04 18:30:44 -04:00
|
|
|
var ExtensionManager = class extends Signals.EventEmitter {
|
2019-03-06 19:45:45 -05:00
|
|
|
constructor() {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2019-09-11 14:15:04 -04:00
|
|
|
this._initialized = 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 = [];
|
2021-11-19 14:15:37 -05:00
|
|
|
this._checkVersion = false;
|
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) {
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`Failed to create file ${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();
|
2022-07-01 07:24:08 -04:00
|
|
|
return (appSys.lookup_app('org.gnome.Extensions.desktop') !== null) ||
|
|
|
|
(appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop') !== null);
|
2020-03-11 15:09:11 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-28 13:54:39 -04:00
|
|
|
_extensionSupportsSessionMode(uuid) {
|
2021-08-10 15:31:00 -04:00
|
|
|
const extension = this.lookup(uuid);
|
2021-08-28 13:54:39 -04:00
|
|
|
|
|
|
|
if (!extension)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (extension.sessionModes.includes(Main.sessionMode.currentMode))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (extension.sessionModes.includes(Main.sessionMode.parentMode))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-09-28 15:31:11 -04:00
|
|
|
if (!this._extensionSupportsSessionMode(uuid))
|
2019-09-11 14:24:17 -04:00
|
|
|
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
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
let stylesheetNames = [`${global.session_mode}.css`, '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.'));
|
2021-01-26 11:12:04 -05:00
|
|
|
notification.connect('activated',
|
|
|
|
() => source.open());
|
2020-01-26 17:47:24 -05:00
|
|
|
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-05-11 19:12:50 -04:00
|
|
|
const message = error instanceof Error
|
|
|
|
? error.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
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
logError(error, `Extension ${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);
|
2021-08-12 10:38:57 -04:00
|
|
|
metadataContents = new TextDecoder().decode(metadataContents);
|
2019-07-07 17:38:27 -04:00
|
|
|
} catch (e) {
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new Error(`Failed to load metadata.json: ${e}`);
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
let meta;
|
|
|
|
try {
|
|
|
|
meta = JSON.parse(metadataContents);
|
|
|
|
} catch (e) {
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new Error(`Failed to parse metadata.json: ${e}`);
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
2022-04-20 13:29:19 -04:00
|
|
|
const requiredProperties = [{
|
|
|
|
prop: 'uuid',
|
|
|
|
typeName: 'string',
|
|
|
|
}, {
|
|
|
|
prop: 'name',
|
|
|
|
typeName: 'string',
|
|
|
|
}, {
|
|
|
|
prop: 'description',
|
|
|
|
typeName: 'string',
|
|
|
|
}, {
|
|
|
|
prop: 'shell-version',
|
|
|
|
typeName: 'string array',
|
|
|
|
typeCheck: v => Array.isArray(v) && v.length > 0 && v.every(e => typeof e === 'string'),
|
|
|
|
}];
|
2019-07-07 17:38:27 -04:00
|
|
|
for (let i = 0; i < requiredProperties.length; i++) {
|
2022-04-20 13:29:19 -04:00
|
|
|
const {
|
|
|
|
prop, typeName, typeCheck = v => typeof v === typeName,
|
|
|
|
} = requiredProperties[i];
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (!meta[prop])
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new Error(`missing "${prop}" property in metadata.json`);
|
2022-04-20 13:29:19 -04:00
|
|
|
if (!typeCheck(meta[prop]))
|
|
|
|
throw new Error(`property "${prop}" is not of type ${typeName}`);
|
2019-07-07 17:38:27 -04:00
|
|
|
}
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (uuid != meta.uuid)
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new Error(`uuid "${meta.uuid}" from metadata.json does not match directory name "${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,
|
2021-08-28 13:54:39 -04:00
|
|
|
sessionModes: meta['session-modes'] ? meta['session-modes'] : ['user'],
|
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
|
|
|
|
2021-11-19 14:15:37 -05:00
|
|
|
if (this._checkVersion && ExtensionUtils.isOutOfDate(extension)) {
|
2019-03-06 19:45:45 -05:00
|
|
|
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 {
|
2022-07-14 09:37:42 -04:00
|
|
|
let enabled = this._enabledExtensions.includes(extension.uuid) &&
|
|
|
|
this._extensionSupportsSessionMode(extension.uuid);
|
2019-03-06 19:45:45 -05:00
|
|
|
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) {
|
2021-09-28 15:31:11 -04:00
|
|
|
if (!this._extensionSupportsSessionMode(uuid))
|
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
|
2021-08-28 13:54:39 -04:00
|
|
|
.filter(uuid => !this._enabledExtensions.includes(uuid) &&
|
|
|
|
this._extensionSupportsSessionMode(uuid))
|
2020-04-03 19:52:29 -04:00
|
|
|
.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
|
2021-08-28 13:54:39 -04:00
|
|
|
.filter(uuid => !newEnabledExtensions.includes(uuid) ||
|
|
|
|
!this._extensionSupportsSessionMode(uuid))
|
2020-04-03 19:52:29 -04:00
|
|
|
.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() {
|
2021-11-19 14:15:37 -05:00
|
|
|
const checkVersion = !global.settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY);
|
|
|
|
if (checkVersion === this._checkVersion)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._checkVersion = checkVersion;
|
|
|
|
|
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) {
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`Failed to install extension updates for ${uuid}`);
|
2020-03-09 11:45:22 -04:00
|
|
|
} finally {
|
|
|
|
FileUtils.recursivelyDeleteDir(dir, true);
|
|
|
|
}
|
2020-01-22 09:09:05 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-06 19:45:45 -05:00
|
|
|
_loadExtensions() {
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`changed::${ENABLED_EXTENSIONS_KEY}`,
|
2019-03-06 19:45:45 -05:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`changed::${DISABLED_EXTENSIONS_KEY}`,
|
2018-01-17 07:43:11 -05:00
|
|
|
this._onEnabledExtensionsChanged.bind(this));
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`changed::${DISABLE_USER_EXTENSIONS_KEY}`,
|
2018-12-04 03:31:27 -05:00
|
|
|
this._onUserExtensionsEnabledChanged.bind(this));
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`changed::${EXTENSION_DISABLE_VERSION_CHECK_KEY}`,
|
2019-03-06 19:45:45 -05:00
|
|
|
this._onVersionValidationChanged.bind(this));
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`writable-changed::${ENABLED_EXTENSIONS_KEY}`,
|
2018-12-04 03:31:27 -05:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`writable-changed::${DISABLED_EXTENSIONS_KEY}`,
|
2018-01-17 07:43:11 -05:00
|
|
|
this._onSettingsWritableChanged.bind(this));
|
2019-03-06 19:45:45 -05:00
|
|
|
|
2021-11-19 14:15:37 -05:00
|
|
|
this._onVersionValidationChanged();
|
|
|
|
|
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) {
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`Extension ${uuid} already installed in ${existing.path}. ${dir.get_path()} will not be loaded`);
|
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) {
|
2022-02-07 09:14:06 -05:00
|
|
|
logError(e, `Could not load extension ${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-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
|
|
|
});
|
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
}
|
|
|
|
|
2019-07-07 20:53:32 -04:00
|
|
|
_disableAllExtensions() {
|
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
|
|
|
});
|
|
|
|
}
|
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() {
|
2021-09-28 15:31:11 -04:00
|
|
|
// Take care of added or removed sessionMode extensions
|
|
|
|
this._onEnabledExtensionsChanged();
|
|
|
|
this._enableAllExtensions();
|
2019-03-06 19:45:45 -05:00
|
|
|
}
|
|
|
|
};
|
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');
|
2022-07-01 07:24:08 -04:00
|
|
|
if (!this._app)
|
|
|
|
this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop');
|
2020-01-26 17:47:24 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|