add sync once after start up

This commit is contained in:
fyears 2022-03-06 18:49:15 +08:00
parent 76e61b6ebf
commit 18cb8ba413
4 changed files with 53 additions and 6 deletions

View File

@ -56,6 +56,7 @@ export interface RemotelySavePluginSettings {
currLogLevel?: string; currLogLevel?: string;
vaultRandomID?: string; vaultRandomID?: string;
autoRunEveryMilliseconds?: number; autoRunEveryMilliseconds?: number;
initRunAfterMilliseconds?: number;
agreeToUploadExtraMetadata?: boolean; agreeToUploadExtraMetadata?: boolean;
concurrency?: number; concurrency?: number;
} }

View File

@ -53,6 +53,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
currLogLevel: "info", currLogLevel: "info",
vaultRandomID: "", vaultRandomID: "",
autoRunEveryMilliseconds: -1, autoRunEveryMilliseconds: -1,
initRunAfterMilliseconds: -1,
agreeToUploadExtraMetadata: false, agreeToUploadExtraMetadata: false,
concurrency: 5, concurrency: 5,
}; };
@ -65,7 +66,7 @@ interface OAuth2Info {
revokeAuthSetting?: Setting; revokeAuthSetting?: Setting;
} }
type SyncTriggerSourceType = "manual" | "auto" | "dry"; type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit";
const iconNameSyncWait = `remotely-save-sync-wait`; const iconNameSyncWait = `remotely-save-sync-wait`;
const iconNameSyncRunning = `remotely-save-sync-running`; const iconNameSyncRunning = `remotely-save-sync-running`;
@ -534,6 +535,9 @@ export default class RemotelySavePlugin extends Plugin {
if (!this.settings.agreeToUploadExtraMetadata) { if (!this.settings.agreeToUploadExtraMetadata) {
const syncAlgoV2Modal = new SyncAlgoV2Modal(this.app, this); const syncAlgoV2Modal = new SyncAlgoV2Modal(this.app, this);
syncAlgoV2Modal.open(); syncAlgoV2Modal.open();
} else {
this.enableAutoSyncIfSet();
this.enableInitSyncIfSet();
} }
} }
@ -662,11 +666,27 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.autoRunEveryMilliseconds !== null && this.settings.autoRunEveryMilliseconds !== null &&
this.settings.autoRunEveryMilliseconds > 0 this.settings.autoRunEveryMilliseconds > 0
) { ) {
this.app.workspace.onLayoutReady(() => {
const intervalID = window.setInterval(() => { const intervalID = window.setInterval(() => {
this.syncRun("auto"); this.syncRun("auto");
}, this.settings.autoRunEveryMilliseconds); }, this.settings.autoRunEveryMilliseconds);
this.autoRunIntervalID = intervalID; this.autoRunIntervalID = intervalID;
this.registerInterval(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);
});
} }
} }

View File

@ -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"); const concurrencyDiv = generalDiv.createEl("div");
new Setting(concurrencyDiv) new Setting(concurrencyDiv)
.setName("Concurrency") .setName("Concurrency")

View File

@ -60,6 +60,7 @@ export class SyncAlgoV2Modal extends Modal {
log.info("agree to use the new algorithm"); log.info("agree to use the new algorithm");
this.plugin.saveAgreeToUseNewSyncAlgorithm(); this.plugin.saveAgreeToUseNewSyncAlgorithm();
this.plugin.enableAutoSyncIfSet(); this.plugin.enableAutoSyncIfSet();
this.plugin.enableInitSyncIfSet();
} else { } else {
log.info("do not agree to use the new algorithm"); log.info("do not agree to use the new algorithm");
this.plugin.unload(); this.plugin.unload();