Skip to content

Commit

Permalink
Load addons after boot
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Jan 25, 2025
1 parent c4cadf4 commit c76c493
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions extensions/web-base/www/app/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
Expand All @@ -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);
Expand All @@ -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');
});

0 comments on commit c76c493

Please sign in to comment.