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, { import GithubClient, {
GetTreeResponseItem, GetTreeResponseItem,
NewTreeRequestItem, NewTreeRequestItem,
@ -262,12 +262,19 @@ export default class SyncManager {
return; return;
} }
const notice = new Notice("Syncing...");
this.syncing = true; this.syncing = true;
try { try {
await this.syncImpl(); await this.syncImpl();
} finally { // Shown only if sync doesn't fail
this.syncing = false; 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() { private async syncImpl() {