From 4be67ce49182ca7448af5f71f5bfd41f9939d0ce Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:07:47 +0800 Subject: [PATCH] minor change to synconsave --- src/baseTypes.ts | 4 ++-- src/langs/en.json | 2 +- src/langs/zh_cn.json | 2 +- src/langs/zh_tw.json | 2 +- src/main.ts | 23 ++++++++++++++--------- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/baseTypes.ts b/src/baseTypes.ts index e771917..47e5645 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -272,9 +272,9 @@ export const DEFAULT_LOG_HISTORY_FILE_PREFIX = "log_hist_exported_on_"; export type SyncTriggerSourceType = | "manual" - | "auto" | "dry" - | "autoOnceInit" + | "auto" + | "auto_once_init" | "auto_sync_on_save"; export const REMOTELY_SAVE_VERSION_2022 = "0.3.25"; diff --git a/src/langs/en.json b/src/langs/en.json index 2a2f864..936e015 100644 --- a/src/langs/en.json +++ b/src/langs/en.json @@ -5,7 +5,7 @@ "goback": "Go Back", "submit": "Submit", "sometext": "Here are some texts.", - "syncrun_alreadyrunning": "{{pluginName}} already running in stage {{syncStatus}}!", + "syncrun_alreadyrunning": "New command {{newTriggerSource}} stops because {{pluginName}} is already running in stage {{syncStatus}}!", "syncrun_syncingribbon": "{{pluginName}}: syncing from {{triggerSource}}", "syncrun_step0": "0/8 Remotely Save is running in dry mode, thus not actual file changes would happen.", "syncrun_step1": "1/8 Remotely Save is preparing ({{serviceType}})", diff --git a/src/langs/zh_cn.json b/src/langs/zh_cn.json index ae65197..dd83c7b 100644 --- a/src/langs/zh_cn.json +++ b/src/langs/zh_cn.json @@ -5,7 +5,7 @@ "goback": "返回", "submit": "提交", "sometext": "这里有一段文字。", - "syncrun_alreadyrunning": "{{pluginName}} 正处于此阶段:{{syncStatus}}!", + "syncrun_alreadyrunning": "{{pluginName}} 正处于此阶段:{{syncStatus}}!中断触发 {{newTriggerSource}}。", "syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 触发运行", "syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不会发生实际的文件交换。", "syncrun_step1": "1/8 Remotely Save 准备同步({{serviceType}})", diff --git a/src/langs/zh_tw.json b/src/langs/zh_tw.json index 95f1797..7b87e9e 100644 --- a/src/langs/zh_tw.json +++ b/src/langs/zh_tw.json @@ -5,7 +5,7 @@ "goback": "返回", "submit": "提交", "sometext": "這裡有一段文字。", - "syncrun_alreadyrunning": "{{pluginName}} 正處於此階段:{{syncStatus}}!", + "syncrun_alreadyrunning": "{{pluginName}} 正處於此階段:{{syncStatus}}! 中斷觸發 {{newTriggerSource}}。", "syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 觸發執行", "syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不會發生實際的檔案交換。", "syncrun_step1": "1/8 Remotely Save 準備同步({{serviceType}})", diff --git a/src/main.ts b/src/main.ts index 4e8a48b..b509757 100644 --- a/src/main.ts +++ b/src/main.ts @@ -167,15 +167,17 @@ export default class RemotelySavePlugin extends Plugin { } }; if (this.syncStatus !== "idle") { - // here the notice is shown regardless of triggerSource - new Notice( + // really, users don't want to see this in auto mode + // so we use getNotice to avoid unnecessary show up + getNotice( t("syncrun_alreadyrunning", { pluginName: this.manifest.name, syncStatus: this.syncStatus, + newTriggerSource: triggerSource, }) ); if (this.currSyncMsg !== undefined && this.currSyncMsg !== "") { - new Notice(this.currSyncMsg); + getNotice(this.currSyncMsg); } return; } @@ -378,7 +380,8 @@ export default class RemotelySavePlugin extends Plugin { realCounter, realTotalCount, pathName, - decision + decision, + triggerSource ), this.db ); @@ -1105,7 +1108,7 @@ export default class RemotelySavePlugin extends Plugin { ) { this.app.workspace.onLayoutReady(() => { window.setTimeout(() => { - this.syncRun("autoOnceInit"); + this.syncRun("auto_once_init"); }, this.settings.initRunAfterMilliseconds); }); } @@ -1139,7 +1142,7 @@ export default class RemotelySavePlugin extends Plugin { // if it has modified after lastSuccessSync // then schedule a run for syncOnSaveAfterMilliseconds after it was modified const lastModified = currentFile.stat.mtime; - const lastSuccessSyncMillis = await getLastSuccessSyncByVault( + const lastSuccessSyncMillis = await getLastSuccessSyncTimeByVault( this.db, this.vaultRandomID ); @@ -1174,7 +1177,8 @@ export default class RemotelySavePlugin extends Plugin { // listen to current file save changes this.registerEvent( - this.app.vault.on("modify", () => { + this.app.vault.on("modify", (x) => { + // console.debug(`event=modify! file=${x}`); checkCurrFileModified("FILE_CHANGES"); }) ); @@ -1197,9 +1201,10 @@ export default class RemotelySavePlugin extends Plugin { i: number, totalCount: number, pathName: string, - decision: string + decision: string, + triggerSource: SyncTriggerSourceType ) { - const msg = `syncing progress=${i}/${totalCount},decision=${decision},path=${pathName}`; + const msg = `syncing progress=${i}/${totalCount},decision=${decision},path=${pathName},source=${triggerSource}`; this.currSyncMsg = msg; }