Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixed unloading the encrypted page after encryption timeout by simply reloading the app completely plus some unrelated refactorings
azivnerb192336113f6
diff --git a/public/javascripts/dialogs/settings.js b/public/javascripts/dialogs/settings.jsindex f968e85e49..244b4b805e 100644--- a/public/javascripts/dialogs/settings.js+++ b/public/javascripts/dialogs/settings.js@@ -26,7 +26,7 @@ const settings = (function() {tabsEl.tabs();- for (module of settingModules) {+ for (const module of settingModules) {module.settingsLoaded(settings);}}diff --git a/public/javascripts/encryption.js b/public/javascripts/encryption.jsindex 0634c41399..2c96b3beb3 100644--- a/public/javascripts/encryption.js+++ b/public/javascripts/encryption.js@@ -22,10 +22,6 @@ const encryption = (function() {encryptedDataKey = settings.encrypted_data_key;});- function setEncryptionSalt(encSalt) {- encryptionSalt = encSalt;- }-function setEncryptedDataKey(encDataKey) {encryptedDataKey = encDataKey;}@@ -149,15 +145,9 @@ const encryption = (function() {dataKey = null;if (noteEditor.getCurrentNote().detail.encryption > 0) {- noteEditor.loadNoteToEditor(noteEditor.getCurrentNoteId());-- for (const noteId of glob.allNoteIds) {- const note = getNodeByKey(noteId);-- if (note.data.encryption > 0) {- note.setTitle("[encrypted]");- }- }+ // most secure solution - guarantees nothing remained in memory+ // since this expires because user doesn't use the app, it shouldn't be disruptive+ window.location.reload(true);}}diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.jsindex af71adbbb6..7dd442d2a4 100644--- a/public/javascripts/note_editor.js+++ b/public/javascripts/note_editor.js@@ -11,7 +11,6 @@ const noteEditor = (function() {const encryptionPasswordEl = $("#encryption-password");let currentNote = null;- let currentNoteLoadTime = null;let noteChangeDisabled = false;@@ -26,7 +25,7 @@ const noteEditor = (function() {}function getCurrentNoteLoadTime() {- return currentNoteLoadTime;+ return currentNote ? currentNote.loadTime : null;}function noteChanged() {@@ -100,9 +99,6 @@ const noteEditor = (function() {message("Saved!");}- currentNote = null;- currentNoteLoadTime = null;-function createNewTopLevelNote() {let rootNode = treeEl.fancytree("getRootNode");@@ -179,9 +175,7 @@ const noteEditor = (function() {}async function loadNoteToEditor(noteId) {- const note = await $.get(baseApiUrl + 'notes/' + noteId);- currentNote = note;- currentNoteLoadTime = Math.floor(new Date().getTime() / 1000);+ currentNote = await $.get(baseApiUrl + 'notes/' + noteId);if (newNoteCreated) {newNoteCreated = false;@@ -189,7 +183,7 @@ const noteEditor = (function() {noteTitleEl.focus().select();}- await encryption.ensureEncryptionIsAvailable(note.detail.encryption > 0, false);+ await encryption.ensureEncryptionIsAvailable(currentNote.detail.encryption > 0, false);noteDetailWrapperEl.show();@@ -201,24 +195,24 @@ const noteEditor = (function() {encryptionPasswordEl.val('');- encryption.decryptNoteIfNecessary(note);+ encryption.decryptNoteIfNecessary(currentNote);- noteTitleEl.val(note.detail.note_title);+ noteTitleEl.val(currentNote.detail.note_title);noteChangeDisabled = true;// Clear contents and remove all stored history. This is to prevent undo from going across notesnoteDetailEl.summernote('reset');- noteDetailEl.summernote('code', note.detail.note_text);+ noteDetailEl.summernote('code', currentNote.detail.note_text);document.location.hash = noteId;- recentNotes.addRecentNote(noteId, note.detail.note_id);+ recentNotes.addRecentNote(noteId, currentNote.detail.note_id);noteChangeDisabled = false;- setNoteBackgroundIfEncrypted(note);+ setNoteBackgroundIfEncrypted(currentNote);}async function loadNote(noteId) {diff --git a/public/javascripts/status.js b/public/javascripts/status.jsindex 31f80597ab..b9111b4fd0 100644--- a/public/javascripts/status.js+++ b/public/javascripts/status.js@@ -12,7 +12,7 @@ const status = (function() {data: JSON.stringify({treeLoadTime: noteTree.getTreeLoadTime(),currentNoteId: noteEditor.getCurrentNoteId(),- currentNoteDateModified: noteEditor.getCurrentNoteLoadTime()+ currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime()}),statusCode: {401: () => {diff --git a/routes/api/notes.js b/routes/api/notes.jsindex 006a6d0137..b7c8816aa3 100644--- a/routes/api/notes.js+++ b/routes/api/notes.js@@ -21,8 +21,9 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {}res.send({- 'detail': detail,- 'images': await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId])+ detail: detail,+ images: await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId]),+ loadTime: utils.nowTimestamp()});});diff --git a/routes/api/status.js b/routes/api/status.jsindex b84983f78b..3b27b7f44e 100644--- a/routes/api/status.js+++ b/routes/api/status.js@@ -11,7 +11,7 @@ const audit_category = require('../../services/audit_category');router.post('', auth.checkApiAuth, async (req, res, next) => {const treeLoadTime = req.body.treeLoadTime;const currentNoteId = req.body.currentNoteId;- const currentNoteDateModified = req.body.currentNoteDateModified;+ const currentNoteLoadTime = req.body.currentNoteLoadTime;const browserId = req.get('x-browser-id');@@ -20,13 +20,13 @@ router.post('', auth.checkApiAuth, async (req, res, next) => {audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION]);const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +- "AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteDateModified, currentNoteId,+ "AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteLoadTime, currentNoteId,audit_category.UPDATE_CONTENT]);if (currentNoteChangesCount > 0) {console.log("Current note changed!");console.log("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != '" + browserId + "') " +- "AND date_modified >= " + currentNoteDateModified + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");+ "AND date_modified >= " + currentNoteLoadTime + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");}let changesToPushCount = 0;