Skip to content

Commit

Permalink
only run auto run after sync in complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Feb 13, 2024
1 parent 0e10f82 commit e84c76a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./settings/settings";
import Core from "./core";
import { getJournalLink, navigateToJournalLink } from "./note-links";
import { runAfterSync } from "./utils/run-after-sync";

export default class AutoJournal extends Plugin {
settings: AutoJournalSettings;
Expand All @@ -19,8 +20,10 @@ export default class AutoJournal extends Plugin {

// Automatically run on startup if enabled
if (this.settings.automaticallyRun) {
this.app.workspace.onLayoutReady(() => {
this.run();
runAfterSync.call(this, () => {
this.app.workspace.onLayoutReady(() => {
this.run();
});
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/utils/run-after-sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let hasRun = false;

export function runAfterSync(callBack: any) {
const sync = this.app?.internalPlugins?.plugins?.sync?.instance;
if (!hasRun || !sync || sync.syncStatus?.toLowerCase() === "fully synced") {
callBack();
hasRun = true;
return;
}
sync.on("status-change", () => {
if (!hasRun && sync?.syncStatus?.toLowerCase() === "fully synced") {
callBack();
hasRun = true;
return;
}
});
}

0 comments on commit e84c76a

Please sign in to comment.