From b2f3db6050ad9746d7ce617daec98b3b0084989c Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Sun, 20 Apr 2025 11:48:06 +0200 Subject: [PATCH] Fix first sync marked as done on failure --- src/main.ts | 16 +++++++++++++--- src/sync-manager.ts | 9 ++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index e13dd68..bb43fb3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -152,9 +152,19 @@ export default class GitHubSyncPlugin extends Plugin { return; } if (this.settings.firstSync) { - await this.syncManager.firstSync(); - this.settings.firstSync = false; - this.saveSettings(); + const notice = new Notice("Syncing..."); + try { + await this.syncManager.firstSync(); + this.settings.firstSync = false; + this.saveSettings(); + // 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}`); + } + notice.hide(); } else { await this.syncManager.sync(); } diff --git a/src/sync-manager.ts b/src/sync-manager.ts index ffef47b..1fb1786 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -95,19 +95,14 @@ export default class SyncManager { return; } - const notice = new Notice("Syncing..."); this.syncing = true; try { await this.firstSyncImpl(); - // 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; + throw err; } this.syncing = false; - notice.hide(); } private async firstSyncImpl() {