From ac608b93344381668f8c479c244edd9d812a5bae Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 24 Apr 2020 21:21:22 +0200 Subject: [PATCH 1/3] small text changes --- .idea/vcs.xml | 1 + src/public/app/widgets/protected_note_switch.js | 4 ++-- src/routes/api/login.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1ddfb..8fe5bdbdc 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/src/public/app/widgets/protected_note_switch.js b/src/public/app/widgets/protected_note_switch.js index 4750bbefc..1a8c031f7 100644 --- a/src/public/app/widgets/protected_note_switch.js +++ b/src/public/app/widgets/protected_note_switch.js @@ -5,12 +5,12 @@ const TPL = `
`;``; diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 23d78807a..1c06305e0 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -27,7 +27,7 @@ async function loginSync(req) { // login token is valid for 5 minutes if (Math.abs(timestamp.getTime() - now.getTime()) > 5 * 60 * 1000) { - return [400, { message: 'Auth request time is out of sync' }]; + return [400, { message: 'Auth request time is out of sync, please check that both client and server have correct time.' }]; } const syncVersion = req.body.syncVersion; From 71d248cd876a2bf30059cf56b6bb65b9def9c13e Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 25 Apr 2020 11:09:07 +0200 Subject: [PATCH 2/3] touch protected session during note update --- package-lock.json | 2 +- src/public/app/services/protected_session_holder.js | 9 ++++++++- src/public/app/services/tab_context.js | 5 +---- src/public/app/widgets/basic_widget.js | 5 ++++- src/public/app/widgets/note_detail.js | 2 ++ src/public/app/widgets/note_title.js | 2 ++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index d0dee325c..dcb55a892 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.41.4-beta", + "version": "0.41.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/app/services/protected_session_holder.js b/src/public/app/services/protected_session_holder.js index 0c180e7fe..7f0dc2a7d 100644 --- a/src/public/app/services/protected_session_holder.js +++ b/src/public/app/services/protected_session_holder.js @@ -39,9 +39,16 @@ function touchProtectedSession() { } } +function touchProtectedSessionIfNecessary(note) { + if (note && note.isProtected && isProtectedSessionAvailable()) { + touchProtectedSession(); + } +} + export default { setProtectedSessionId, resetProtectedSession, isProtectedSessionAvailable, - touchProtectedSession + touchProtectedSession, + touchProtectedSessionIfNecessary }; \ No newline at end of file diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index b17df18fd..dec5ebf0c 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -69,10 +69,7 @@ class TabContext extends Component { } }, 5000); - if (this.note.isProtected && protectedSessionHolder.isProtectedSessionAvailable()) { - // FIXME: there are probably more places where this should be done - protectedSessionHolder.touchProtectedSession(); - } + protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); if (triggerSwitchEvent) { this.triggerEvent('tabNoteSwitched', { diff --git a/src/public/app/widgets/basic_widget.js b/src/public/app/widgets/basic_widget.js index 4b5a7dc34..06514edaa 100644 --- a/src/public/app/widgets/basic_widget.js +++ b/src/public/app/widgets/basic_widget.js @@ -57,7 +57,10 @@ class BasicWidget extends Component { for (const key in this.attrs) { if (key === 'style') { if (this.attrs[key]) { - $widget.attr(key, $widget.attr('style') + ';' + this.attrs[key]); + let style = $widget.attr('style'); + style = style ? `${style}; ${this.attrs[key]}` : this.attrs[key]; + + $widget.attr(key, style); } } else { diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index a973370cf..9523b7b84 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -61,6 +61,8 @@ export default class NoteDetailWidget extends TabAwareWidget { const dto = note.dto; dto.content = this.getTypeWidget().getContent(); + protectedSessionHolder.touchProtectedSessionIfNecessary(note); + await server.put('notes/' + noteId, dto, this.componentId); }); } diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index 074d01ca2..93eb840c3 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -29,6 +29,8 @@ export default class NoteTitleWidget extends TabAwareWidget { this.spacedUpdate = new SpacedUpdate(async () => { const title = this.$noteTitle.val(); + protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); + await server.put(`notes/${this.noteId}/change-title`, {title}); }); } From d1eacbb574e2215b101531f4b684882eed35529e Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 25 Apr 2020 17:15:57 +0200 Subject: [PATCH 3/3] more robust entering protected session and the following protection of a note --- src/public/app/services/app_context.js | 6 ------ src/public/app/services/protected_session.js | 12 +++++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/public/app/services/app_context.js b/src/public/app/services/app_context.js index 6dbcfa2db..f4537f087 100644 --- a/src/public/app/services/app_context.js +++ b/src/public/app/services/app_context.js @@ -94,12 +94,6 @@ class AppContext extends Component { getComponentByEl(el) { return $(el).closest(".component").prop('component'); } - - async protectedSessionStartedEvent() { - await treeCache.loadInitialTree(); - - this.triggerEvent('treeCacheReloaded'); - } } const appContext = new AppContext(); diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.js index 9e49de015..100df55e1 100644 --- a/src/public/app/services/protected_session.js +++ b/src/public/app/services/protected_session.js @@ -1,13 +1,10 @@ -import treeService from './tree.js'; import utils from './utils.js'; import server from './server.js'; import protectedSessionHolder from './protected_session_holder.js'; import toastService from "./toast.js"; import ws from "./ws.js"; import appContext from "./app_context.js"; - -const $enterProtectedSessionButton = $("#enter-protected-session-button"); -const $leaveProtectedSessionButton = $("#leave-protected-session-button"); +import treeCache from "./tree_cache.js"; let protectedSessionDeferred = null; @@ -45,6 +42,10 @@ async function setupProtectedSession(password) { protectedSessionHolder.setProtectedSessionId(response.protectedSessionId); protectedSessionHolder.touchProtectedSession(); + await treeCache.loadInitialTree(); + + await appContext.triggerEvent('treeCacheReloaded'); + appContext.triggerEvent('protectedSessionStarted'); if (protectedSessionDeferred !== null) { @@ -54,9 +55,6 @@ async function setupProtectedSession(password) { protectedSessionDeferred = null; } - $enterProtectedSessionButton.hide(); - $leaveProtectedSessionButton.show(); - toastService.showMessage("Protected session has been started."); }