From e1e185e5dbe2ce6c6a4def0483dbd8a55acbd049 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 15 Jan 2021 20:12:14 +0100 Subject: [PATCH] added "safe mode" environment variable switch which disables startup scripts and resets tabs --- src/public/app/widgets/note_type.js | 3 +++ src/routes/api/script.js | 14 ++++++++++++-- src/services/options_init.js | 4 ++-- src/services/scheduler.js | 8 +++++--- src/services/script.js | 1 - 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/public/app/widgets/note_type.js b/src/public/app/widgets/note_type.js index 08dc943b0..efcfa84f4 100644 --- a/src/public/app/widgets/note_type.js +++ b/src/public/app/widgets/note_type.js @@ -41,6 +41,9 @@ export default class NoteTypeWidget extends TabAwareWidget { this.$noteTypeDropdown = this.$widget.find(".note-type-dropdown"); this.$noteTypeButton = this.$widget.find(".note-type-button"); this.$noteTypeDesc = this.$widget.find(".note-type-desc"); + + this.$widget.on('click', '.dropdown-item', + () => this.$widget.find('.dropdown-toggle').dropdown('toggle')); } async refreshWithNote(note) { diff --git a/src/routes/api/script.js b/src/routes/api/script.js index 53b6ca56c..5e1492a8d 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -54,11 +54,21 @@ function getBundlesWithLabel(label, value) { } function getStartupBundles() { - return getBundlesWithLabel("run", "frontendStartup"); + if (!process.env.TRILIUM_SAFE_MODE) { + return getBundlesWithLabel("run", "frontendStartup"); + } + else { + return []; + } } function getWidgetBundles() { - return getBundlesWithLabel("widget"); + if (!process.env.TRILIUM_SAFE_MODE) { + return getBundlesWithLabel("widget"); + } + else { + return []; + } } function getRelationBundles(req) { diff --git a/src/services/options_init.js b/src/services/options_init.js index 02dbc1ee2..7e66f524a 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -101,10 +101,10 @@ function initStartupOptions() { } } - if (process.env.TRILIUM_START_NOTE_ID) { + if (process.env.TRILIUM_START_NOTE_ID || process.env.TRILIUM_SAFE_MODE) { optionService.setOption('openTabs', JSON.stringify([ { - notePath: process.env.TRILIUM_START_NOTE_ID, + notePath: process.env.TRILIUM_START_NOTE_ID || 'root', active: true } ])); diff --git a/src/services/scheduler.js b/src/services/scheduler.js index 083343163..fffdc6152 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -22,9 +22,11 @@ function runNotesWithLabel(runAttrValue) { } sqlInit.dbReady.then(() => { - setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000); + if (!process.env.TRILIUM_SAFE_MODE) { + setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000); - setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000); + setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000); - setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000); + setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000); + } }); diff --git a/src/services/script.js b/src/services/script.js index eb9c92f83..6f34b9eaf 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,4 +1,3 @@ -const sql = require('./sql'); const ScriptContext = require('./script_context'); const repository = require('./repository'); const cls = require('./cls');