extensionUtils: Always use manager to find current extension
Now that we always have an extension manager object, we can use the same code path for use from extensions and prefs. For that, inject the D-Bus service's extensionManager instead of the current extension. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2832>
This commit is contained in:
parent
10672597c2
commit
df350cab0a
@ -7,8 +7,6 @@ import GLib from 'gi://GLib';
|
|||||||
import GObject from 'gi://GObject';
|
import GObject from 'gi://GObject';
|
||||||
import Gtk from 'gi://Gtk?version=4.0';
|
import Gtk from 'gi://Gtk?version=4.0';
|
||||||
|
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
|
||||||
|
|
||||||
export const ExtensionPrefsDialog = GObject.registerClass({
|
export const ExtensionPrefsDialog = GObject.registerClass({
|
||||||
GTypeName: 'ExtensionPrefsDialog',
|
GTypeName: 'ExtensionPrefsDialog',
|
||||||
}, class ExtensionPrefsDialog extends Adw.PreferencesWindow {
|
}, class ExtensionPrefsDialog extends Adw.PreferencesWindow {
|
||||||
@ -27,9 +25,6 @@ export const ExtensionPrefsDialog = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _loadPrefs() {
|
async _loadPrefs() {
|
||||||
// give extension prefs access to their own extension object
|
|
||||||
ExtensionUtils.setCurrentExtension(this._extension);
|
|
||||||
|
|
||||||
const {dir, metadata} = this._extension;
|
const {dir, metadata} = this._extension;
|
||||||
|
|
||||||
const prefsJs = dir.get_child('prefs.js');
|
const prefsJs = dir.get_child('prefs.js');
|
||||||
|
@ -7,6 +7,7 @@ import {ExtensionPrefsDialog} from './extensionPrefsDialog.js';
|
|||||||
import {ServiceImplementation} from './dbusService.js';
|
import {ServiceImplementation} from './dbusService.js';
|
||||||
|
|
||||||
const {deserializeExtension} = imports.misc.extensionUtils;
|
const {deserializeExtension} = imports.misc.extensionUtils;
|
||||||
|
const {setExtensionManager} = imports.misc.extensionUtils;
|
||||||
const {loadInterfaceXML} = imports.misc.dbusUtils;
|
const {loadInterfaceXML} = imports.misc.dbusUtils;
|
||||||
|
|
||||||
const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions');
|
const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions');
|
||||||
@ -27,6 +28,7 @@ class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const extensionManager = new ExtensionManager();
|
const extensionManager = new ExtensionManager();
|
||||||
|
setExtensionManager(extensionManager);
|
||||||
|
|
||||||
export const ExtensionsService = class extends ServiceImplementation {
|
export const ExtensionsService = class extends ServiceImplementation {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/* exported ExtensionState, ExtensionType, getCurrentExtension,
|
/* exported ExtensionState, ExtensionType, getCurrentExtension,
|
||||||
getSettings, initTranslations, gettext, ngettext, pgettext,
|
getSettings, initTranslations, gettext, ngettext, pgettext,
|
||||||
openPrefs, isOutOfDate, serializeExtension,
|
openPrefs, isOutOfDate, serializeExtension,
|
||||||
deserializeExtension, setCurrentExtension */
|
deserializeExtension, setExtensionManager */
|
||||||
|
|
||||||
// Common utils for the extension system and the extension
|
// Common utils for the extension system and the extension
|
||||||
// preferences tool
|
// preferences tool
|
||||||
@ -14,18 +14,7 @@ const Gettext = imports.gettext;
|
|||||||
|
|
||||||
const Config = imports.misc.config;
|
const Config = imports.misc.config;
|
||||||
|
|
||||||
let Main = null;
|
let _extensionManager = null;
|
||||||
|
|
||||||
try {
|
|
||||||
Main = imports.ui.main;
|
|
||||||
} catch (error) {
|
|
||||||
// Only log the error if it is not due to the
|
|
||||||
// missing import.
|
|
||||||
if (error?.name !== 'ImportError')
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
let _extension = null;
|
|
||||||
|
|
||||||
var ExtensionType = {
|
var ExtensionType = {
|
||||||
SYSTEM: 1,
|
SYSTEM: 1,
|
||||||
@ -58,13 +47,13 @@ const SERIALIZED_PROPERTIES = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} extension the extension object to use in utilities like `initTranslations()`
|
* @param {object} extensionManager to use in utilities like `initTranslations()`
|
||||||
*/
|
*/
|
||||||
function setCurrentExtension(extension) {
|
function setExtensionManager(extensionManager) {
|
||||||
if (Main)
|
if (_extensionManager)
|
||||||
throw new Error('setCurrentExtension() can only be called from outside the shell');
|
throw new Error('Trying to override existing extension manager');
|
||||||
|
|
||||||
_extension = extension;
|
_extensionManager = extensionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,9 +63,6 @@ function setCurrentExtension(extension) {
|
|||||||
* an extension.
|
* an extension.
|
||||||
*/
|
*/
|
||||||
function getCurrentExtension() {
|
function getCurrentExtension() {
|
||||||
if (_extension)
|
|
||||||
return _extension;
|
|
||||||
|
|
||||||
const basePath = '/gnome-shell/extensions/';
|
const basePath = '/gnome-shell/extensions/';
|
||||||
|
|
||||||
// Search for an occurrence of an extension stack frame
|
// Search for an occurrence of an extension stack frame
|
||||||
@ -89,8 +75,9 @@ function getCurrentExtension() {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// local import, as the module is used from outside the gnome-shell process
|
// local import, as the module is used from outside the gnome-shell process
|
||||||
// as well (not this function though)
|
// as well
|
||||||
let extensionManager = imports.ui.main.extensionManager;
|
if (!_extensionManager)
|
||||||
|
setExtensionManager(imports.ui.main.extensionManager);
|
||||||
|
|
||||||
// The exact stack line differs depending on where the function
|
// The exact stack line differs depending on where the function
|
||||||
// was called (function or module scope), and whether it's called
|
// was called (function or module scope), and whether it's called
|
||||||
@ -106,7 +93,7 @@ function getCurrentExtension() {
|
|||||||
path = GLib.path_get_dirname(path);
|
path = GLib.path_get_dirname(path);
|
||||||
|
|
||||||
const dirName = GLib.path_get_basename(path);
|
const dirName = GLib.path_get_basename(path);
|
||||||
const extension = extensionManager.lookup(dirName);
|
const extension = _extensionManager.lookup(dirName);
|
||||||
if (extension !== undefined)
|
if (extension !== undefined)
|
||||||
return extension;
|
return extension;
|
||||||
} while (path !== '/');
|
} while (path !== '/');
|
||||||
|
Loading…
Reference in New Issue
Block a user