Track connectedToBackend as a setting. Use it across obsidian plugin

- Display warning at top of khoj obsidian plugin settings
- Make search command available only if connected to backend
- Show warning notice on clicking khoj search ribbon button

- Call saveData after configureKhojBackend to ensure
  connnectedToBackend setting saved after being (potentially) updated
  in configureKhojBackend function
This commit is contained in:
Debanjum Singh Solanky
2023-01-10 17:11:56 -03:00
parent 768e874185
commit f046a95f3d
3 changed files with 25 additions and 10 deletions

View File

@@ -16,13 +16,15 @@ export async function configureKhojBackend(setting: KhojSetting) {
// Check if khoj backend is configured, show error if backend is not running
let khoj_already_configured = await request(khojConfigUrl)
.then(response => {
setting.connectedToBackend = true;
return response !== "null"
})
.catch(error => {
new Notice(`Ensure Khoj backend is running and Khoj URL is pointing to it in the Khoj plugin settings.\n\n${error}`);
setting.connectedToBackend = false;
new Notice(`Ensure Khoj backend is running and Khoj URL is pointing to it in the plugin settings.\n\n${error}`);
})
// Short-circuit configuring khoj if unable to connect to khoj backend
if (khoj_already_configured === null) return;
if (!setting.connectedToBackend) return;
// Get current config if khoj backend configured, else get default config from khoj backend
await request(khoj_already_configured ? khojConfigUrl : `${khojConfigUrl}/default`)