From 4257fc9522beaa9b946e24fcf7b1f249f3093933 Mon Sep 17 00:00:00 2001 From: Evan Welsh Date: Tue, 5 Jul 2022 12:11:46 -0400 Subject: [PATCH] environment: Remove inline import of extensionUtils The logging function cannot be asynchronous, so move the override into main.js where ExtensionUtils can be imported at the top level. Importing ExtensionUtils in environment.js at the top level is not possible because it would import Main prematurely. Part-of: --- js/ui/environment.js | 17 ----------------- js/ui/main.js | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/js/ui/environment.js b/js/ui/environment.js index ca27e02fb..83df7bcce 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -316,27 +316,10 @@ function _easeActorProperty(actor, propName, target, params) { transition.connect('stopped', (t, finished) => callback(finished)); } -function _loggingFunc(...args) { - let fields = { 'MESSAGE': args.join(', ') }; - let domain = "GNOME Shell"; - - // If the caller is an extension, add it as metadata - let extension = imports.misc.extensionUtils.getCurrentExtension(); - if (extension != null) { - domain = extension.metadata.name; - fields['GNOME_SHELL_EXTENSION_UUID'] = extension.uuid; - fields['GNOME_SHELL_EXTENSION_NAME'] = extension.metadata.name; - } - - GLib.log_structured(domain, GLib.LogLevelFlags.LEVEL_MESSAGE, fields); -} - function init() { // Add some bindings to the global JS namespace globalThis.global = Shell.Global.get(); - globalThis.log = _loggingFunc; - globalThis._ = Gettext.gettext; globalThis.C_ = Gettext.pgettext; globalThis.ngettext = Gettext.ngettext; diff --git a/js/ui/main.js b/js/ui/main.js index d1f791a90..2d8804aca 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -141,7 +141,27 @@ function _sessionUpdated() { } } +/** + * @param {any...} args a list of values to log + */ +function _loggingFunc(...args) { + let fields = { 'MESSAGE': args.join(', ') }; + let domain = 'GNOME Shell'; + + // If the caller is an extension, add it as metadata + let extension = imports.misc.extensionUtils.getCurrentExtension(); + if (extension != null) { + domain = extension.metadata.name; + fields['GNOME_SHELL_EXTENSION_UUID'] = extension.uuid; + fields['GNOME_SHELL_EXTENSION_NAME'] = extension.metadata.name; + } + + GLib.log_structured(domain, GLib.LogLevelFlags.LEVEL_MESSAGE, fields); +} + function start() { + globalThis.log = _loggingFunc; + // These are here so we don't break compatibility. global.logError = globalThis.log; global.log = globalThis.log;