diff --git a/src/main.ts b/src/main.ts index 38270f1..34242f7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ import SyncChecker from './syncChecker'; export interface CronSettings { cronInterval: number; + runOnStartup: boolean watchObsidianSync: boolean crons: Array, locks: { [key: string]: CronLock } @@ -22,6 +23,7 @@ export interface CRONJob { const DEFAULT_SETTINGS: CronSettings = { cronInterval: 15, + runOnStartup: true, watchObsidianSync: true, crons: [], locks: {} @@ -48,6 +50,12 @@ export default class Cron extends Plugin { // load our cronjobs this.loadCrons() this.loadInterval() + + this.app.workspace.onLayoutReady(() => { + if(this.settings.runOnStartup) { + this.runCron() + } + }) } public async runCron() { diff --git a/src/settings.ts b/src/settings.ts index bf755dc..ce24e48 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -30,6 +30,17 @@ export default class CronSettingTab extends PluginSettingTab { }) ); + new Setting(containerEl) + .setName('Run cron on startup') + .setDesc('Do a cron run on startup instead of waiting for the first interval to pass') + .addToggle(toggle => toggle + .setValue(this.plugin.settings.runOnStartup) + .onChange(async (value) => { + this.plugin.settings.runOnStartup = value; + await this.plugin.saveSettings(); + }) + ); + new Setting(containerEl) .setName('Enable Obsidian Sync Checker') .setDesc('Whether or not to wait for Obsidian sync before running any CRONs globally.')