2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2022-07-04 22:30:44 +00:00
|
|
|
/* exported init connect disconnect ExtensionManager */
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2023-06-08 04:52:46 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2022-07-04 22:30:44 +00:00
|
|
|
const Signals = imports.misc.signals;
|
2011-06-11 04:21:35 +00:00
|
|
|
|
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
|
|
|
|
|
2022-07-04 22:30:44 +00:00
|
|
|
var ExtensionManager = class extends Signals.EventEmitter {
|
2019-03-07 00:45:45 +00:00
|
|
|
constructor() {
|
2022-07-04 22:30:44 +00:00
|
|
|
super();
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
this._initializationPromise = null;
|
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 = [];
|
2021-11-19 19:15:37 +00:00
|
|
|
this._checkVersion = false;
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2023-03-21 21:53:05 +00:00
|
|
|
St.Settings.get().connect('notify::color-scheme',
|
|
|
|
() => this._reloadExtensionStylesheets());
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
Main.sessionMode.connect('updated', () => {
|
|
|
|
this._sessionUpdated();
|
|
|
|
});
|
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) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Failed to create file ${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();
|
2022-11-24 19:55:18 +00:00
|
|
|
this._sessionUpdated().then(() => {
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
|
|
|
});
|
2020-01-26 23:59:19 +00:00
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, UPDATE_CHECK_TIMEOUT, () => {
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
2022-11-24 19:55:18 +00:00
|
|
|
|
2020-01-26 23:59:19 +00:00
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
});
|
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();
|
2022-07-01 11:24:08 +00:00
|
|
|
return (appSys.lookup_app('org.gnome.Extensions.desktop') !== null) ||
|
|
|
|
(appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop') !== null);
|
2020-03-11 19:09:11 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-21 21:53:05 +00:00
|
|
|
_reloadExtensionStylesheets() {
|
|
|
|
for (const ext of this._extensions.values()) {
|
|
|
|
// No stylesheet, nothing to reload
|
|
|
|
if (!ext.stylesheet)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// No variants, so skip reloading
|
|
|
|
const path = ext.stylesheet.get_path();
|
|
|
|
if (!path.endsWith('-dark.css') && !path.endsWith('-light.css'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this._unloadExtensionStylesheet(ext);
|
|
|
|
this._loadExtensionStylesheet(ext);
|
|
|
|
} catch (e) {
|
|
|
|
this._callExtensionDisable(ext.uuid);
|
|
|
|
this.logExtensionError(ext.uuid, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadExtensionStylesheet(extension) {
|
|
|
|
if (extension.state !== ExtensionState.ENABLED &&
|
|
|
|
extension.state !== ExtensionState.ENABLING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const variant = Main.getStyleVariant();
|
|
|
|
const stylesheetNames = [
|
|
|
|
`${global.sessionMode}-${variant}.css`,
|
|
|
|
`stylesheet-${variant}.css`,
|
|
|
|
`${global.sessionMode}.css`,
|
|
|
|
'stylesheet.css',
|
|
|
|
];
|
|
|
|
const theme = St.ThemeContext.get_for_stage(global.stage).get_theme();
|
|
|
|
for (const name of stylesheetNames) {
|
|
|
|
try {
|
|
|
|
const stylesheetFile = extension.dir.get_child(name);
|
|
|
|
theme.load_stylesheet(stylesheetFile);
|
|
|
|
extension.stylesheet = stylesheetFile;
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND))
|
|
|
|
continue; // not an error
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_unloadExtensionStylesheet(extension) {
|
|
|
|
if (!extension.stylesheet)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const theme = St.ThemeContext.get_for_stage(global.stage).get_theme();
|
|
|
|
theme.unload_stylesheet(extension.stylesheet);
|
|
|
|
delete extension.stylesheet;
|
|
|
|
}
|
|
|
|
|
2021-08-28 17:54:39 +00:00
|
|
|
_extensionSupportsSessionMode(uuid) {
|
2021-08-10 19:31:00 +00:00
|
|
|
const extension = this.lookup(uuid);
|
2021-08-28 17:54:39 +00: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;
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
if (extension.state !== ExtensionState.ENABLED)
|
2019-03-07 00:45:45 +00:00
|
|
|
return;
|
2011-10-14 22:06:03 +00:00
|
|
|
|
2022-07-25 02:25:23 +00:00
|
|
|
extension.state = ExtensionState.DISABLING;
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-21 21:53:05 +00:00
|
|
|
this._unloadExtensionStylesheet(extension);
|
2020-05-13 18:10:56 +00:00
|
|
|
|
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 {
|
2022-11-24 19:55:18 +00:00
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await 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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
if (extension.state !== ExtensionState.ERROR) {
|
2019-03-07 00:45:45 +00:00
|
|
|
extension.state = ExtensionState.DISABLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
2011-10-14 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _callExtensionEnable(uuid) {
|
2021-09-28 19:31:11 +00:00
|
|
|
if (!this._extensionSupportsSessionMode(uuid))
|
2019-09-11 18:24:17 +00:00
|
|
|
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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
if (extension.state === ExtensionState.INITIALIZED)
|
|
|
|
await this._callExtensionInit(uuid);
|
2011-10-25 18:38:25 +00:00
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
|
|
|
|
if (extension.state !== ExtensionState.DISABLED)
|
2019-03-07 00:45:45 +00:00
|
|
|
return;
|
2011-06-23 01:56:24 +00:00
|
|
|
|
2022-07-25 02:25:23 +00:00
|
|
|
extension.state = ExtensionState.ENABLING;
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
|
2023-03-21 21:53:05 +00:00
|
|
|
try {
|
|
|
|
this._loadExtensionStylesheet(extension);
|
|
|
|
} catch (e) {
|
|
|
|
this.logExtensionError(uuid, e);
|
|
|
|
return;
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
2011-10-14 22:06:03 +00:00
|
|
|
|
2018-08-03 15:46:27 +00:00
|
|
|
try {
|
2022-11-24 19:55:18 +00:00
|
|
|
await extension.stateObj.enable();
|
2019-03-07 00:45:45 +00:00
|
|
|
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) {
|
2023-03-21 21:53:05 +00:00
|
|
|
this._unloadExtensionStylesheet(extension);
|
2019-03-07 00:45:45 +00:00
|
|
|
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);
|
|
|
|
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.'));
|
2021-01-26 16:12:04 +00:00
|
|
|
notification.connect('activated',
|
|
|
|
() => source.open());
|
2020-01-26 22:47:24 +00:00
|
|
|
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-05-11 23:12:50 +00:00
|
|
|
const message = error instanceof Error
|
|
|
|
? error.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
|
|
|
|
2022-02-07 14:14:06 +00:00
|
|
|
logError(error, `Extension ${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);
|
2021-08-12 14:38:57 +00:00
|
|
|
metadataContents = new TextDecoder().decode(metadataContents);
|
2019-07-07 21:38:27 +00:00
|
|
|
} catch (e) {
|
2022-02-07 14:14:06 +00:00
|
|
|
throw new Error(`Failed to load metadata.json: ${e}`);
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
let meta;
|
|
|
|
try {
|
|
|
|
meta = JSON.parse(metadataContents);
|
|
|
|
} catch (e) {
|
2022-02-07 14:14:06 +00:00
|
|
|
throw new Error(`Failed to parse metadata.json: ${e}`);
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 17:29:19 +00: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 21:38:27 +00:00
|
|
|
for (let i = 0; i < requiredProperties.length; i++) {
|
2022-04-20 17:29:19 +00:00
|
|
|
const {
|
|
|
|
prop, typeName, typeCheck = v => typeof v === typeName,
|
|
|
|
} = requiredProperties[i];
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (!meta[prop])
|
2022-02-07 14:14:06 +00:00
|
|
|
throw new Error(`missing "${prop}" property in metadata.json`);
|
2022-04-20 17:29:19 +00:00
|
|
|
if (!typeCheck(meta[prop]))
|
|
|
|
throw new Error(`property "${prop}" is not of type ${typeName}`);
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (uuid != meta.uuid)
|
2022-02-07 14:14:06 +00:00
|
|
|
throw new Error(`uuid "${meta.uuid}" from metadata.json does not match directory name "${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,
|
2021-08-28 17:54:39 +00:00
|
|
|
sessionModes: meta['session-modes'] ? meta['session-modes'] : ['user'],
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async loadExtension(extension) {
|
2019-03-07 00:45:45 +00:00
|
|
|
// Default to error, we set success as the last step
|
|
|
|
extension.state = ExtensionState.ERROR;
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2021-11-19 19:15:37 +00:00
|
|
|
if (this._checkVersion && ExtensionUtils.isOutOfDate(extension)) {
|
2019-03-07 00:45:45 +00:00
|
|
|
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 {
|
2022-07-14 13:37:42 +00:00
|
|
|
let enabled = this._enabledExtensions.includes(extension.uuid) &&
|
|
|
|
this._extensionSupportsSessionMode(extension.uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
if (enabled) {
|
2022-11-24 19:55:18 +00:00
|
|
|
if (!await this._callExtensionInit(extension.uuid))
|
2019-03-07 00:45:45 +00:00
|
|
|
return;
|
2022-11-24 19:55:18 +00:00
|
|
|
|
|
|
|
if (extension.state === ExtensionState.DISABLED)
|
|
|
|
await 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
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async 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.
|
2022-11-24 19:55:18 +00:00
|
|
|
await this._callExtensionDisable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
|
|
|
|
extension.state = ExtensionState.UNINSTALLED;
|
|
|
|
this.emit('extension-state-changed', extension);
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
// The extension is now cached and it's impossible to load a different version
|
|
|
|
if (type === ExtensionType.PER_USER && extension.isImported)
|
2020-05-07 11:54:24 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async reloadExtension(oldExtension) {
|
2019-03-07 00:45:45 +00:00
|
|
|
// 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.
|
2023-03-14 11:57:43 +00:00
|
|
|
await 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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
await this.loadExtension(newExtension);
|
2017-05-17 22:03:28 +00:00
|
|
|
}
|
2009-10-25 22:53:10 +00:00
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _callExtensionInit(uuid) {
|
2021-09-28 19:31:11 +00:00
|
|
|
if (!this._extensionSupportsSessionMode(uuid))
|
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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
// TODO: This function does not have an async operation but when ESM is
|
|
|
|
// merged there will be a dynamic import here instead of `installImporter`.
|
|
|
|
await 0;
|
|
|
|
|
2019-03-07 00:45:45 +00:00
|
|
|
ExtensionUtils.installImporter(extension);
|
2022-11-24 19:55:18 +00:00
|
|
|
|
|
|
|
// Extensions can only be imported once, so add a property to avoid
|
|
|
|
// attempting to re-import an extension.
|
|
|
|
extension.isImported = true;
|
|
|
|
|
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 {
|
2022-11-24 19:55:18 +00:00
|
|
|
extensionState = await extensionModule.init(extension);
|
2019-03-07 00:45:45 +00:00
|
|
|
} 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 =
|
2022-11-24 19:55:18 +00:00
|
|
|
extension.state === ExtensionState.ERROR ||
|
|
|
|
extension.state === ExtensionState.OUT_OF_DATE;
|
2018-12-04 08:31:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _onUserExtensionsEnabledChanged() {
|
|
|
|
await this._onEnabledExtensionsChanged();
|
2018-12-04 08:31:27 +00:00
|
|
|
this._onSettingsWritableChanged();
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _onEnabledExtensionsChanged() {
|
2019-03-07 00:45:45 +00:00
|
|
|
let newEnabledExtensions = this._getEnabledExtensions();
|
|
|
|
|
|
|
|
// Find and enable all the newly enabled extensions: UUIDs found in the
|
|
|
|
// new setting, but not in the old one.
|
2022-11-24 19:55:18 +00:00
|
|
|
const extensionsToEnable = newEnabledExtensions
|
2021-08-28 17:54:39 +00:00
|
|
|
.filter(uuid => !this._enabledExtensions.includes(uuid) &&
|
2022-11-24 19:55:18 +00:00
|
|
|
this._extensionSupportsSessionMode(uuid));
|
|
|
|
for (const uuid of extensionsToEnable) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await this._callExtensionEnable(uuid);
|
|
|
|
}
|
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.
|
2022-11-24 19:55:18 +00:00
|
|
|
const extensionsToDisable = this._extensionOrder
|
2021-08-28 17:54:39 +00:00
|
|
|
.filter(uuid => !newEnabledExtensions.includes(uuid) ||
|
2022-11-24 19:55:18 +00:00
|
|
|
!this._extensionSupportsSessionMode(uuid));
|
|
|
|
// Reverse mutates the original array, but .filter() creates a new array.
|
|
|
|
extensionsToDisable.reverse();
|
|
|
|
|
|
|
|
for (const uuid of extensionsToDisable) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _onVersionValidationChanged() {
|
2021-11-19 19:15:37 +00:00
|
|
|
const checkVersion = !global.settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY);
|
|
|
|
if (checkVersion === this._checkVersion)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._checkVersion = checkVersion;
|
|
|
|
|
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
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
// Disable enabled extensions first to avoid
|
2018-11-19 11:26:16 +00:00
|
|
|
// the "rebasing" done in _callExtensionDisable...
|
2022-11-24 19:55:18 +00:00
|
|
|
this._disableAllExtensions();
|
2018-11-19 11:26:16 +00:00
|
|
|
|
|
|
|
// ...and then reload and enable extensions in the correct order again.
|
2022-11-24 19:55:18 +00:00
|
|
|
const extensionsToReload = [...this._extensions.values()].sort((a, b) => {
|
2018-11-19 11:26:16 +00:00
|
|
|
return extensionOrder.indexOf(a.uuid) - extensionOrder.indexOf(b.uuid);
|
2022-11-24 19:55:18 +00:00
|
|
|
});
|
|
|
|
for (const extension of extensionsToReload) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await 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;
|
|
|
|
|
2022-11-30 02:17:20 +00:00
|
|
|
for (const {dir, info} of FileUtils.collectFromDatadirs('extension-updates', true)) {
|
2020-01-22 14:09:05 +00:00
|
|
|
let fileType = info.get_file_type();
|
|
|
|
if (fileType !== Gio.FileType.DIRECTORY)
|
2022-11-30 02:17:20 +00:00
|
|
|
continue;
|
2020-01-22 14:09:05 +00:00
|
|
|
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) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Failed to install extension updates for ${uuid}`);
|
2020-03-09 15:45:22 +00:00
|
|
|
} finally {
|
|
|
|
FileUtils.recursivelyDeleteDir(dir, true);
|
|
|
|
}
|
2022-11-30 02:17:20 +00:00
|
|
|
}
|
2020-01-22 14:09:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _loadExtensions() {
|
|
|
|
global.settings.connect(`changed::${ENABLED_EXTENSIONS_KEY}`, () => {
|
|
|
|
this._onEnabledExtensionsChanged();
|
|
|
|
});
|
|
|
|
global.settings.connect(`changed::${DISABLED_EXTENSIONS_KEY}`, () => {
|
|
|
|
this._onEnabledExtensionsChanged();
|
|
|
|
});
|
|
|
|
global.settings.connect(`changed::${DISABLE_USER_EXTENSIONS_KEY}`, () => {
|
|
|
|
this._onUserExtensionsEnabledChanged();
|
|
|
|
});
|
|
|
|
global.settings.connect(`changed::${EXTENSION_DISABLE_VERSION_CHECK_KEY}`, () => {
|
|
|
|
this._onVersionValidationChanged();
|
|
|
|
});
|
|
|
|
global.settings.connect(`writable-changed::${ENABLED_EXTENSIONS_KEY}`, () =>
|
|
|
|
this._onSettingsWritableChanged());
|
|
|
|
global.settings.connect(`writable-changed::${DISABLED_EXTENSIONS_KEY}`, () =>
|
|
|
|
this._onSettingsWritableChanged());
|
2019-03-07 00:45:45 +00:00
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
await this._onVersionValidationChanged();
|
2021-11-19 19:15:37 +00:00
|
|
|
|
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);
|
2022-11-30 02:17:20 +00:00
|
|
|
|
|
|
|
const extensionFiles = [...FileUtils.collectFromDatadirs('extensions', true)];
|
|
|
|
const extensionObjects = extensionFiles.map(({dir, info}) => {
|
2019-07-07 21:38:27 +00:00
|
|
|
let fileType = info.get_file_type();
|
2022-11-30 02:17:20 +00:00
|
|
|
if (fileType !== Gio.FileType.DIRECTORY)
|
|
|
|
return null;
|
2019-07-07 21:38:27 +00:00
|
|
|
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) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Extension ${uuid} already installed in ${existing.path}. ${dir.get_path()} will not be loaded`);
|
2022-11-30 02:17:20 +00:00
|
|
|
return null;
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let extension;
|
|
|
|
let type = dir.has_prefix(perUserDir)
|
|
|
|
? ExtensionType.PER_USER
|
|
|
|
: ExtensionType.SYSTEM;
|
|
|
|
try {
|
|
|
|
extension = this.createExtensionObject(uuid, dir, type);
|
2022-11-30 02:17:20 +00:00
|
|
|
} catch (error) {
|
|
|
|
logError(error, `Could not load extension ${uuid}`);
|
|
|
|
return null;
|
2019-07-07 21:38:27 +00:00
|
|
|
}
|
2022-11-30 02:17:20 +00:00
|
|
|
|
|
|
|
return extension;
|
|
|
|
}).filter(extension => extension !== null);
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
for (const extension of extensionObjects) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await this.loadExtension(extension);
|
|
|
|
}
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _enableAllExtensions() {
|
|
|
|
if (!this._initializationPromise)
|
|
|
|
this._initializationPromise = this._loadExtensions();
|
|
|
|
|
|
|
|
await this._initializationPromise;
|
|
|
|
|
|
|
|
for (const uuid of this._enabledExtensions) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await this._callExtensionEnable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables all currently enabled extensions.
|
|
|
|
*/
|
|
|
|
async _disableAllExtensions() {
|
|
|
|
// Wait for extensions to finish loading before starting
|
|
|
|
// to disable, otherwise some extensions may enable after
|
|
|
|
// this function.
|
|
|
|
if (this._initializationPromise)
|
|
|
|
await this._initializationPromise;
|
|
|
|
|
|
|
|
const extensionsToDisable = this._extensionOrder.slice();
|
|
|
|
// Extensions are disabled in the reverse order
|
|
|
|
// from when they were enabled.
|
|
|
|
extensionsToDisable.reverse();
|
|
|
|
|
|
|
|
for (const uuid of extensionsToDisable) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await this._callExtensionDisable(uuid);
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
2012-11-29 15:09:21 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2022-11-24 19:55:18 +00:00
|
|
|
async _sessionUpdated() {
|
2021-09-28 19:31:11 +00:00
|
|
|
// Take care of added or removed sessionMode extensions
|
2022-11-24 19:55:18 +00:00
|
|
|
await this._onEnabledExtensionsChanged();
|
|
|
|
await this._enableAllExtensions();
|
2019-03-07 00:45:45 +00:00
|
|
|
}
|
|
|
|
};
|
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');
|
2022-07-01 11:24:08 +00:00
|
|
|
if (!this._app)
|
|
|
|
this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop');
|
2020-01-26 22:47:24 +00: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();
|
|
|
|
}
|
|
|
|
});
|