diff --git a/src/interface/obsidian/src/main.ts b/src/interface/obsidian/src/main.ts index a400da76..f5992061 100644 --- a/src/interface/obsidian/src/main.ts +++ b/src/interface/obsidian/src/main.ts @@ -49,11 +49,11 @@ export default class Khoj extends Plugin { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); // Load, configure khoj server settings - await configureKhojBackend(this.settings); + await configureKhojBackend(this.app.vault, this.settings); } async saveSettings() { - await configureKhojBackend(this.settings, false) + await configureKhojBackend(this.app.vault, this.settings, false) .then(() => this.saveData(this.settings)); } } diff --git a/src/interface/obsidian/src/modal.ts b/src/interface/obsidian/src/modal.ts index d44da44a..f0ded644 100644 --- a/src/interface/obsidian/src/modal.ts +++ b/src/interface/obsidian/src/modal.ts @@ -10,9 +10,11 @@ export class KhojModal extends SuggestModal { setting: KhojSetting; rerank: boolean = false; find_similar_notes: boolean; + app: App; constructor(app: App, setting: KhojSetting, find_similar_notes: boolean = false) { super(app); + this.app = app; this.setting = setting; this.find_similar_notes = find_similar_notes; diff --git a/src/interface/obsidian/src/utils.ts b/src/interface/obsidian/src/utils.ts index bc3ec598..b8142f6d 100644 --- a/src/interface/obsidian/src/utils.ts +++ b/src/interface/obsidian/src/utils.ts @@ -1,16 +1,16 @@ -import { FileSystemAdapter, Notice, RequestUrlParam, request } from 'obsidian'; +import { FileSystemAdapter, Notice, RequestUrlParam, request, Vault } from 'obsidian'; import { KhojSetting } from 'src/settings' -export function getVaultAbsolutePath(): string { - let adaptor = this.app.vault.adapter; +export function getVaultAbsolutePath(vault: Vault): string { + let adaptor = vault.adapter; if (adaptor instanceof FileSystemAdapter) { return adaptor.getBasePath(); } return ''; } -export async function configureKhojBackend(setting: KhojSetting, notify: boolean = true) { - let mdInVault = `${getVaultAbsolutePath()}/**/*.md`; +export async function configureKhojBackend(vault: Vault, setting: KhojSetting, notify: boolean = true) { + let mdInVault = `${getVaultAbsolutePath(vault)}/**/*.md`; let khojConfigUrl = `${setting.khojUrl}/api/config/data`; // Check if khoj backend is configured, note if cannot connect to backend @@ -28,7 +28,7 @@ export async function configureKhojBackend(setting: KhojSetting, notify: boolean if (!setting.connectedToBackend) return; // Set index name from the path of the current vault - let indexName = getVaultAbsolutePath().replace(/\//g, '_').replace(/ /g, '_'); + let indexName = getVaultAbsolutePath(vault).replace(/\//g, '_').replace(/ /g, '_'); // Get default index directory from khoj backend let khojDefaultIndexDirectory = await request(`${khojConfigUrl}/default`) .then(response => JSON.parse(response))