From 55cf8cf4bbe67bd31eed2e8692623dcd2e74877e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 9 Jul 2023 02:13:17 +0200 Subject: [PATCH] extensions/internals: Port to ESM We got rid of all uses of extension utils code in the gnome-shell process itself, and everything that is now using it - including extensions - is already loaded as module. We can therefore quickly move the file to ESM, which will help a bit with upcoming changes. Part-of: --- .eslintrc.yml | 1 + .../extensions/extensionsService.js | 2 +- js/extensions/sharedInternals.js | 25 ++++++++----------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 60fb8efa7..8a7d9f51b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -8,6 +8,7 @@ overrides: - js/ui/scripting.js - js/misc/dependencies.js - js/dbusServices/** + - js/extensions/** - js/portalHelper/** - subprojects/extensions-app/** - subprojects/extensions-tool/** diff --git a/js/dbusServices/extensions/extensionsService.js b/js/dbusServices/extensions/extensionsService.js index cd87f6c79..f0c93f6cb 100644 --- a/js/dbusServices/extensions/extensionsService.js +++ b/js/dbusServices/extensions/extensionsService.js @@ -5,9 +5,9 @@ import Shew from 'gi://Shew'; import {ExtensionPrefsDialog} from './extensionPrefsDialog.js'; import {ServiceImplementation} from './dbusService.js'; +import {setExtensionManager} from './extensions/sharedInternals.js'; const {deserializeExtension} = imports.misc.extensionUtils; -const {setExtensionManager} = imports.extensions.sharedInternals; const {loadInterfaceXML} = imports.misc.dbusUtils; const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions'); diff --git a/js/extensions/sharedInternals.js b/js/extensions/sharedInternals.js index 23f553664..0be5dfb55 100644 --- a/js/extensions/sharedInternals.js +++ b/js/extensions/sharedInternals.js @@ -1,10 +1,7 @@ -/* exported getCurrentExtension, setExtensionManager, getSettings, - initTranslations, gettext, ngettext, pgettext, openPrefs */ +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; -const Gio = imports.gi.Gio; -const GLib = imports.gi.GLib; - -const Gettext = imports.gettext; +import * as Gettext from 'gettext'; const Config = imports.misc.config; @@ -13,7 +10,7 @@ let _extensionManager = null; /** * @param {object} extensionManager to use in utilities like `initTranslations()` */ -function setExtensionManager(extensionManager) { +export function setExtensionManager(extensionManager) { if (_extensionManager) throw new Error('Trying to override existing extension manager'); @@ -26,7 +23,7 @@ function setExtensionManager(extensionManager) { * @returns {?object} - The current extension, or null if not called from * an extension. */ -function getCurrentExtension() { +export function getCurrentExtension() { const basePath = '/gnome-shell/extensions/'; // Search for an occurrence of an extension stack frame @@ -71,7 +68,7 @@ function getCurrentExtension() { * * @param {string=} domain - the gettext domain to use */ -function initTranslations(domain) { +export function initTranslations(domain) { let extension = getCurrentExtension(); if (!extension) @@ -97,7 +94,7 @@ function initTranslations(domain) { * * @returns {string} - the translated string */ -function gettext(str) { +export function gettext(str) { return callExtensionGettextFunc('gettext', str); } @@ -111,7 +108,7 @@ function gettext(str) { * * @returns {string} - the translated string */ -function ngettext(str, strPlural, n) { +export function ngettext(str, strPlural, n) { return callExtensionGettextFunc('ngettext', str, strPlural, n); } @@ -124,7 +121,7 @@ function ngettext(str, strPlural, n) { * * @returns {string} - the translated string */ -function pgettext(context, str) { +export function pgettext(context, str) { return callExtensionGettextFunc('pgettext', context, str); } @@ -153,7 +150,7 @@ function callExtensionGettextFunc(func, ...args) { * @param {string=} schema - the GSettings schema id * @returns {Gio.Settings} - a new settings object for @schema */ -function getSettings(schema) { +export function getSettings(schema) { let extension = getCurrentExtension(); if (!extension) @@ -184,7 +181,7 @@ function getSettings(schema) { /** * Open the preference dialog of the current extension */ -function openPrefs() { +export function openPrefs() { const extension = getCurrentExtension(); if (!extension)