trilium/public/javascripts/status.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 07:35:39 +08:00
const status = (function() {
const treeEl = $("#tree");
const $changesToPushCountEl = $("#changesToPushCount");
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
}
2017-11-05 07:35:39 +08:00
$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
};
})();