mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
making WS connection asynchronous to not block module registration
This commit is contained in:
parent
fddd1c278f
commit
299252b650
@ -3,9 +3,14 @@
|
|||||||
import treeService from './tree_service.js';
|
import treeService from './tree_service.js';
|
||||||
import noteDetailService from './note_detail.js';
|
import noteDetailService from './note_detail.js';
|
||||||
import utils from './utils.js';
|
import utils from './utils.js';
|
||||||
|
import recentNotes from '../dialogs/recent_notes.js';
|
||||||
|
|
||||||
const $changesToPushCount = $("#changes-to-push-count");
|
const $changesToPushCount = $("#changes-to-push-count");
|
||||||
|
|
||||||
|
let ws;
|
||||||
|
let lastSyncId;
|
||||||
|
let lastPingTs;
|
||||||
|
|
||||||
function logError(message) {
|
function logError(message) {
|
||||||
console.log(utils.now(), message); // needs to be separate from .trace()
|
console.log(utils.now(), message); // needs to be separate from .trace()
|
||||||
console.trace();
|
console.trace();
|
||||||
@ -80,36 +85,38 @@ function connectWebSocket() {
|
|||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ws = connectWebSocket();
|
setTimeout(() => {
|
||||||
|
ws = connectWebSocket();
|
||||||
|
|
||||||
let lastSyncId = glob.maxSyncIdAtLoad;
|
lastSyncId = glob.maxSyncIdAtLoad;
|
||||||
let lastPingTs = new Date().getTime();
|
lastPingTs = new Date().getTime();
|
||||||
let connectionBrokenNotification = null;
|
let connectionBrokenNotification = null;
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
if (new Date().getTime() - lastPingTs > 30000) {
|
if (new Date().getTime() - lastPingTs > 30000) {
|
||||||
if (!connectionBrokenNotification) {
|
if (!connectionBrokenNotification) {
|
||||||
connectionBrokenNotification = $.notify({
|
connectionBrokenNotification = $.notify({
|
||||||
// options
|
// options
|
||||||
message: "Lost connection to server"
|
message: "Lost connection to server"
|
||||||
},{
|
},{
|
||||||
// settings
|
// settings
|
||||||
type: 'danger',
|
type: 'danger',
|
||||||
delay: 100000000 // keep it until we explicitly close it
|
delay: 100000000 // keep it until we explicitly close it
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (connectionBrokenNotification) {
|
||||||
else if (connectionBrokenNotification) {
|
await connectionBrokenNotification.close();
|
||||||
await connectionBrokenNotification.close();
|
connectionBrokenNotification = null;
|
||||||
connectionBrokenNotification = null;
|
|
||||||
|
|
||||||
utils.showMessage("Re-connected to server");
|
utils.showMessage("Re-connected to server");
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
type: 'ping',
|
type: 'ping',
|
||||||
lastSyncId: lastSyncId
|
lastSyncId: lastSyncId
|
||||||
}));
|
}));
|
||||||
|
}, 1000);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user