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 @@ ...@@ -41,37 +41,19 @@
originalConsoleLog('[WebAdapter] Loading Qt scripts for Qt environment'); originalConsoleLog('[WebAdapter] Loading Qt scripts for Qt environment');
// Load qwebchannel.js // Use document.write for synchronous loading in Qt environment
const qwebchannelScript = document.createElement('script'); // This ensures scripts are loaded before template's inline scripts run
qwebchannelScript.src = 'qrc:///qtwebchannel/qwebchannel.js'; document.write('<script src="qrc:///qtwebchannel/qwebchannel.js"><\/script>');
document.head.appendChild(qwebchannelScript); document.write('<script src="overlay://overlay.js"><\/script>');
// Load overlay.js
const overlayScript = document.createElement('script');
overlayScript.src = 'overlay://overlay.js';
document.head.appendChild(overlayScript);
return true; 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) { if (isQtEnvironment) {
originalConsoleLog('[WebAdapter] Qt environment detected, loading Qt scripts'); originalConsoleLog('[WebAdapter] Qt environment detected, loading Qt scripts synchronously');
// Load Qt scripts immediately using document.write for synchronous loading
// 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 {
window.loadQtScripts(); window.loadQtScripts();
}
return; 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