mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	decoupled protected session holder from presentation stuff and similar things
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| import treeService from '../services/tree.js'; | import treeService from '../services/tree.js'; | ||||||
| import messagingService from '../services/messaging.js'; | import messagingService from '../services/messaging.js'; | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
|  | import utils from "../services/utils"; | ||||||
|  |  | ||||||
| const $dialog = $("#recent-notes-dialog"); | const $dialog = $("#recent-notes-dialog"); | ||||||
| const $searchInput = $('#recent-notes-search-input'); | const $searchInput = $('#recent-notes-search-input'); | ||||||
| @@ -92,6 +93,14 @@ async function showDialog() { | |||||||
|  |  | ||||||
| setTimeout(reload, 100); | setTimeout(reload, 100); | ||||||
|  |  | ||||||
|  | messagingService.subscribeToMessages(syncData => { | ||||||
|  |     if (syncData.some(sync => sync.entityName === 'recent_notes')) { | ||||||
|  |         console.log(utils.now(), "Reloading recent notes because of background changes"); | ||||||
|  |  | ||||||
|  |         reload(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     showDialog, |     showDialog, | ||||||
|     addRecentNote, |     addRecentNote, | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| import protectedSessionService from '../services/protected_session.js'; | import protectedSessionHolder from '../services/protected_session_holder.js'; | ||||||
| import utils from '../services/utils.js'; | import utils from '../services/utils.js'; | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
|  |  | ||||||
| @@ -77,7 +77,7 @@ addModule((function() { | |||||||
|                 alert("Password has been changed. Trilium will be reloaded after you press OK."); |                 alert("Password has been changed. Trilium will be reloaded after you press OK."); | ||||||
|  |  | ||||||
|                 // password changed so current protected session is invalid and needs to be cleared |                 // password changed so current protected session is invalid and needs to be cleared | ||||||
|                 protectedSessionService.resetProtectedSession(); |                 protectedSessionHolder.resetProtectedSession(); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 utils.showError(result.message); |                 utils.showError(result.message); | ||||||
| @@ -105,7 +105,7 @@ addModule((function() { | |||||||
|         const protectedSessionTimeout = $protectedSessionTimeout.val(); |         const protectedSessionTimeout = $protectedSessionTimeout.val(); | ||||||
|  |  | ||||||
|         settings.saveSettings(settingName, protectedSessionTimeout).then(() => { |         settings.saveSettings(settingName, protectedSessionTimeout).then(() => { | ||||||
|             protectedSessionService.setProtectedSessionTimeout(protectedSessionTimeout); |             protectedSessionHolder.setProtectedSessionTimeout(protectedSessionTimeout); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								src/public/javascripts/services/bundle.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/public/javascripts/services/bundle.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | import ScriptContext from "./script_context"; | ||||||
|  |  | ||||||
|  | async function executeBundle(bundle) { | ||||||
|  |     const apiContext = ScriptContext(bundle.note, bundle.allNotes); | ||||||
|  |  | ||||||
|  |     return await (function () { | ||||||
|  |         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); | ||||||
|  |     }.call(apiContext)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     executeBundle | ||||||
|  | } | ||||||
| @@ -1,10 +1,10 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
|  |  | ||||||
| function exportSubTree(noteId) { | function exportSubTree(noteId) { | ||||||
|     const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId=" |     const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId=" | ||||||
|         + encodeURIComponent(protectedSessionService.getProtectedSessionId()); |         + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); | ||||||
|  |  | ||||||
|     utils.download(url); |     utils.download(url); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import noteDetailService from './note_detail.js'; | |||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|  | import bundleService from './bundle.js'; | ||||||
|  |  | ||||||
| // hot keys are active also inside inputs and content editables | // hot keys are active also inside inputs and content editables | ||||||
| jQuery.hotkeys.options.filterInputAcceptingElements = false; | jQuery.hotkeys.options.filterInputAcceptingElements = false; | ||||||
| @@ -209,7 +210,7 @@ $("#logout-button").toggle(!utils.isElectron()); | |||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     server.get("script/startup").then(scriptBundles => { |     server.get("script/startup").then(scriptBundles => { | ||||||
|         for (const bundle of scriptBundles) { |         for (const bundle of scriptBundles) { | ||||||
|             utils.executeBundle(bundle); |             bundleService.executeBundle(bundle); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -1,10 +1,9 @@ | |||||||
| import treeService from './tree.js'; |  | ||||||
| import noteDetailService from './note_detail.js'; |  | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import recentNotesDialog from '../dialogs/recent_notes.js'; |  | ||||||
|  |  | ||||||
| const $changesToPushCount = $("#changes-to-push-count"); | const $changesToPushCount = $("#changes-to-push-count"); | ||||||
|  |  | ||||||
|  | const messageHandlers = []; | ||||||
|  |  | ||||||
| let ws; | let ws; | ||||||
| let lastSyncId; | let lastSyncId; | ||||||
| let lastPingTs; | let lastPingTs; | ||||||
| @@ -21,7 +20,11 @@ function logError(message) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function messageHandler(event) { | function subscribeToMessages(messageHandler) { | ||||||
|  |     messageHandlers.push(messageHandler); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function handleMessage(event) { | ||||||
|     const message = JSON.parse(event.data); |     const message = JSON.parse(event.data); | ||||||
|  |  | ||||||
|     if (message.type === 'sync') { |     if (message.type === 'sync') { | ||||||
| @@ -35,29 +38,10 @@ function messageHandler(event) { | |||||||
|  |  | ||||||
|         const syncData = message.data.filter(sync => sync.sourceId !== glob.sourceId); |         const syncData = message.data.filter(sync => sync.sourceId !== glob.sourceId); | ||||||
|  |  | ||||||
|         if (syncData.some(sync => sync.entityName === 'branches') |         for (const messageHandler of messageHandlers) { | ||||||
|             || syncData.some(sync => sync.entityName === 'notes')) { |             messageHandler(syncData); | ||||||
|  |  | ||||||
|             console.log(utils.now(), "Reloading tree because of background changes"); |  | ||||||
|  |  | ||||||
|             treeService.reload(); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === noteDetailService.getCurrentNoteId())) { |  | ||||||
|             utils.showMessage('Reloading note because of background changes'); |  | ||||||
|  |  | ||||||
|             noteDetailService.reload(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (syncData.some(sync => sync.entityName === 'recent_notes')) { |  | ||||||
|             console.log(utils.now(), "Reloading recent notes because of background changes"); |  | ||||||
|  |  | ||||||
|             recentNotesDialog.reload(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // we don't detect image changes here since images themselves are immutable and references should be |  | ||||||
|         // updated in note detail as well |  | ||||||
|  |  | ||||||
|         $changesToPushCount.html(message.changesToPushCount); |         $changesToPushCount.html(message.changesToPushCount); | ||||||
|     } |     } | ||||||
|     else if (message.type === 'sync-hash-check-failed') { |     else if (message.type === 'sync-hash-check-failed') { | ||||||
| @@ -74,7 +58,7 @@ function connectWebSocket() { | |||||||
|     // use wss for secure messaging |     // use wss for secure messaging | ||||||
|     const ws = new WebSocket(protocol + "://" + location.host); |     const ws = new WebSocket(protocol + "://" + location.host); | ||||||
|     ws.onopen = event => console.log(utils.now(), "Connected to server with WebSocket"); |     ws.onopen = event => console.log(utils.now(), "Connected to server with WebSocket"); | ||||||
|     ws.onmessage = messageHandler; |     ws.onmessage = handleMessage; | ||||||
|     ws.onclose = function(){ |     ws.onclose = function(){ | ||||||
|         // Try to reconnect in 5 seconds |         // Try to reconnect in 5 seconds | ||||||
|         setTimeout(() => connectWebSocket(), 5000); |         setTimeout(() => connectWebSocket(), 5000); | ||||||
| @@ -118,5 +102,6 @@ setTimeout(() => { | |||||||
| }, 1000); | }, 1000); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     logError |     logError, | ||||||
|  |     subscribeToMessages | ||||||
| }; | }; | ||||||
| @@ -1,8 +1,11 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import noteTypeService from './note_type.js'; | import noteTypeService from './note_type.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionService from './protected_session.js'; | ||||||
|  | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|  | import messagingService from "./messaging.js"; | ||||||
|  | import bundleService from "./bundle.js"; | ||||||
|  |  | ||||||
| const $noteTitle = $("#note-title"); | const $noteTitle = $("#note-title"); | ||||||
|  |  | ||||||
| @@ -78,7 +81,7 @@ async function saveNoteIfChanged() { | |||||||
|     await saveNoteToServer(note); |     await saveNoteToServer(note); | ||||||
|  |  | ||||||
|     if (note.detail.isProtected) { |     if (note.detail.isProtected) { | ||||||
|         protectedSessionService.touchProtectedSession(); |         protectedSessionHolder.touchProtectedSession(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -222,7 +225,7 @@ async function loadNoteToEditor(noteId) { | |||||||
|     await protectedSessionService.ensureProtectedSession(currentNote.detail.isProtected, false); |     await protectedSessionService.ensureProtectedSession(currentNote.detail.isProtected, false); | ||||||
|  |  | ||||||
|     if (currentNote.detail.isProtected) { |     if (currentNote.detail.isProtected) { | ||||||
|         protectedSessionService.touchProtectedSession(); |         protectedSessionHolder.touchProtectedSession(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // this might be important if we focused on protected note when not in protected note and we got a dialog |     // this might be important if we focused on protected note when not in protected note and we got a dialog | ||||||
| @@ -251,7 +254,7 @@ async function loadNoteToEditor(noteId) { | |||||||
|  |  | ||||||
|         $noteDetailRender.html(bundle.html); |         $noteDetailRender.html(bundle.html); | ||||||
|  |  | ||||||
|         utils.executeBundle(bundle); |         bundleService.executeBundle(bundle); | ||||||
|     } |     } | ||||||
|     else if (currentNote.detail.type === 'file') { |     else if (currentNote.detail.type === 'file') { | ||||||
|         $noteDetailAttachment.show(); |         $noteDetailAttachment.show(); | ||||||
| @@ -333,7 +336,7 @@ async function executeCurrentNote() { | |||||||
|         if (currentNote.detail.mime.endsWith("env=frontend")) { |         if (currentNote.detail.mime.endsWith("env=frontend")) { | ||||||
|             const bundle = await server.get('script/bundle/' + getCurrentNoteId()); |             const bundle = await server.get('script/bundle/' + getCurrentNoteId()); | ||||||
|  |  | ||||||
|             utils.executeBundle(bundle); |             bundleService.executeBundle(bundle); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (currentNote.detail.mime.endsWith("env=backend")) { |         if (currentNote.detail.mime.endsWith("env=backend")) { | ||||||
| @@ -360,9 +363,17 @@ $attachmentOpen.click(() => { | |||||||
| function getAttachmentUrl() { | function getAttachmentUrl() { | ||||||
|     // electron needs absolute URL so we extract current host, port, protocol |     // electron needs absolute URL so we extract current host, port, protocol | ||||||
|     return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId() |     return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId() | ||||||
|         + "?protectedSessionId=" + encodeURIComponent(protectedSessionService.getProtectedSessionId()); |         + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | messagingService.subscribeToMessages(syncData => { | ||||||
|  |     if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) { | ||||||
|  |         utils.showMessage('Reloading note because of background changes'); | ||||||
|  |  | ||||||
|  |         reload(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     $noteTitle.on('input', () => { |     $noteTitle.on('input', () => { | ||||||
|         noteChanged(); |         noteChanged(); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import treeService from './tree.js'; | |||||||
| import noteDetail from './note_detail.js'; | import noteDetail from './note_detail.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|  | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
|  |  | ||||||
| const $dialog = $("#protected-session-password-dialog"); | const $dialog = $("#protected-session-password-dialog"); | ||||||
| const $passwordForm = $("#protected-session-password-form"); | const $passwordForm = $("#protected-session-password-form"); | ||||||
| @@ -11,22 +12,11 @@ const $protectButton = $("#protect-button"); | |||||||
| const $unprotectButton = $("#unprotect-button"); | const $unprotectButton = $("#unprotect-button"); | ||||||
|  |  | ||||||
| let protectedSessionDeferred = null; | let protectedSessionDeferred = null; | ||||||
| let lastProtectedSessionOperationDate = null; |  | ||||||
| let protectedSessionTimeout = null; |  | ||||||
| let protectedSessionId = null; |  | ||||||
|  |  | ||||||
| $(document).ready(() => { |  | ||||||
|     server.get('settings/all').then(settings => protectedSessionTimeout = settings.protected_session_timeout); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| function setProtectedSessionTimeout(encSessTimeout) { |  | ||||||
|     protectedSessionTimeout = encSessTimeout; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function ensureProtectedSession(requireProtectedSession, modal) { | function ensureProtectedSession(requireProtectedSession, modal) { | ||||||
|     const dfd = $.Deferred(); |     const dfd = $.Deferred(); | ||||||
|  |  | ||||||
|     if (requireProtectedSession && !isProtectedSessionAvailable()) { |     if (requireProtectedSession && !protectedSessionHolder.isProtectedSessionAvailable()) { | ||||||
|         protectedSessionDeferred = dfd; |         protectedSessionDeferred = dfd; | ||||||
|  |  | ||||||
|         if (treeService.getCurrentNode().data.isProtected) { |         if (treeService.getCurrentNode().data.isProtected) { | ||||||
| @@ -62,7 +52,7 @@ async function setupProtectedSession() { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protectedSessionId = response.protectedSessionId; |     protectedSessionHolder.setProtectedSessionId(response.protectedSessionId); | ||||||
|  |  | ||||||
|     $dialog.dialog("close"); |     $dialog.dialog("close"); | ||||||
|  |  | ||||||
| @@ -96,22 +86,6 @@ async function enterProtectedSession(password) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function getProtectedSessionId() { |  | ||||||
|     return protectedSessionId; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function resetProtectedSession() { |  | ||||||
|     protectedSessionId = null; |  | ||||||
|  |  | ||||||
|     // most secure solution - guarantees nothing remained in memory |  | ||||||
|     // since this expires because user doesn't use the app, it shouldn't be disruptive |  | ||||||
|     utils.reloadApp(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function isProtectedSessionAvailable() { |  | ||||||
|     return protectedSessionId !== null; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function protectNoteAndSendToServer() { | async function protectNoteAndSendToServer() { | ||||||
|     await ensureProtectedSession(true, true); |     await ensureProtectedSession(true, true); | ||||||
|  |  | ||||||
| @@ -144,12 +118,6 @@ async function unprotectNoteAndSendToServer() { | |||||||
|     noteDetail.setNoteBackgroundIfProtected(note); |     noteDetail.setNoteBackgroundIfProtected(note); | ||||||
| } | } | ||||||
|  |  | ||||||
| function touchProtectedSession() { |  | ||||||
|     if (isProtectedSessionAvailable()) { |  | ||||||
|         lastProtectedSessionOperationDate = new Date(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function protectSubTree(noteId, protect) { | async function protectSubTree(noteId, protect) { | ||||||
|     await ensureProtectedSession(true, true); |     await ensureProtectedSession(true, true); | ||||||
|  |  | ||||||
| @@ -167,24 +135,13 @@ $passwordForm.submit(() => { | |||||||
|     return false; |     return false; | ||||||
| }); | }); | ||||||
|  |  | ||||||
| setInterval(() => { |  | ||||||
|     if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) { |  | ||||||
|         resetProtectedSession(); |  | ||||||
|     } |  | ||||||
| }, 5000); |  | ||||||
|  |  | ||||||
| $protectButton.click(protectNoteAndSendToServer); | $protectButton.click(protectNoteAndSendToServer); | ||||||
| $unprotectButton.click(unprotectNoteAndSendToServer); | $unprotectButton.click(unprotectNoteAndSendToServer); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     setProtectedSessionTimeout, |  | ||||||
|     ensureProtectedSession, |     ensureProtectedSession, | ||||||
|     resetProtectedSession, |  | ||||||
|     isProtectedSessionAvailable, |  | ||||||
|     protectNoteAndSendToServer, |     protectNoteAndSendToServer, | ||||||
|     unprotectNoteAndSendToServer, |     unprotectNoteAndSendToServer, | ||||||
|     getProtectedSessionId, |  | ||||||
|     touchProtectedSession, |  | ||||||
|     protectSubTree, |     protectSubTree, | ||||||
|     ensureDialogIsClosed |     ensureDialogIsClosed | ||||||
| }; | }; | ||||||
							
								
								
									
										55
									
								
								src/public/javascripts/services/protected_session_holder.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/public/javascripts/services/protected_session_holder.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | |||||||
|  | import utils from "./utils.js"; | ||||||
|  | import server from "./server.js"; | ||||||
|  |  | ||||||
|  | let lastProtectedSessionOperationDate = null; | ||||||
|  | let protectedSessionTimeout = null; | ||||||
|  | let protectedSessionId = null; | ||||||
|  |  | ||||||
|  | $(document).ready(() => { | ||||||
|  |     server.get('settings/all').then(settings => protectedSessionTimeout = settings.protected_session_timeout); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | setInterval(() => { | ||||||
|  |     if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) { | ||||||
|  |         resetProtectedSession(); | ||||||
|  |     } | ||||||
|  | }, 5000); | ||||||
|  |  | ||||||
|  | function setProtectedSessionTimeout(encSessTimeout) { | ||||||
|  |     protectedSessionTimeout = encSessTimeout; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function getProtectedSessionId() { | ||||||
|  |     return protectedSessionId; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function setProtectedSessionId(id) { | ||||||
|  |     protectedSessionId = id; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function resetProtectedSession() { | ||||||
|  |     protectedSessionId = null; | ||||||
|  |  | ||||||
|  |     // most secure solution - guarantees nothing remained in memory | ||||||
|  |     // since this expires because user doesn't use the app, it shouldn't be disruptive | ||||||
|  |     utils.reloadApp(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function isProtectedSessionAvailable() { | ||||||
|  |     return protectedSessionId !== null; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function touchProtectedSession() { | ||||||
|  |     if (isProtectedSessionAvailable()) { | ||||||
|  |         lastProtectedSessionOperationDate = new Date(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     getProtectedSessionId, | ||||||
|  |     setProtectedSessionId, | ||||||
|  |     resetProtectedSession, | ||||||
|  |     isProtectedSessionAvailable, | ||||||
|  |     setProtectedSessionTimeout, | ||||||
|  |     touchProtectedSession | ||||||
|  | }; | ||||||
| @@ -1,11 +1,11 @@ | |||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
|  |  | ||||||
| function getHeaders() { | function getHeaders() { | ||||||
|     let protectedSessionId = null; |     let protectedSessionId = null; | ||||||
|  |  | ||||||
|     try { // this is because protected session might not be declared in some cases - like when it's included in migration page |     try { // this is because protected session might not be declared in some cases - like when it's included in migration page | ||||||
|         protectedSessionId = protectedSessionService.getProtectedSessionId(); |         protectedSessionId = protectedSessionHolder.getProtectedSessionId(); | ||||||
|     } |     } | ||||||
|     catch(e) {} |     catch(e) {} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ import dragAndDropSetup from './drag_and_drop.js'; | |||||||
| import linkService from './link.js'; | import linkService from './link.js'; | ||||||
| import messagingService from './messaging.js'; | import messagingService from './messaging.js'; | ||||||
| import noteDetailService from './note_detail.js'; | import noteDetailService from './note_detail.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import treeChangesService from './tree_changes.js'; | import treeChangesService from './tree_changes.js'; | ||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| @@ -777,7 +777,7 @@ async function createNote(node, parentNoteId, target, isProtected) { | |||||||
|  |  | ||||||
|     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted |     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted | ||||||
|     // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often |     // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often | ||||||
|     if (!isProtected || !protectedSessionService.isProtectedSessionAvailable()) { |     if (!isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) { | ||||||
|         isProtected = false; |         isProtected = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -857,6 +857,16 @@ async function getBranch(branchId) { | |||||||
|     return await treeCache.getBranch(branchId); |     return await treeCache.getBranch(branchId); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | messagingService.subscribeToMessages(syncData => { | ||||||
|  |     if (syncData.some(sync => sync.entityName === 'branches') | ||||||
|  |         || syncData.some(sync => sync.entityName === 'notes')) { | ||||||
|  |  | ||||||
|  |         console.log(utils.now(), "Reloading tree because of background changes"); | ||||||
|  |  | ||||||
|  |         reload(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| $(document).bind('keydown', 'ctrl+o', e => { | $(document).bind('keydown', 'ctrl+o', e => { | ||||||
|     const node = getCurrentNode(); |     const node = getCurrentNode(); | ||||||
|     const parentNoteId = node.data.parentNoteId; |     const parentNoteId = node.data.parentNoteId; | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
| //import messagingService from './messaging.js'; | import messagingService from './messaging.js'; | ||||||
| //import ScriptContext from './script_context.js'; |  | ||||||
|  |  | ||||||
| function reloadApp() { | function reloadApp() { | ||||||
|     window.location.reload(true); |     window.location.reload(true); | ||||||
| @@ -116,14 +115,6 @@ async function stopWatch(what, func) { | |||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function executeBundle(bundle) { |  | ||||||
|     const apiContext = ScriptContext(bundle.note, bundle.allNotes); |  | ||||||
|  |  | ||||||
|     return await (function () { |  | ||||||
|         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); |  | ||||||
|     }.call(apiContext)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function formatValueWithWhitespace(val) { | function formatValueWithWhitespace(val) { | ||||||
|     return /[^\w_-]/.test(val) ? '"' + val + '"' : val; |     return /[^\w_-]/.test(val) ? '"' + val + '"' : val; | ||||||
| } | } | ||||||
| @@ -263,7 +254,6 @@ export default { | |||||||
|     isRootNode, |     isRootNode, | ||||||
|     escapeHtml, |     escapeHtml, | ||||||
|     stopWatch, |     stopWatch, | ||||||
|     executeBundle, |  | ||||||
|     formatValueWithWhitespace, |     formatValueWithWhitespace, | ||||||
|     formatLabel, |     formatLabel, | ||||||
|     requireLibrary, |     requireLibrary, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user