mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Pass app object from plugin instance to child objects and functions
Do not reference global app object from child objects and funcs directly. It is only available for debugging purposes and access to it maybe dropped in the future.
This commit is contained in:
parent
c203c6a3fd
commit
4070be637c
3 changed files with 10 additions and 8 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ export class KhojModal extends SuggestModal<SearchResult> {
|
|||
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;
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue