Use document.write for synchronous Qt script loading

- In Qt environment, use document.write to load Qt scripts synchronously
- This ensures QWebChannel and overlay.js are available before template's inline scripts run
- Async loading was causing templates to fail because overlay object wasn't ready
parent ec731acc
......@@ -41,37 +41,19 @@
originalConsoleLog('[WebAdapter] Loading Qt scripts for Qt environment');
// Load qwebchannel.js
const qwebchannelScript = document.createElement('script');
qwebchannelScript.src = 'qrc:///qtwebchannel/qwebchannel.js';
document.head.appendChild(qwebchannelScript);
// Load overlay.js
const overlayScript = document.createElement('script');
overlayScript.src = 'overlay://overlay.js';
document.head.appendChild(overlayScript);
// Use document.write for synchronous loading in Qt environment
// This ensures scripts are loaded before template's inline scripts run
document.write('<script src="qrc:///qtwebchannel/qwebchannel.js"><\/script>');
document.write('<script src="overlay://overlay.js"><\/script>');
return true;
};
// If already in Qt environment, load Qt scripts and provide temporary overlay
// If already in Qt environment, load Qt scripts synchronously and exit
if (isQtEnvironment) {
originalConsoleLog('[WebAdapter] Qt environment detected, loading Qt scripts');
// Provide temporary overlay object with log function until Qt's overlay.js loads
// This prevents errors from template's console.log override that runs immediately
window.overlay = window.overlay || {
log: function(message) {
originalConsoleLog('[Overlay]', message);
}
};
// Load Qt scripts when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', window.loadQtScripts);
} else {
originalConsoleLog('[WebAdapter] Qt environment detected, loading Qt scripts synchronously');
// Load Qt scripts immediately using document.write for synchronous loading
window.loadQtScripts();
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment