Show notice on sync start, success and failure

This commit is contained in:
Silvano Cerza 2025-02-12 18:34:55 +01:00
parent 3f06dd4f90
commit c0792c79e7

View file

@ -1,4 +1,4 @@
import { Vault, normalizePath, base64ToArrayBuffer } from "obsidian";
import { Vault, Notice, normalizePath, base64ToArrayBuffer } from "obsidian";
import GithubClient, {
GetTreeResponseItem,
NewTreeRequestItem,
@ -262,12 +262,19 @@ export default class SyncManager {
return;
}
const notice = new Notice("Syncing...");
this.syncing = true;
try {
await this.syncImpl();
} finally {
this.syncing = false;
// Shown only if sync doesn't fail
new Notice("Sync successful", 5000);
} catch (err) {
// Show the error to the user, it's not automatically dismissed to make sure
// the user sees it.
new Notice(`Error syncing. ${err}`);
}
this.syncing = false;
notice.hide();
}
private async syncImpl() {