Update plugin notifications for errors and success

- Only show notification on plugin load and failure.
- In settings page, set current backend status at top of pane instead
  of showing notification
  Notices bubbles cluttered the UI while typing updates to settings
- Show notification once index updated via settings pane button click
  There was no notification on index updated, which usually takes time
  on the backend
This commit is contained in:
Debanjum Singh Solanky
2023-01-11 02:45:50 -03:00
parent 853192932a
commit 5af2b68e2b
3 changed files with 22 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ export function getVaultAbsolutePath(): string {
return '';
}
export async function configureKhojBackend(setting: KhojSetting) {
export async function configureKhojBackend(setting: KhojSetting, notify: boolean = true) {
let mdInVault = `${setting.obsidianVaultPath}/**/*.md`;
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
@@ -21,7 +21,8 @@ export async function configureKhojBackend(setting: KhojSetting) {
})
.catch(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}`);
if (notify)
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 (!setting.connectedToBackend) return;
@@ -79,10 +80,10 @@ export async function configureKhojBackend(setting: KhojSetting) {
updateKhojBackend(setting.khojUrl, data);
console.log(`Khoj: Updated markdown config in khoj backend config:\n${JSON.stringify(data["content-type"]["markdown"])}`)
}
new Notice(`✅ Successfully Setup Khoj`);
})
.catch(error => {
new Notice(`Failed to configure Khoj backend. Contact developer on Github.\n\nError: ${error}`);
if (notify)
new Notice(`Failed to configure Khoj backend. Contact developer on Github.\n\nError: ${error}`);
})
}