diff --git a/src/baseTypes.ts b/src/baseTypes.ts index e2c3ce4..72f24d7 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -56,6 +56,7 @@ export interface RemotelySavePluginSettings { currLogLevel?: string; vaultRandomID?: string; autoRunEveryMilliseconds?: number; + initRunAfterMilliseconds?: number; agreeToUploadExtraMetadata?: boolean; concurrency?: number; } diff --git a/src/main.ts b/src/main.ts index 5156a71..2b2a1a0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,6 +53,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { currLogLevel: "info", vaultRandomID: "", autoRunEveryMilliseconds: -1, + initRunAfterMilliseconds: -1, agreeToUploadExtraMetadata: false, concurrency: 5, }; @@ -65,7 +66,7 @@ interface OAuth2Info { revokeAuthSetting?: Setting; } -type SyncTriggerSourceType = "manual" | "auto" | "dry"; +type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit"; const iconNameSyncWait = `remotely-save-sync-wait`; const iconNameSyncRunning = `remotely-save-sync-running`; @@ -534,6 +535,9 @@ export default class RemotelySavePlugin extends Plugin { if (!this.settings.agreeToUploadExtraMetadata) { const syncAlgoV2Modal = new SyncAlgoV2Modal(this.app, this); syncAlgoV2Modal.open(); + } else { + this.enableAutoSyncIfSet(); + this.enableInitSyncIfSet(); } } @@ -662,11 +666,27 @@ export default class RemotelySavePlugin extends Plugin { this.settings.autoRunEveryMilliseconds !== null && this.settings.autoRunEveryMilliseconds > 0 ) { - const intervalID = window.setInterval(() => { - this.syncRun("auto"); - }, this.settings.autoRunEveryMilliseconds); - this.autoRunIntervalID = intervalID; - this.registerInterval(intervalID); + this.app.workspace.onLayoutReady(() => { + const intervalID = window.setInterval(() => { + this.syncRun("auto"); + }, this.settings.autoRunEveryMilliseconds); + this.autoRunIntervalID = intervalID; + this.registerInterval(intervalID); + }); + } + } + + enableInitSyncIfSet() { + if ( + this.settings.initRunAfterMilliseconds !== undefined && + this.settings.initRunAfterMilliseconds !== null && + this.settings.initRunAfterMilliseconds > 0 + ) { + this.app.workspace.onLayoutReady(() => { + window.setTimeout(() => { + this.syncRun("autoOnceInit"); + }, this.settings.initRunAfterMilliseconds); + }); } } diff --git a/src/settings.ts b/src/settings.ts index 97aa9f3..02dba14 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -521,6 +521,31 @@ export class RemotelySaveSettingTab extends PluginSettingTab { }); }); + const runOnceStartUpDiv = generalDiv.createEl("div"); + new Setting(runOnceStartUpDiv) + .setName("run once on start up automatically") + .setDesc( + `This settings allows setting running ONCE on start up automatically. This will take effect on NEXT start up after changing. This setting, is different from "schedule for auto run" which starts syncing after EVERY interval.` + ) + .addDropdown((dropdown) => { + dropdown.addOption("-1", "(not set)"); + dropdown.addOption( + `${1000 * 10 * 1}`, + "sync once after 10 seconds of start up" + ); + dropdown.addOption( + `${1000 * 30 * 1}`, + "sync once after 30 seconds of start up" + ); + dropdown + .setValue(`${this.plugin.settings.initRunAfterMilliseconds}`) + .onChange(async (val: string) => { + const realVal = parseInt(val); + this.plugin.settings.initRunAfterMilliseconds = realVal; + await this.plugin.saveSettings(); + }); + }); + const concurrencyDiv = generalDiv.createEl("div"); new Setting(concurrencyDiv) .setName("Concurrency") diff --git a/src/syncAlgoV2Notice.ts b/src/syncAlgoV2Notice.ts index 1133ca9..d0db1a9 100644 --- a/src/syncAlgoV2Notice.ts +++ b/src/syncAlgoV2Notice.ts @@ -60,6 +60,7 @@ export class SyncAlgoV2Modal extends Modal { log.info("agree to use the new algorithm"); this.plugin.saveAgreeToUseNewSyncAlgorithm(); this.plugin.enableAutoSyncIfSet(); + this.plugin.enableInitSyncIfSet(); } else { log.info("do not agree to use the new algorithm"); this.plugin.unload();