tidy up the codes of sync on save
This commit is contained in:
parent
30f7c0058c
commit
a13cc8d5c1
@ -183,4 +183,9 @@ export const DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX =
|
|||||||
"sync_plans_hist_exported_on_";
|
"sync_plans_hist_exported_on_";
|
||||||
export const DEFAULT_LOG_HISTORY_FILE_PREFIX = "log_hist_exported_on_";
|
export const DEFAULT_LOG_HISTORY_FILE_PREFIX = "log_hist_exported_on_";
|
||||||
|
|
||||||
export type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit";
|
export type SyncTriggerSourceType =
|
||||||
|
| "manual"
|
||||||
|
| "auto"
|
||||||
|
| "dry"
|
||||||
|
| "autoOnceInit"
|
||||||
|
| "auto_sync_on_save";
|
||||||
|
|||||||
@ -103,19 +103,19 @@
|
|||||||
"settings_autorun_5min": "every 5 minutes",
|
"settings_autorun_5min": "every 5 minutes",
|
||||||
"settings_autorun_10min": "every 10 minutes",
|
"settings_autorun_10min": "every 10 minutes",
|
||||||
"settings_autorun_30min": "every 30 minutes",
|
"settings_autorun_30min": "every 30 minutes",
|
||||||
"settings_saverun": "Sync on Save",
|
|
||||||
"settings_saverun_desc": "The plugin tries to sync on after each file save. Battery may be impacted. (May need to restart after changing)",
|
|
||||||
"settings_saverun_notset": "(not set)",
|
|
||||||
"settings_saverun_1sec": "every 1 second",
|
|
||||||
"settings_saverun_5sec": "every 5 seconds",
|
|
||||||
"settings_saverun_10sec": "every 10 seconds",
|
|
||||||
"settings_saverun_1min": "every 1 minute",
|
|
||||||
"settings_runoncestartup": "Run Once On Start Up Automatically",
|
"settings_runoncestartup": "Run Once On Start Up Automatically",
|
||||||
"settings_runoncestartup_desc": "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.",
|
"settings_runoncestartup_desc": "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.",
|
||||||
"settings_runoncestartup_notset": "(not set)",
|
"settings_runoncestartup_notset": "(not set)",
|
||||||
"settings_runoncestartup_1sec": "sync once after 1 second of start up",
|
"settings_runoncestartup_1sec": "sync once after 1 second of start up",
|
||||||
"settings_runoncestartup_10sec": "sync once after 10 seconds of start up",
|
"settings_runoncestartup_10sec": "sync once after 10 seconds of start up",
|
||||||
"settings_runoncestartup_30sec": "sync once after 30 seconds of start up",
|
"settings_runoncestartup_30sec": "sync once after 30 seconds of start up",
|
||||||
|
"settings_saverun": "Sync On Save (experimental)",
|
||||||
|
"settings_saverun_desc": "A sync will be triggered if a file save action happened within a few seconds. Please pay attention that syncing is potentially a heavy action and battery may be impacted. (May need to reload the plugin or restart Obsidian after changing)",
|
||||||
|
"settings_saverun_notset": "(not set)",
|
||||||
|
"settings_saverun_1sec": "check every 1 second",
|
||||||
|
"settings_saverun_5sec": "check every 5 seconds",
|
||||||
|
"settings_saverun_10sec": "check every 10 seconds (recommended)",
|
||||||
|
"settings_saverun_1min": "check every 1 minute",
|
||||||
"settings_skiplargefiles": "Skip Large Files (experimental)",
|
"settings_skiplargefiles": "Skip Large Files (experimental)",
|
||||||
"settings_skiplargefiles_desc": "Skip files with sizes larger than the threshold. Here 1 MB = 10^6 bytes.",
|
"settings_skiplargefiles_desc": "Skip files with sizes larger than the threshold. Here 1 MB = 10^6 bytes.",
|
||||||
"settings_skiplargefiles_notset": "(not set)",
|
"settings_skiplargefiles_notset": "(not set)",
|
||||||
|
|||||||
@ -103,19 +103,19 @@
|
|||||||
"settings_autorun_5min": "每 5 分钟",
|
"settings_autorun_5min": "每 5 分钟",
|
||||||
"settings_autorun_10min": "每 10 分钟",
|
"settings_autorun_10min": "每 10 分钟",
|
||||||
"settings_autorun_30min": "每 30 分钟",
|
"settings_autorun_30min": "每 30 分钟",
|
||||||
"settings_saverun": "保存时同步",
|
|
||||||
"settings_saverun_desc": "插件在每次保存文件后尝试同步。电池可能会受到影响。",
|
|
||||||
"settings_saverun_notset": "(未设置)",
|
|
||||||
"settings_saverun_1sec": "每1秒",
|
|
||||||
"settings_saverun_5sec": "每5秒",
|
|
||||||
"settings_saverun_10sec": "每10秒",
|
|
||||||
"settings_saverun_1min": "每1分钟",
|
|
||||||
"settings_runoncestartup": "启动后自动运行一次",
|
"settings_runoncestartup": "启动后自动运行一次",
|
||||||
"settings_runoncestartup_desc": "本设置使得插件在程序启动后自动触发一次同步。修改后,会在下一次启动生效。本设置和“自动运行”是不同的,那个设置是指“每隔一段时间”都自动同步一次。",
|
"settings_runoncestartup_desc": "本设置使得插件在程序启动后自动触发一次同步。修改后,会在下一次启动生效。本设置和“自动运行”是不同的,那个设置是指“每隔一段时间”都自动同步一次。",
|
||||||
"settings_runoncestartup_notset": "(不设置)",
|
"settings_runoncestartup_notset": "(不设置)",
|
||||||
"settings_runoncestartup_1sec": "启动后第 1 秒运行一次",
|
"settings_runoncestartup_1sec": "启动后第 1 秒运行一次",
|
||||||
"settings_runoncestartup_10sec": "启动后第 10 秒运行一次",
|
"settings_runoncestartup_10sec": "启动后第 10 秒运行一次",
|
||||||
"settings_runoncestartup_30sec": "启动后第 30 秒运行一次",
|
"settings_runoncestartup_30sec": "启动后第 30 秒运行一次",
|
||||||
|
"settings_saverun": "保存时同步(实验性质)",
|
||||||
|
"settings_saverun_desc": "插件如果检查到当前文件在最近一段时间有修改保存过,则尝试同步。请注意,同步是一个很重的操作,因此会影响到耗电量。(修改设置后可能需要重载插件或重启。)",
|
||||||
|
"settings_saverun_notset": "(不设置)",
|
||||||
|
"settings_saverun_1sec": "隔 1 秒检查一次",
|
||||||
|
"settings_saverun_5sec": "隔 5 秒检查一次",
|
||||||
|
"settings_saverun_10sec": "隔 10 秒检查一次(推荐)",
|
||||||
|
"settings_saverun_1min": "隔 1 分钟检查一次",
|
||||||
"settings_skiplargefiles": "跳过大文件(实验性质)",
|
"settings_skiplargefiles": "跳过大文件(实验性质)",
|
||||||
"settings_skiplargefiles_desc": "跳过大于某一个阈值的文件。这里 1 MB = 10^6 bytes。",
|
"settings_skiplargefiles_desc": "跳过大于某一个阈值的文件。这里 1 MB = 10^6 bytes。",
|
||||||
"settings_skiplargefiles_notset": "(不设置)",
|
"settings_skiplargefiles_notset": "(不设置)",
|
||||||
|
|||||||
@ -103,19 +103,19 @@
|
|||||||
"settings_autorun_5min": "每 5 分鐘",
|
"settings_autorun_5min": "每 5 分鐘",
|
||||||
"settings_autorun_10min": "每 10 分鐘",
|
"settings_autorun_10min": "每 10 分鐘",
|
||||||
"settings_autorun_30min": "每 30 分鐘",
|
"settings_autorun_30min": "每 30 分鐘",
|
||||||
"settings_saverun": "保存時同步",
|
|
||||||
"settings_saverun_desc": "插件在每次保存文件後嘗試同步。電池可能會受到影響。",
|
|
||||||
"settings_saverun_notset": "(未設置)",
|
|
||||||
"settings_saverun_1sec": "每1秒",
|
|
||||||
"settings_saverun_5sec": "每5秒",
|
|
||||||
"settings_saverun_10sec": "每10秒",
|
|
||||||
"settings_saverun_1min": "每1分鐘",
|
|
||||||
"settings_runoncestartup": "啟動後自動執行一次",
|
"settings_runoncestartup": "啟動後自動執行一次",
|
||||||
"settings_runoncestartup_desc": "本設定使得外掛在程式啟動後自動觸發一次同步。修改後,會在下一次啟動生效。本設定和“自動執行”是不同的,那個設定是指“每隔一段時間”都自動同步一次。",
|
"settings_runoncestartup_desc": "本設定使得外掛在程式啟動後自動觸發一次同步。修改後,會在下一次啟動生效。本設定和“自動執行”是不同的,那個設定是指“每隔一段時間”都自動同步一次。",
|
||||||
"settings_runoncestartup_notset": "(不設定)",
|
"settings_runoncestartup_notset": "(不設定)",
|
||||||
"settings_runoncestartup_1sec": "啟動後第 1 秒執行一次",
|
"settings_runoncestartup_1sec": "啟動後第 1 秒執行一次",
|
||||||
"settings_runoncestartup_10sec": "啟動後第 10 秒執行一次",
|
"settings_runoncestartup_10sec": "啟動後第 10 秒執行一次",
|
||||||
"settings_runoncestartup_30sec": "啟動後第 30 秒執行一次",
|
"settings_runoncestartup_30sec": "啟動後第 30 秒執行一次",
|
||||||
|
"settings_saverun": "儲存時同步(實驗性質)",
|
||||||
|
"settings_saverun_desc": "外掛如果檢查到當前檔案在最近一段時間有修改儲存過,則嘗試同步。請注意,同步是一個很重的操作,因此會影響到耗電量。(修改設定後可能需要過載外掛或重啟。)",
|
||||||
|
"settings_saverun_notset": "(不設定)",
|
||||||
|
"settings_saverun_1sec": "隔 1 秒檢查一次",
|
||||||
|
"settings_saverun_5sec": "隔 5 秒檢查一次",
|
||||||
|
"settings_saverun_10sec": "隔 10 秒檢查一次(推薦)",
|
||||||
|
"settings_saverun_1min": "隔 1 分鐘檢查一次",
|
||||||
"settings_skiplargefiles": "跳過大檔案(實驗性質)",
|
"settings_skiplargefiles": "跳過大檔案(實驗性質)",
|
||||||
"settings_skiplargefiles_desc": "跳過大於某一個閾值的檔案。這裡 1 MB = 10^6 bytes。",
|
"settings_skiplargefiles_desc": "跳過大於某一個閾值的檔案。這裡 1 MB = 10^6 bytes。",
|
||||||
"settings_skiplargefiles_notset": "(不設定)",
|
"settings_skiplargefiles_notset": "(不設定)",
|
||||||
|
|||||||
100
src/main.ts
100
src/main.ts
@ -176,7 +176,8 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(
|
log.info(
|
||||||
`${this.manifest.id
|
`${
|
||||||
|
this.manifest.id
|
||||||
}-${Date.now()}: start sync, triggerSource=${triggerSource}`
|
}-${Date.now()}: start sync, triggerSource=${triggerSource}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -382,7 +383,8 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`${this.manifest.id
|
`${
|
||||||
|
this.manifest.id
|
||||||
}-${Date.now()}: finish sync, triggerSource=${triggerSource}`
|
}-${Date.now()}: finish sync, triggerSource=${triggerSource}`
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -864,6 +866,9 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
if (this.settings.enableStatusBarInfo === undefined) {
|
if (this.settings.enableStatusBarInfo === undefined) {
|
||||||
this.settings.enableStatusBarInfo = true;
|
this.settings.enableStatusBarInfo = true;
|
||||||
}
|
}
|
||||||
|
if (this.settings.syncOnSaveAfterMilliseconds === undefined) {
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkIfPresetRulesFollowed() {
|
async checkIfPresetRulesFollowed() {
|
||||||
@ -991,47 +996,6 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.vaultRandomID = vaultRandomID;
|
this.vaultRandomID = vaultRandomID;
|
||||||
}
|
}
|
||||||
|
|
||||||
enableSyncOnSaveIfSet() {
|
|
||||||
if (
|
|
||||||
this.settings.syncOnSaveAfterMilliseconds !== undefined &&
|
|
||||||
this.settings.syncOnSaveAfterMilliseconds !== null &&
|
|
||||||
this.settings.syncOnSaveAfterMilliseconds > 0
|
|
||||||
) {
|
|
||||||
let runScheduled = false;
|
|
||||||
this.app.workspace.onLayoutReady(() => {
|
|
||||||
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.settings.syncOnSaveAfterMilliseconds / 1000} seconds, last modified: ${(currentTime - lastModified) / 1000} seconds ago`
|
|
||||||
);
|
|
||||||
if (currentTime - lastModified < this.settings.syncOnSaveAfterMilliseconds) {
|
|
||||||
if (!runScheduled) {
|
|
||||||
const scheduleTimeFromNow = this.settings.syncOnSaveAfterMilliseconds - (currentTime - lastModified)
|
|
||||||
log.info(`schedule a run for ${scheduleTimeFromNow} milliseconds later`)
|
|
||||||
runScheduled = true
|
|
||||||
setTimeout(() => {
|
|
||||||
this.syncRun("auto")
|
|
||||||
runScheduled = false
|
|
||||||
},
|
|
||||||
scheduleTimeFromNow
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1_000);
|
|
||||||
this.syncOnSaveIntervalID = intervalID;
|
|
||||||
this.registerInterval(intervalID);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enableAutoSyncIfSet() {
|
enableAutoSyncIfSet() {
|
||||||
if (
|
if (
|
||||||
this.settings.autoRunEveryMilliseconds !== undefined &&
|
this.settings.autoRunEveryMilliseconds !== undefined &&
|
||||||
@ -1062,6 +1026,56 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableSyncOnSaveIfSet() {
|
||||||
|
if (
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds !== undefined &&
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds !== null &&
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds > 0
|
||||||
|
) {
|
||||||
|
let runScheduled = false;
|
||||||
|
this.app.workspace.onLayoutReady(() => {
|
||||||
|
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.settings.syncOnSaveAfterMilliseconds / 1000
|
||||||
|
// } seconds, last modified: ${
|
||||||
|
// (currentTime - lastModified) / 1000
|
||||||
|
// } seconds ago`
|
||||||
|
// );
|
||||||
|
if (
|
||||||
|
currentTime - lastModified <
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds
|
||||||
|
) {
|
||||||
|
if (!runScheduled) {
|
||||||
|
const scheduleTimeFromNow =
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds -
|
||||||
|
(currentTime - lastModified);
|
||||||
|
log.info(
|
||||||
|
`schedule a run for ${scheduleTimeFromNow} milliseconds later`
|
||||||
|
);
|
||||||
|
runScheduled = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.syncRun("auto_sync_on_save");
|
||||||
|
runScheduled = false;
|
||||||
|
}, scheduleTimeFromNow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this.settings.syncOnSaveAfterMilliseconds);
|
||||||
|
this.syncOnSaveIntervalID = intervalID;
|
||||||
|
this.registerInterval(intervalID);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async saveAgreeToUseNewSyncAlgorithm() {
|
async saveAgreeToUseNewSyncAlgorithm() {
|
||||||
this.settings.agreeToUploadExtraMetadata = true;
|
this.settings.agreeToUploadExtraMetadata = true;
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
|
|||||||
@ -21,7 +21,6 @@ export const applyLogWriterInplace = function (writer: (...msg: any[]) => any) {
|
|||||||
logLevel: LogLevelNumbers,
|
logLevel: LogLevelNumbers,
|
||||||
loggerName: string | symbol
|
loggerName: string | symbol
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
|
||||||
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
||||||
|
|
||||||
return function (...msg: any[]) {
|
return function (...msg: any[]) {
|
||||||
|
|||||||
135
src/settings.ts
135
src/settings.ts
@ -831,7 +831,8 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
|
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(
|
.setValue(
|
||||||
`${this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
`${
|
||||||
|
this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
@ -1516,67 +1517,6 @@ 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)
|
new Setting(basicDiv)
|
||||||
.setName(t("settings_autorun"))
|
.setName(t("settings_autorun"))
|
||||||
.setDesc(t("settings_autorun_desc"))
|
.setDesc(t("settings_autorun_desc"))
|
||||||
@ -1607,7 +1547,6 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
) {
|
) {
|
||||||
const intervalID = window.setInterval(() => {
|
const intervalID = window.setInterval(() => {
|
||||||
log.info("auto run from settings.ts");
|
log.info("auto run from settings.ts");
|
||||||
console.log("auto run from settings.ts");
|
|
||||||
this.plugin.syncRun("auto");
|
this.plugin.syncRun("auto");
|
||||||
}, realVal);
|
}, realVal);
|
||||||
this.plugin.autoRunIntervalID = intervalID;
|
this.plugin.autoRunIntervalID = intervalID;
|
||||||
@ -1642,6 +1581,76 @@ 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_sync_on_save");
|
||||||
|
runScheduled = false;
|
||||||
|
}, scheduleTimeFromNow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, realVal);
|
||||||
|
this.plugin.syncOnSaveIntervalID = intervalID;
|
||||||
|
this.plugin.registerInterval(intervalID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(basicDiv)
|
new Setting(basicDiv)
|
||||||
.setName(t("settings_skiplargefiles"))
|
.setName(t("settings_skiplargefiles"))
|
||||||
.setDesc(t("settings_skiplargefiles_desc"))
|
.setDesc(t("settings_skiplargefiles_desc"))
|
||||||
|
|||||||
@ -308,7 +308,7 @@ const isSkipItem = (
|
|||||||
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
|
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isFolderToSkip(key, [])) {
|
if (isFolderToSkip(key, [])) {
|
||||||
// some special dirs and files are always skipped
|
// some special dirs and files are always skipped
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,14 +13,7 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"lib": [
|
"lib": ["dom", "es5", "scripthost", "es2015"]
|
||||||
"dom",
|
|
||||||
"es5",
|
|
||||||
"scripthost",
|
|
||||||
"es2015"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["**/*.ts"]
|
||||||
"**/*.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user