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
This commit is contained in:
Debanjum Singh Solanky
2023-02-13 19:53:06 -06:00
parent 24aa696ef5
commit a4dcb20622
2 changed files with 20 additions and 5 deletions

View File

@@ -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);
}
}

View File

@@ -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')