From c76c4939ac0637cffe61ed96b123e943e81d682e Mon Sep 17 00:00:00 2001 From: javalikescript Date: Sat, 25 Jan 2025 14:43:42 +0100 Subject: [PATCH] Load addons after boot --- extensions/web-base/www/app/boot.js | 46 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/extensions/web-base/www/app/boot.js b/extensions/web-base/www/app/boot.js index c15422d..d7d4c70 100644 --- a/extensions/web-base/www/app/boot.js +++ b/extensions/web-base/www/app/boot.js @@ -49,10 +49,30 @@ window.addEventListener('scroll', function () { } }); +function setupWebSocket() { + var protocol = location.protocol.replace('http', 'ws'); + var url = protocol + '//' + location.host + '/ws/'; + var webSocket = new WebSocket(url); + webSocket.onmessage = function(event) { + //console.log('webSocket.onmessage', event); + if (event.data) { + app.onMessage(JSON.parse(event.data)); + } + }; + webSocket.onopen = function() { + console.log('WebSocket opened at ' + url); + }; + webSocket.onclose = function() { + console.log('WebSocket closed'); + webSocket = null; + setTimeout(setupWebSocket, 3000); + }; +} + /************************************************************ * Load web base configuration and addons ************************************************************/ - Promise.all([ +Promise.all([ fetch('/engine/configuration/extensions/web-base').then(rejectIfNotOk).then(getJson).then(function(response) { return response.value; }), @@ -65,6 +85,8 @@ window.addEventListener('scroll', function () { } app.setTheme(webBaseConfig.theme || 'default'); app.user = user; + onHashchange(); + setupWebSocket(); if (Array.isArray(addons)) { return Promise.all(addons.map(function(addon) { console.log('loading addon ' + addon.id); @@ -74,25 +96,5 @@ window.addEventListener('scroll', function () { })); } })).then(function() { - onHashchange(); - function setupWebSocket() { - var protocol = location.protocol.replace('http', 'ws'); - var url = protocol + '//' + location.host + '/ws/'; - var webSocket = new WebSocket(url); - webSocket.onmessage = function(event) { - //console.log('webSocket.onmessage', event); - if (event.data) { - app.onMessage(JSON.parse(event.data)); - } - }; - webSocket.onopen = function() { - console.log('WebSocket opened at ' + url); - }; - webSocket.onclose = function() { - console.log('WebSocket closed'); - webSocket = null; - setTimeout(setupWebSocket, 3000); - }; - } - setupWebSocket(); + console.info('addons loaded'); });