mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import options from './options.js';
|
|
import server from "./server.js";
|
|
|
|
let lastProtectedSessionOperationDate = 0;
|
|
|
|
setInterval(() => {
|
|
const protectedSessionTimeout = options.getInt('protectedSessionTimeout');
|
|
if (lastProtectedSessionOperationDate
|
|
&& Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
|
|
|
|
resetProtectedSession();
|
|
}
|
|
}, 10000);
|
|
|
|
function enableProtectedSession() {
|
|
glob.isProtectedSessionAvailable = true;
|
|
|
|
touchProtectedSession();
|
|
}
|
|
|
|
async function resetProtectedSession() {
|
|
await server.post("logout/protected");
|
|
}
|
|
|
|
function isProtectedSessionAvailable() {
|
|
return glob.isProtectedSessionAvailable;
|
|
}
|
|
|
|
function touchProtectedSession() {
|
|
if (isProtectedSessionAvailable()) {
|
|
lastProtectedSessionOperationDate = Date.now();
|
|
}
|
|
}
|
|
|
|
function touchProtectedSessionIfNecessary(note) {
|
|
if (note && note.isProtected && isProtectedSessionAvailable()) {
|
|
touchProtectedSession();
|
|
}
|
|
}
|
|
|
|
export default {
|
|
enableProtectedSession,
|
|
resetProtectedSession,
|
|
isProtectedSessionAvailable,
|
|
touchProtectedSession,
|
|
touchProtectedSessionIfNecessary
|
|
};
|