From 801500f924b878b1ace7f8d13fc9f12ff6a56ae4 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Mon, 4 Apr 2022 19:58:44 +0900 Subject: [PATCH] Fixed: - Fixed merging issue (Concat both) - Overdetection of file change after the replication --- package-lock.json | 4 ++-- package.json | 2 +- src/main.ts | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index f544945..f039588 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-livesync", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-livesync", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "diff-match-patch": "^1.0.5", diff --git a/package.json b/package.json index 8e6920e..2394a21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-livesync", - "version": "0.8.0", + "version": "0.8.1", "description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.", "main": "main.js", "type": "module", diff --git a/src/main.ts b/src/main.ts index b4e4dc0..689bcb0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -427,10 +427,21 @@ export default class ObsidianLiveSyncPlugin extends Plugin { return; } if (this.settings.suspendFileWatching) return; + // If batchsave is enabled, queue all changes and do nothing. if (this.settings.batchSave) { - this.batchFileChange = Array.from(new Set([...this.batchFileChange, file.path])); - this.refreshStatusText(); + ~(async () => { + const meta = await this.localDatabase.getDBEntryMeta(file.path); + if (meta != false) { + const localMtime = ~~(file.stat.mtime / 1000); + const docMtime = ~~(meta.mtime / 1000); + if (localMtime !== docMtime) { + // Perhaps we have to modify (to using newer doc), but we don't be sure to every device's clock is adjusted. + this.batchFileChange = Array.from(new Set([...this.batchFileChange, file.path])); + this.refreshStatusText(); + } + } + })(); return; } this.watchVaultChangeAsync(file, ...args); @@ -1232,10 +1243,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin { //concat both, // write data,and delete both old rev. const p = conflictCheckResult.diff.map((e) => e[1]).join(""); - await this.app.vault.modify(file, p); - await this.updateIntoDB(file); await this.localDatabase.deleteDBEntry(file.path, { rev: conflictCheckResult.left.rev }); await this.localDatabase.deleteDBEntry(file.path, { rev: conflictCheckResult.right.rev }); + await this.app.vault.modify(file, p); + await this.updateIntoDB(file); await this.pullFile(file.path); Logger("concat both file"); setTimeout(() => {