From 58196c242348bae94c199c45f01fc664ffb0721d Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Tue, 14 Mar 2023 19:02:57 +0900 Subject: [PATCH] Fixed: - Now `redflag3` can be run surely. - Synchronisation can now be aborted. --- src/lib | 2 +- src/main.ts | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib b/src/lib index 8985fa7..a929ee4 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 8985fa74e99505c2424cb2aecfb8eb4a167db84d +Subproject commit a929ee40cc1fed152686133d0703684e809f4b64 diff --git a/src/main.ts b/src/main.ts index a560e40..d105527 100644 --- a/src/main.ts +++ b/src/main.ts @@ -298,10 +298,11 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } else if (this.isRedFlag3Raised()) { Logger(`${FLAGMD_REDFLAG3} has been detected! Self-hosted LiveSync will discard the local database and fetch everything from the remote once again.`, LOG_LEVEL.NOTICE); await this.resetLocalDatabase(); + await delay(1000); await this.markRemoteResolved(); await this.openDatabase(); this.isReady = true; - await this.replicate(true); + await this.replicateAllFromServer(true); await this.deleteRedFlag3(); if (await askYesNo(this.app, "Do you want to disable Suspend file watching and restart obsidian now?") == "yes") { this.settings.suspendFileWatching = false; @@ -473,13 +474,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin { this.usedPassphrase = ""; await this.saveSettings(); if (keepLocalDB == "no") { - this.resetLocalDatabase(); - this.localDatabase.initializeDatabase(); + await this.resetLocalDatabase(); + await this.localDatabase.initializeDatabase(); const rebuild = await askYesNo(this.app, "Rebuild the database?"); if (rebuild == "yes") { initDB = this.initializeDatabase(true); } else { - this.markRemoteResolved(); + await this.markRemoteResolved(); } } if (keepRemoteDB == "no") { @@ -730,6 +731,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin { await this.applyBatchChange(); }, }) + this.addCommand({ + id: "livesync-abortsync", + name: "Abort synchronization immediately", + callback: () => { + this.localDatabase.terminateSync(); + }, + }) } @@ -1917,7 +1925,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { if (this.settings.syncInternalFiles && this.settings.syncInternalFilesBeforeReplication && !this.settings.watchInternalFileChanges) { await this.syncInternalFilesAndDatabase("push", showMessage); } - await this.localDatabase.openReplication(this.settings, false, showMessage, this.parseReplicationResult); + return await this.localDatabase.openReplication(this.settings, false, showMessage, this.parseReplicationResult); } async initializeDatabase(showingNotice?: boolean, reopenDatabase = true) { @@ -1964,6 +1972,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } return await this.localDatabase.replicateAllToServer(this.settings, showingNotice); } + async replicateAllFromServer(showingNotice?: boolean) { + if (!this.isReady) return false; + return await this.localDatabase.replicateAllFromServer(this.settings, this.parseReplicationResult, showingNotice); + } async markRemoteLocked() { return await this.localDatabase.markRemoteLocked(this.settings, true);