Skip to content

Build your personal knowledge base with Trilium Notes

options now allow selecting user theme

zadam67630b1a221c
diff --git a/src/public/javascripts/dialogs/options.js b/src/public/javascripts/dialogs/options.js
index 8940dce6c2..c84bb30744 100644
--- a/src/public/javascripts/dialogs/options.js
+++ b/src/public/javascripts/dialogs/options.js
@@ -5,6 +5,7 @@ import server from '../services/server.js';
import infoService from "../services/info.js";
import zoomService from "../services/zoom.js";
import utils from "../services/utils.js";
+import cssLoader from "../services/css_loader.js";
const $dialog = $("#options-dialog");
@@ -50,7 +51,22 @@ addTabHandler((function() {
const $body = $("body");
const $container = $("#container");
- function optionsLoaded(options) {
+ async function optionsLoaded(options) {
+ const themes = [
+ { val: 'white', title: 'White' },
+ { val: 'dark', title: 'Dark' },
+ { val: 'black', title: 'Black' }
+ ].concat(await server.get('options/user-themes'));
+
+ $themeSelect.empty();
+
+ for (const theme of themes) {
+ $themeSelect.append($("<option>")
+ .attr("value", theme.val)
+ .attr("data-note-id", theme.noteId)
+ .html(theme.title));
+ }
+
$themeSelect.val(options.theme);
if (utils.isElectron()) {
@@ -77,6 +93,14 @@ addTabHandler((function() {
}
}
+ const noteId = $(this).find(":selected").attr("data-note-id");
+
+ if (noteId) {
+ // make sure the CSS is loaded
+ // if the CSS has been loaded and then updated then the changes won't take effect though
+ cssLoader.requireCss(`/api/notes/${noteId}/download`);
+ }
+
$body.addClass("theme-" + newTheme);
server.put('options/theme/' + newTheme);
diff --git a/src/routes/api/options.js b/src/routes/api/options.js
index fd630ec182..98f9ab0017 100644
--- a/src/routes/api/options.js
+++ b/src/routes/api/options.js
@@ -1,8 +1,8 @@
"use strict";
-const sql = require('../../services/sql');
const optionService = require('../../services/options');
const log = require('../../services/log');
+const attributes = require('../../services/attributes');
// options allowed to be updated directly in options dialog
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval',
@@ -42,8 +42,20 @@ async function update(name, value) {
return true;
}
+async function getUserThemes() {
+ return (await attributes.getNotesWithLabel('appTheme'))
+ .map(note => {
+ return {
+ val: note.title,
+ title: note.title,
+ noteId: note.noteId
+ };
+ });
+}
+
module.exports = {
getOptions,
updateOption,
- updateOptions
+ updateOptions,
+ getUserThemes
};
\ No newline at end of file
diff --git a/src/routes/routes.js b/src/routes/routes.js
index a34da2047c..22c96f7a19 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -153,6 +153,7 @@ function register(app) {
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
apiRoute(PUT, '/api/options/:name/:value*', optionsApiRoute.updateOption);
apiRoute(PUT, '/api/options', optionsApiRoute.updateOptions);
+ apiRoute(GET, '/api/options/user-themes', optionsApiRoute.getUserThemes);
apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword);
diff --git a/src/services/attributes.js b/src/services/attributes.js
index e0fc547cdf..f4465b65ac 100644
--- a/src/services/attributes.js
+++ b/src/services/attributes.js
@@ -15,6 +15,7 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'manualTransactionHandling' },
{ type: 'label', name: 'disableInclusion' },
{ type: 'label', name: 'appCss' },
+ { type: 'label', name: 'appTheme' },
{ type: 'label', name: 'hideChildrenOverview' },
{ type: 'label', name: 'hidePromotedAttributes' },
{ type: 'label', name: 'readOnly' },
diff --git a/src/views/dialogs/options.ejs b/src/views/dialogs/options.ejs
index b280a5133f..bd0c537ea7 100644
--- a/src/views/dialogs/options.ejs
+++ b/src/views/dialogs/options.ejs
@@ -40,11 +40,7 @@
<form>
<div class="form-group">
<label for="theme-select">Theme</label>
- <select class="form-control" id="theme-select">
- <option value="white">White</option>
- <option value="dark">Dark</option>
- <option value="black">Black</option>
- </select>
+ <select class="form-control" id="theme-select"></select>
</div>
<div class="form-group">