trilium/public/javascripts/status.js

49 lines
1.5 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 07:35:39 +08:00
const status = (function() {
const changesToPushCountEl = $("#changesToPushCount");
2017-11-05 07:35:39 +08:00
async function checkStatus() {
const resp = await $.ajax({
url: baseApiUrl + 'status',
type: 'POST',
contentType: "application/json",
data: JSON.stringify({
treeLoadTime: noteTree.getTreeLoadTime(),
currentNoteId: noteEditor.getCurrentNoteId(),
currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime()
2017-11-05 07:35:39 +08:00
}),
statusCode: {
401: () => {
// if the user got logged out then we should display the page
// here we do that by reloading which will force the redirect if the user is really logged out
window.location.reload(true);
},
409: () => {
// 409 means we need to migrate database, reload will take care of it
window.location.reload(true);
}
}
2017-11-05 07:35:39 +08:00
});
2017-11-05 07:35:39 +08:00
if (resp.changedTree) {
console.log("Reloading tree because of background changes");
noteTree.reload();
2017-11-05 07:35:39 +08:00
}
if (resp.changedCurrentNote) {
2017-11-09 11:33:08 +08:00
showMessage('Reloading note because background change');
noteEditor.reload();
}
changesToPushCountEl.html(resp.changesToPushCount);
}
2017-11-05 07:35:39 +08:00
setInterval(checkStatus, 5 * 1000);
2017-11-05 07:35:39 +08:00
return {
checkStatus
};
})();