From 2416e4eec046c55b8bc6d2383f0e106a4116281e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sat, 27 May 2023 03:19:39 +0200 Subject: [PATCH] scripting: Make helper proxy initialization async We are about to port the helper proxy to GApplication, which means that it will establish a display connection before exporting its D-Bus name. That means that the compositor must be able to respond to a roundtrip request to avoid locking, so don't block on the proxy becoming available. Part-of: --- js/perf/closeWithActiveWindows.js | 2 +- js/ui/scripting.js | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/js/perf/closeWithActiveWindows.js b/js/perf/closeWithActiveWindows.js index 64fd63084..970de7d95 100644 --- a/js/perf/closeWithActiveWindows.js +++ b/js/perf/closeWithActiveWindows.js @@ -12,7 +12,7 @@ async function run() { /* eslint-disable no-await-in-loop */ /* Make created windows remain visible during exit. */ - Scripting.disableHelperAutoExit(); + await Scripting.disableHelperAutoExit(); const seat = Clutter.get_default_backend().get_default_seat(); const virtualDevice_ = diff --git a/js/ui/scripting.js b/js/ui/scripting.js index 951e9f94b..545db8531 100644 --- a/js/ui/scripting.js +++ b/js/ui/scripting.js @@ -64,14 +64,13 @@ function waitLeisure() { const PerfHelperIface = loadInterfaceXML('org.gnome.Shell.PerfHelper'); var PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface); -function PerfHelper() { - return new PerfHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper'); -} let _perfHelper = null; -function _getPerfHelper() { +/** private */ +async function _getPerfHelper() { if (_perfHelper == null) { - _perfHelper = new PerfHelper(); + _perfHelper = await PerfHelperProxy.newAsync( + Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper'); _perfHelper._autoExit = true; } @@ -100,7 +99,7 @@ function _spawnPerfHelper() { * because of the normal X asynchronous mapping process, to actually wait * until the window has been mapped and exposed, use waitTestWindows(). */ -function createTestWindow(params) { +async function createTestWindow(params) { params = Params.parse(params, { width: 640, height: 480, @@ -110,7 +109,7 @@ function createTestWindow(params) { textInput: false, }); - let perfHelper = _getPerfHelper(); + let perfHelper = await _getPerfHelper(); perfHelper.CreateWindowAsync( params.width, params.height, params.alpha, params.maximized, @@ -124,8 +123,8 @@ function createTestWindow(params) { * Used within an automation script to pause until all windows previously * created with createTestWindow have been mapped and exposed. */ -function waitTestWindows() { - let perfHelper = _getPerfHelper(); +async function waitTestWindows() { + let perfHelper = await _getPerfHelper(); return perfHelper.WaitWindowsAsync().catch(logError); } @@ -139,8 +138,8 @@ function waitTestWindows() { * this doesn't guarantee that Mutter has actually finished the destroy * process because of normal X asynchronicity. */ -function destroyTestWindows() { - let perfHelper = _getPerfHelper(); +async function destroyTestWindows() { + let perfHelper = await _getPerfHelper(); return perfHelper.DestroyWindowsAsync().catch(logError); } @@ -150,8 +149,8 @@ function destroyTestWindows() { * Don't exixt the perf helper after running the script. Instead it will remain * running until something else makes it exit, e.g. the Wayland socket closing. */ -function disableHelperAutoExit() { - let perfHelper = _getPerfHelper(); +async function disableHelperAutoExit() { + let perfHelper = await _getPerfHelper(); perfHelper._autoExit = false; } @@ -301,7 +300,7 @@ async function _runPerfScript(scriptModule, outputFile) { } try { - const perfHelper = _getPerfHelper(); + const perfHelper = await _getPerfHelper(); if (perfHelper._autoExit) perfHelper.ExitSync(); } catch (err) {