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/services/app_context.js b/src/public/app/services/app_context.js index 77e80e185..67787988a 100644 --- a/src/public/app/services/app_context.js +++ b/src/public/app/services/app_context.js @@ -101,12 +101,6 @@ class AppContext extends Component { return $(el).closest(".component").prop('component'); } - async protectedSessionStartedEvent() { - await treeCache.loadInitialTree(); - - this.triggerEvent('treeCacheReloaded'); - } - async openInNewWindow(notePath) { if (utils.isElectron()) { const {ipcRenderer} = utils.dynamicRequire('electron'); 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."); } 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}); }); } 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;