From 2b62922e2e9705d006f3ef427d589e0bcd121a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 5 Jul 2023 14:38:18 +0200 Subject: [PATCH] wasm: Add qtloader compatibility API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement the main features of the pre Qt 6.6 loader as adaption layer on top of the new loader. Task-id: QTBUG-115049 Change-Id: Iabe860d3fb0488fd003876508787da3688e0c87b Reviewed-by: MikoĊ‚aj Boc Reviewed-by: Lorn Potter (cherry picked from commit 20d17b1a3b0e3a17a0ed1214cc21d84d79d3c829) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qtloader.js | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index b0252775118..ee6c91180bb 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -219,3 +219,57 @@ async function qtLoad(config) return instance; } + +// Compatibility API. This API is deprecated, +// and will be removed in a future version of Qt. +function QtLoader(qtConfig) { + + const warning = 'Warning: The QtLoader API is deprecated and will be removed in ' + + 'a future version of Qt. Please port to the new qtLoad() API.'; + console.warn(warning); + + let emscriptenConfig = qtConfig.moduleConfig || {} + qtConfig.moduleConfig = undefined; + const showLoader = qtConfig.showLoader; + qtConfig.showLoader = undefined; + const showError = qtConfig.showError; + qtConfig.showError = undefined; + const showExit = qtConfig.showExit; + qtConfig.showExit = undefined; + const showCanvas = qtConfig.showCanvas; + qtConfig.showCanvas = undefined; + if (qtConfig.canvasElements) { + qtConfig.containerElements = qtConfig.canvasElements + qtConfig.canvasElements = undefined; + } else { + qtConfig.containerElements = qtConfig.containerElements; + qtConfig.containerElements = undefined; + } + emscriptenConfig.qt = qtConfig; + + let qtloader = { + exitCode: undefined, + exitText: "", + loadEmscriptenModule: _name => { + try { + qtLoad(emscriptenConfig); + } catch (e) { + showError?.(e.message); + } + } + } + + qtConfig.onLoaded = () => { + showCanvas?.(); + } + + qtConfig.onExit = exit => { + qtloader.exitCode = exit.code + qtloader.exitText = exit.text; + showExit?.(); + } + + showLoader?.("Loading"); + + return qtloader; +};