mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +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());
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||||
|
|
||||||
// Load, configure khoj server settings
|
// Load, configure khoj server settings
|
||||||
await configureKhojBackend(this.settings);
|
await configureKhojBackend(this.app.vault, this.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
await configureKhojBackend(this.settings, false)
|
await configureKhojBackend(this.app.vault, this.settings, false)
|
||||||
.then(() => this.saveData(this.settings));
|
.then(() => this.saveData(this.settings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,11 @@ export class KhojModal extends SuggestModal<SearchResult> {
|
||||||
setting: KhojSetting;
|
setting: KhojSetting;
|
||||||
rerank: boolean = false;
|
rerank: boolean = false;
|
||||||
find_similar_notes: boolean;
|
find_similar_notes: boolean;
|
||||||
|
app: App;
|
||||||
|
|
||||||
constructor(app: App, setting: KhojSetting, find_similar_notes: boolean = false) {
|
constructor(app: App, setting: KhojSetting, find_similar_notes: boolean = false) {
|
||||||
super(app);
|
super(app);
|
||||||
|
this.app = app;
|
||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
this.find_similar_notes = find_similar_notes;
|
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'
|
import { KhojSetting } from 'src/settings'
|
||||||
|
|
||||||
export function getVaultAbsolutePath(): string {
|
export function getVaultAbsolutePath(vault: Vault): string {
|
||||||
let adaptor = this.app.vault.adapter;
|
let adaptor = vault.adapter;
|
||||||
if (adaptor instanceof FileSystemAdapter) {
|
if (adaptor instanceof FileSystemAdapter) {
|
||||||
return adaptor.getBasePath();
|
return adaptor.getBasePath();
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function configureKhojBackend(setting: KhojSetting, notify: boolean = true) {
|
export async function configureKhojBackend(vault: Vault, setting: KhojSetting, notify: boolean = true) {
|
||||||
let mdInVault = `${getVaultAbsolutePath()}/**/*.md`;
|
let mdInVault = `${getVaultAbsolutePath(vault)}/**/*.md`;
|
||||||
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
|
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
|
||||||
|
|
||||||
// Check if khoj backend is configured, note if cannot connect to backend
|
// 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;
|
if (!setting.connectedToBackend) return;
|
||||||
|
|
||||||
// Set index name from the path of the current vault
|
// 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
|
// Get default index directory from khoj backend
|
||||||
let khojDefaultIndexDirectory = await request(`${khojConfigUrl}/default`)
|
let khojDefaultIndexDirectory = await request(`${khojConfigUrl}/default`)
|
||||||
.then(response => JSON.parse(response))
|
.then(response => JSON.parse(response))
|
||||||
|
|
Loading…
Reference in a new issue