Add ability to do a run on Obsidian startup

This commit is contained in:
Callum Loh 2023-03-26 00:38:51 +00:00
parent 62e2ef6b7c
commit 32ecb73efc
2 changed files with 19 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import SyncChecker from './syncChecker';
export interface CronSettings {
cronInterval: number;
runOnStartup: boolean
watchObsidianSync: boolean
crons: Array<CRONJob>,
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() {

View file

@ -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.')