diff --git a/src/main.ts b/src/main.ts index fa4d42f..ad1838a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; @@ -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(); + }); }); } diff --git a/src/utils/run-after-sync.ts b/src/utils/run-after-sync.ts new file mode 100644 index 0000000..ae139bc --- /dev/null +++ b/src/utils/run-after-sync.ts @@ -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; + } + }); +}