mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[fix] No messages displayed on web admin top bar
This commit is contained in:
parent
e775c66514
commit
5b19e7974a
1 changed files with 25 additions and 14 deletions
|
@ -65,14 +65,19 @@
|
||||||
api: function(uri, callback, method, data, websocket, callbackOnFailure) {
|
api: function(uri, callback, method, data, websocket, callbackOnFailure) {
|
||||||
c = this;
|
c = this;
|
||||||
|
|
||||||
|
method = typeof method !== 'undefined' ? method : 'GET';
|
||||||
|
data = typeof data !== 'undefined' ? data : {};
|
||||||
|
if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) {
|
||||||
|
data.locale = y18n.locale || window.navigator.language.substr(0, 2);
|
||||||
|
}
|
||||||
|
app.loaded = false;
|
||||||
|
if ($('div.loader').length === 0) {
|
||||||
|
$('#main').append('<div class="loader loader-content"></div>');
|
||||||
|
}
|
||||||
call = function(uri, callback, method, data, callbackOnFailure) {
|
call = function(uri, callback, method, data, callbackOnFailure) {
|
||||||
method = typeof method !== 'undefined' ? method : 'GET';
|
|
||||||
data = typeof data !== 'undefined' ? data : {};
|
|
||||||
if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) {
|
|
||||||
data.locale = y18n.locale || window.navigator.language.substr(0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = data;
|
var args = data;
|
||||||
|
// TODO: change this code
|
||||||
if (uri === '/postinstall') {
|
if (uri === '/postinstall') {
|
||||||
var installing = false;
|
var installing = false;
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
|
@ -80,10 +85,6 @@
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.loaded = false;
|
|
||||||
if ($('div.loader').length === 0) {
|
|
||||||
$('#main').append('<div class="loader loader-content"></div>');
|
|
||||||
}
|
|
||||||
if (typeof callbackOnFailure !== 'function') {
|
if (typeof callbackOnFailure !== 'function') {
|
||||||
callbackOnFailure = function(xhr) {
|
callbackOnFailure = function(xhr) {
|
||||||
// Postinstall is a custom case, we have to wait that
|
// Postinstall is a custom case, we have to wait that
|
||||||
|
@ -170,9 +171,12 @@
|
||||||
|
|
||||||
websocket = typeof websocket !== 'undefined' ? websocket : true;
|
websocket = typeof websocket !== 'undefined' ? websocket : true;
|
||||||
if (websocket) {
|
if (websocket) {
|
||||||
|
|
||||||
// Open a WebSocket connection to retrieve live messages from the moulinette
|
// Open a WebSocket connection to retrieve live messages from the moulinette
|
||||||
var ws = new WebSocket('wss://'+ store.get('url') +'/messages');
|
var ws = new WebSocket('wss://'+ store.get('url') +'/messages');
|
||||||
|
// Flag to avoid to call twice the API
|
||||||
|
// We need to set that in ws object as we need to use it in ws.onopen
|
||||||
|
// and several ws object could be running at the same time...
|
||||||
|
ws.api_called = false;
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
// console.log(evt.data);
|
// console.log(evt.data);
|
||||||
$.each($.parseJSON(evt.data), function(k, v) {
|
$.each($.parseJSON(evt.data), function(k, v) {
|
||||||
|
@ -181,11 +185,18 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// If not connected, WebSocket connection will raise an error, but we do not want to interrupt API request
|
// If not connected, WebSocket connection will raise an error, but we do not want to interrupt API request
|
||||||
ws.onerror = ws.onopen;
|
ws.onerror = function () {
|
||||||
|
ws.onopen();
|
||||||
|
};
|
||||||
|
|
||||||
ws.onclose = function() {};
|
ws.onclose = function() { };
|
||||||
|
|
||||||
ws.onopen = call(uri, callback, method, data, callbackOnFailure);
|
ws.onopen = function () {
|
||||||
|
if (!ws.api_called) {
|
||||||
|
ws.api_called = true;
|
||||||
|
call(uri, callback, method, data, callbackOnFailure);
|
||||||
|
}
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
call(uri, callback, method, data, callbackOnFailure);
|
call(uri, callback, method, data, callbackOnFailure);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue