Skip to content

Commit 31c4eba

Browse files
committed
fix: 🐛 auto-sync on startup
Validate the token before attempting auto-sync on startup, and only run auto-sync if a token is set. FIXES #59
1 parent bee8fc0 commit 31c4eba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ export default class ReadwiseMirror extends Plugin {
633633
} else {
634634
this._readwiseApi = new ReadwiseApi(this.settings.apiToken, this.notify, this._logger);
635635

636+
this.logger.info('Validating Readwise token ...');
637+
this._readwiseApi.validateToken().then((isValid) => {
638+
if (isValid && this.settings.autoSync) {
639+
this.notify.notice('Readwise: Run auto sync on startup');
640+
this.sync();
641+
}
642+
});
643+
636644
if (this.settings.lastUpdated)
637645
this.notify.setStatusBarText(`Readwise: Updated ${this.lastUpdatedHumanReadableFormat()}`);
638646
else this.notify.setStatusBarText('Readwise: Click to Sync');
@@ -694,8 +702,6 @@ export default class ReadwiseMirror extends Plugin {
694702
);
695703

696704
this.addSettingTab(new ReadwiseMirrorSettingTab(this.app, this, this.notify, this.frontmatterManager));
697-
698-
if (this.settings.autoSync) this.sync();
699705
}
700706

701707
async loadSettings() {

0 commit comments

Comments
 (0)