Fix first sync marked as done on failure

This commit is contained in:
Silvano Cerza 2025-04-20 11:48:06 +02:00
parent be547d8691
commit b2f3db6050
2 changed files with 15 additions and 10 deletions

View file

@ -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();
}

View file

@ -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() {