From c0792c79e743cdda6f7debca612608b720064cc1 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Wed, 12 Feb 2025 18:34:55 +0100 Subject: [PATCH] Show notice on sync start, success and failure --- src/sync-manager.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sync-manager.ts b/src/sync-manager.ts index 440f137..a639ee9 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -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() {