Skip to content

Build your personal knowledge base with Trilium Notes

add switch to manually enter/leave protected session, fixes #107

azivner5dde2752d248
diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js
index 8af5b838a5..515ca64a91 100644
--- a/src/public/javascripts/services/entrypoints.js
+++ b/src/public/javascripts/services/entrypoints.js
@@ -12,6 +12,7 @@ import recentChangesDialog from "../dialogs/recent_changes.js";
import sqlConsoleDialog from "../dialogs/sql_console.js";
import searchTreeService from "./search_tree.js";
import labelsDialog from "../dialogs/labels.js";
+import protectedSessionService from "./protected_session.js";
function registerEntrypoints() {
// hot keys are active also inside inputs and content editables
@@ -31,6 +32,9 @@ function registerEntrypoints() {
$("#recent-changes-button").click(recentChangesDialog.showDialog);
+ $("#protected-session-on").click(protectedSessionService.enterProtectedSession);
+ $("#protected-session-off").click(protectedSessionService.leaveProtectedSession);
+
$("#recent-notes-button").click(recentNotesDialog.showDialog);
utils.bindShortcut('ctrl+e', recentNotesDialog.showDialog);
diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js
index 399742250d..b316953473 100644
--- a/src/public/javascripts/services/protected_session.js
+++ b/src/public/javascripts/services/protected_session.js
@@ -11,9 +11,23 @@ const $password = $("#protected-session-password");
const $noteDetailWrapper = $("#note-detail-wrapper");
const $protectButton = $("#protect-button");
const $unprotectButton = $("#unprotect-button");
+const $protectedSessionOnButton = $("#protected-session-on");
+const $protectedSessionOffButton = $("#protected-session-off");
let protectedSessionDeferred = null;
+async function enterProtectedSession() {
+ if (!protectedSessionHolder.isProtectedSessionAvailable()) {
+ await ensureProtectedSession(true, true);
+ }
+}
+
+async function leaveProtectedSession() {
+ if (protectedSessionHolder.isProtectedSessionAvailable()) {
+ utils.reloadApp();
+ }
+}
+
function ensureProtectedSession(requireProtectedSession, modal) {
const dfd = $.Deferred();
@@ -46,7 +60,7 @@ async function setupProtectedSession() {
const password = $password.val();
$password.val("");
- const response = await enterProtectedSession(password);
+ const response = await enterProtectedSessionOnServer(password);
if (!response.success) {
infoService.showError("Wrong password.");
@@ -67,6 +81,9 @@ async function setupProtectedSession() {
protectedSessionDeferred.resolve();
+ $protectedSessionOnButton.addClass('active');
+ $protectedSessionOffButton.removeClass('active');
+
protectedSessionDeferred = null;
}
}
@@ -81,7 +98,7 @@ function ensureDialogIsClosed() {
$password.val('');
}
-async function enterProtectedSession(password) {
+async function enterProtectedSessionOnServer(password) {
return await server.post('login/protected', {
password: password
});
@@ -138,5 +155,7 @@ export default {
protectNoteAndSendToServer,
unprotectNoteAndSendToServer,
protectBranch,
- ensureDialogIsClosed
+ ensureDialogIsClosed,
+ enterProtectedSession,
+ leaveProtectedSession
};
\ No newline at end of file
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index e48fcf11fc..a0bd5f0615 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -371,4 +371,12 @@ div.ui-tooltip {
#history-navigation {
margin: 0 20px 0 5px;
display: flex;
+}
+
+.btn {
+ border-color: #ddd;
+}
+
+.btn.active {
+ background-color: #ddd;
}
\ No newline at end of file
diff --git a/src/views/index.ejs b/src/views/index.ejs
index 7c5f0681e9..41a18a38aa 100644
--- a/src/views/index.ejs
+++ b/src/views/index.ejs
@@ -23,10 +23,18 @@
style="background: url('/images/icons/forward.png')"></a>
</div>
- <div style="flex-grow: 100;">
+ <div style="flex-grow: 100; display: flex;">
<button class="btn btn-xs" id="jump-to-note-button" title="CTRL+J">Jump to note</button>
<button class="btn btn-xs" id="recent-notes-button" title="CTRL+E">Recent notes</button>
<button class="btn btn-xs" id="recent-changes-button">Recent changes</button>
+ <div>
+ <span style="font-size: smaller">Protected session:</span>
+
+ <div class="btn-group btn-group-xs">
+ <button type="button" class="btn" id="protected-session-on">On</button>
+ <button type="button" class="btn active" id="protected-session-off">Off</button>
+ </div>
+ </div>
</div>
<div id="plugin-buttons">