Skip to content

Commit 2b17138

Browse files
committed
added setting to disable js view fields
1 parent 8398e4a commit 2b17138

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-meta-bind-plugin",
33
"name": "Meta Bind Plugin",
4-
"version": "0.5.0",
4+
"version": "0.5.1",
55
"minAppVersion": "0.14.0",
66
"description": "This plugin can create input fields inside your notes and bind them to metadata fields.",
77
"author": "Moritz Jung",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-meta-bind-plugin",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "This plugin can create input fields inside your notes and bind them to metadata fields.",
55
"main": "main.js",
66
"scripts": {

src/renderChildren/JsViewFieldMDRC.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MetaBindPlugin from '../main';
2-
import { ErrorLevel, MetaBindExpressionError } from '../utils/errors/MetaBindErrors';
2+
import { ErrorLevel, MetaBindExpressionError, MetaBindJsError } from '../utils/errors/MetaBindErrors';
33
import { Listener, Signal } from '../utils/Signal';
44
import { RenderChildType } from './InputFieldMDRC';
55
import { JsViewFieldDeclaration } from '../parsers/ViewFieldDeclarationParser';
@@ -82,10 +82,10 @@ export class JsViewFieldMDRC extends AbstractViewFieldMDRC {
8282

8383
async evaluateExpression(): Promise<string> {
8484
if (!this.expression) {
85-
throw new Error("Can't evaluate expression. Expression is undefined.");
85+
throw new MetaBindJsError(ErrorLevel.CRITICAL, "Can't evaluate expression.", 'Expression is undefined.');
8686
}
87-
if (!(this.plugin instanceof MetaBindPlugin)) {
88-
throw new Error("Can't evaluate expression. JS expressions are unsupported outside of obsidian.");
87+
if (!this.plugin.settings.enableJs) {
88+
throw new MetaBindJsError(ErrorLevel.CRITICAL, "Can't evaluate expression.", 'JS expressions are disabled in the plugin settings.');
8989
}
9090

9191
const context = this.buildContext();

src/settings/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface MetaBindPluginSettings {
5353
syncInterval: number;
5454
maxSyncInterval: number;
5555
minSyncInterval: number;
56+
enableJs: boolean;
5657

5758
inputTemplates: string;
5859
}
@@ -66,6 +67,7 @@ export const DEFAULT_SETTINGS: MetaBindPluginSettings = {
6667
syncInterval: 200,
6768
minSyncInterval: 50,
6869
maxSyncInterval: 1000,
70+
enableJs: false,
6971

7072
inputTemplates: '',
7173
};

src/settings/SettingsTab.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ export class MetaBindSettingTab extends PluginSettingTab {
103103
});
104104
});
105105

106+
new Setting(containerEl)
107+
.setName('Enable JS Input Fields')
108+
.setDesc("Enable the processing of JavaScript input fields. This is potentially DANGEROUS, thus it's disabled by default. RESTART REQUIRED.")
109+
.addToggle(cb => {
110+
cb.setValue(this.plugin.settings.enableJs);
111+
cb.onChange(data => {
112+
this.plugin.settings.enableJs = data;
113+
this.plugin.saveSettings();
114+
});
115+
});
116+
106117
new Setting(containerEl)
107118
.setName('Disable Code Block Restrictions')
108119
.setDesc('Disable restrictions on which input fields can be created in which code blocks. Not recommended unless you know what you are doing.')

0 commit comments

Comments
 (0)