From a4dcb20622249cd7fa4c3b2a2004d86c6defe2c9 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 13 Feb 2023 19:53:06 -0600 Subject: [PATCH] Add setting to toggle auto configuring of khoj backend from Obsidian - By default the obsidian plugin automatically configures the khoj backend to index the current vault - For more complex scenarios, users can manage their ~/.khoj/khoj.yml manually by toggling the auto-configure setting off in the khoj plugin settings Resolves #156 --- src/interface/obsidian/src/main.ts | 14 +++++++++----- src/interface/obsidian/src/settings.ts | 11 +++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/interface/obsidian/src/main.ts b/src/interface/obsidian/src/main.ts index f5992061..b367037c 100644 --- a/src/interface/obsidian/src/main.ts +++ b/src/interface/obsidian/src/main.ts @@ -48,12 +48,16 @@ export default class Khoj extends Plugin { // Load khoj obsidian plugin settings this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); - // Load, configure khoj server settings - await configureKhojBackend(this.app.vault, this.settings); + if (this.settings.autoConfigure) { + // Load, configure khoj server settings + await configureKhojBackend(this.app.vault, this.settings); + } } async saveSettings() { - await configureKhojBackend(this.app.vault, this.settings, false) - .then(() => this.saveData(this.settings)); - } + if (this.settings.autoConfigure) { + await configureKhojBackend(this.app.vault, this.settings, false); + } + this.saveData(this.settings); + } } diff --git a/src/interface/obsidian/src/settings.ts b/src/interface/obsidian/src/settings.ts index 20bb7863..d7f41ba7 100644 --- a/src/interface/obsidian/src/settings.ts +++ b/src/interface/obsidian/src/settings.ts @@ -5,12 +5,14 @@ export interface KhojSetting { resultsCount: number; khojUrl: string; connectedToBackend: boolean; + autoConfigure: boolean; } export const DEFAULT_SETTINGS: KhojSetting = { resultsCount: 6, khojUrl: 'http://localhost:8000', connectedToBackend: false, + autoConfigure: true, } export class KhojSettingTab extends PluginSettingTab { @@ -50,6 +52,15 @@ export class KhojSettingTab extends PluginSettingTab { this.plugin.settings.resultsCount = value; await this.plugin.saveSettings(); })); + new Setting(containerEl) + .setName('Auto Configure') + .setDesc('Automatically configure the Khoj backend') + .addToggle(toggle => toggle + .setValue(this.plugin.settings.autoConfigure) + .onChange(async (value) => { + this.plugin.settings.autoConfigure = value; + await this.plugin.saveSettings(); + })); let indexVaultSetting = new Setting(containerEl); indexVaultSetting .setName('Index Vault')