Issue 199 sync on save (#340)
* begin adding a sync on save option * get the main sync on save working * get settings sync on save working --------- Co-authored-by: Sam Purkis <sam.purkis@zimmerbiomet.com> Co-authored-by: fyears <1142836+fyears@users.noreply.github.com>
This commit is contained in:
co-authored by
Sam Purkis
fyears
parent
8d286a79a1
commit
19d5da3e45
+65
-2
@@ -831,8 +831,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
|
||||
dropdown
|
||||
.setValue(
|
||||
`${
|
||||
this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
||||
`${this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
||||
}`
|
||||
)
|
||||
.onChange(async (value) => {
|
||||
@@ -1517,6 +1516,67 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(basicDiv)
|
||||
.setName(t("settings_saverun"))
|
||||
.setDesc(t("settings_saverun_desc"))
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption("-1", t("settings_saverun_notset"));
|
||||
dropdown.addOption(`${1000 * 1}`, t("settings_saverun_1sec"));
|
||||
dropdown.addOption(`${1000 * 5}`, t("settings_saverun_5sec"));
|
||||
dropdown.addOption(`${1000 * 10}`, t("settings_saverun_10sec"));
|
||||
dropdown.addOption(`${1000 * 60}`, t("settings_saverun_1min"));
|
||||
let runScheduled = false
|
||||
dropdown
|
||||
.setValue(`${this.plugin.settings.syncOnSaveAfterMilliseconds}`)
|
||||
.onChange(async (val: string) => {
|
||||
const realVal = parseInt(val);
|
||||
this.plugin.settings.syncOnSaveAfterMilliseconds = realVal;
|
||||
await this.plugin.saveSettings();
|
||||
if (
|
||||
(realVal === undefined || realVal === null || realVal <= 0) &&
|
||||
this.plugin.syncOnSaveIntervalID !== undefined
|
||||
) {
|
||||
// clear
|
||||
window.clearInterval(this.plugin.syncOnSaveIntervalID);
|
||||
this.plugin.syncOnSaveIntervalID = undefined;
|
||||
} else if (
|
||||
realVal !== undefined &&
|
||||
realVal !== null &&
|
||||
realVal > 0
|
||||
) {
|
||||
const intervalID = window.setInterval(() => {
|
||||
const currentFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (currentFile) {
|
||||
// get the last modified time of the current file
|
||||
// if it has been modified within the last syncOnSaveAfterMilliseconds
|
||||
// then schedule a run for syncOnSaveAfterMilliseconds after it was modified
|
||||
const lastModified = currentFile.stat.mtime;
|
||||
const currentTime = Date.now();
|
||||
log.debug(
|
||||
`Checking if file was modified within last ${this.plugin.settings.syncOnSaveAfterMilliseconds / 1000} seconds, last modified: ${(currentTime - lastModified) / 1000} seconds ago`
|
||||
);
|
||||
if (currentTime - lastModified < this.plugin.settings.syncOnSaveAfterMilliseconds) {
|
||||
if (!runScheduled) {
|
||||
const scheduleTimeFromNow = this.plugin.settings.syncOnSaveAfterMilliseconds - (currentTime - lastModified)
|
||||
log.info(`schedule a run for ${scheduleTimeFromNow} milliseconds later`)
|
||||
runScheduled = true
|
||||
setTimeout(() => {
|
||||
this.plugin.syncRun("auto")
|
||||
runScheduled = false
|
||||
},
|
||||
scheduleTimeFromNow
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, realVal);
|
||||
this.plugin.syncOnSaveIntervalID = intervalID;
|
||||
this.plugin.registerInterval(intervalID);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(basicDiv)
|
||||
.setName(t("settings_autorun"))
|
||||
.setDesc(t("settings_autorun_desc"))
|
||||
@@ -1546,6 +1606,8 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
realVal > 0
|
||||
) {
|
||||
const intervalID = window.setInterval(() => {
|
||||
log.info("auto run from settings.ts");
|
||||
console.log("auto run from settings.ts");
|
||||
this.plugin.syncRun("auto");
|
||||
}, realVal);
|
||||
this.plugin.autoRunIntervalID = intervalID;
|
||||
@@ -1579,6 +1641,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(basicDiv)
|
||||
.setName(t("settings_skiplargefiles"))
|
||||
.setDesc(t("settings_skiplargefiles_desc"))
|
||||
|
||||
Reference in New Issue
Block a user