diff --git a/manifest.json b/manifest.json index d3ddd50..7a7519a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "id": "obsidian-livesync", "name": "Self-hosted LiveSync", - "version": "0.11.4", + "version": "0.11.5", "minAppVersion": "0.9.12", "description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.", "author": "vorotamoroz", "authorUrl": "https://github.com/vrtmrz", "isDesktopOnly": false -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bbcd7d1..70b8f8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-livesync", - "version": "0.11.4", + "version": "0.11.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-livesync", - "version": "0.11.4", + "version": "0.11.5", "license": "MIT", "dependencies": { "diff-match-patch": "^1.0.5", diff --git a/package.json b/package.json index 6af8d08..6292931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-livesync", - "version": "0.11.4", + "version": "0.11.5", "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", @@ -41,4 +41,4 @@ "svelte-preprocess": "^4.10.2", "xxhash-wasm": "^0.4.2" } -} +} \ No newline at end of file diff --git a/src/LocalPouchDB.ts b/src/LocalPouchDB.ts index 2f5db25..d7fe557 100644 --- a/src/LocalPouchDB.ts +++ b/src/LocalPouchDB.ts @@ -19,6 +19,7 @@ import { VER, MILSTONE_DOCID, DatabaseConnectingStatus, + ObsidianLiveSyncSettings, } from "./lib/src/types"; import { RemoteDBSettings } from "./lib/src/types"; import { resolveWithIgnoreKnownError, delay, runWithLock, NewNotice, WrappedNotice, shouldSplitAsPlainText, splitPieces2, enableEncryption } from "./lib/src/utils"; @@ -33,7 +34,7 @@ class LRUCache { cache = new Map([]); revCache = new Map([]); maxCache = 100; - constructor() {} + constructor() { } get(key: string) { // debugger const v = this.cache.get(key); @@ -770,7 +771,7 @@ export class LocalPouchDB { this.openOneshotReplication( setting, showingNotice, - async (e) => {}, + async (e) => { }, false, (e) => { if (e === true) res(e); @@ -1222,10 +1223,14 @@ export class LocalPouchDB { } async garbageCollect() { - // if (this.settings.useHistory) { - // Logger("GC skipped for using history", LOG_LEVEL.VERBOSE); - // return; - // } + if (this.settings.useHistory) { + Logger("GC skipped for using history", LOG_LEVEL.VERBOSE); + return; + } + if ((this.settings as ObsidianLiveSyncSettings).liveSync) { + Logger("GC skipped while live sync.", LOG_LEVEL.VERBOSE); + return; + } // NOTE:Garbage collection could break old revisions. await runWithLock("replicate", true, async () => { if (this.gcRunning) return; diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index b78cd86..2754d34 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -188,7 +188,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { ); new Setting(containerRemoteDatabaseEl) .setName("End to End Encryption") - .setDesc("Encrypting contents on the database.") + .setDesc("Encrypting contents on the remote database. If you use the plugins synchronizing feature, enabling this is recommend.") .addToggle((toggle) => toggle.setValue(this.plugin.settings.workingEncrypt).onChange(async (value) => { this.plugin.settings.workingEncrypt = value; diff --git a/src/main.ts b/src/main.ts index 688cc41..a94b170 100644 --- a/src/main.ts +++ b/src/main.ts @@ -61,7 +61,7 @@ class PluginDialogModal extends Modal { } class PopoverYesNo extends FuzzySuggestModal { app: App; - callback: (e: string) => void = () => {}; + callback: (e: string) => void = () => { }; constructor(app: App, note: string, callback: (e: string) => void) { super(app); @@ -415,15 +415,19 @@ export default class ObsidianLiveSyncPlugin extends Plugin { onunload() { this.hidePluginSyncModal(); - this.localDatabase.onunload(); + if (this.localDatabase != null) { + this.localDatabase.onunload(); + } if (this.gcTimerHandler != null) { clearTimeout(this.gcTimerHandler); this.gcTimerHandler = null; } this.clearPeriodicSync(); this.clearPluginSweep(); - this.localDatabase.closeReplication(); - this.localDatabase.close(); + if (this.localDatabase != null) { + this.localDatabase.closeReplication(); + this.localDatabase.close(); + } window.removeEventListener("visibilitychange", this.watchWindowVisiblity); Logger("unloading plugin"); } @@ -453,6 +457,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin { this.settings.workingPassphrase = this.settings.passphrase; // Delete this feature to avoid problems on mobile. this.settings.disableRequestURI = true; + // Temporary disabled + // TODO: If a new GC is created, a new default value must be created. + this.settings.gcDelay = 0; + const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName(); if (this.settings.deviceAndVaultName != "") { if (!localStorage.getItem(lsname)) { @@ -618,7 +626,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { // When save is delayed, it should be cancelled. this.batchFileChange = this.batchFileChange.filter((e) => e == file.path); if (this.settings.suspendFileWatching) return; - this.watchVaultDeleteAsync(file).then(() => {}); + this.watchVaultDeleteAsync(file).then(() => { }); } async watchVaultDeleteAsync(file: TAbstractFile) { @@ -647,7 +655,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { watchVaultRename(file: TAbstractFile, oldFile: any) { if (this.settings.suspendFileWatching) return; - this.watchVaultRenameAsync(file, oldFile).then(() => {}); + this.watchVaultRenameAsync(file, oldFile).then(() => { }); } getFilePath(file: TAbstractFile): string { @@ -1209,16 +1217,16 @@ export default class ObsidianLiveSyncPlugin extends Plugin { const locks = getLocks(); const pendingTask = locks.pending.length ? "\nPending: " + - Object.entries([...new Set([...locks.pending])].reduce((p, c) => ({ ...p, [c]: p[c] ?? 0 + 1 }), {} as { [key: string]: number })) - .map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`) - .join(", ") + Object.entries([...new Set([...locks.pending])].reduce((p, c) => ({ ...p, [c]: p[c] ?? 0 + 1 }), {} as { [key: string]: number })) + .map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`) + .join(", ") : ""; const runningTask = locks.running.length ? "\nRunning: " + - Object.entries([...new Set([...locks.running])].reduce((p, c) => ({ ...p, [c]: p[c] ?? 0 + 1 }), {} as { [key: string]: number })) - .map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`) - .join(", ") + Object.entries([...new Set([...locks.running])].reduce((p, c) => ({ ...p, [c]: p[c] ?? 0 + 1 }), {} as { [key: string]: number })) + .map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`) + .join(", ") : ""; this.setStatusBarText(message + pendingTask + runningTask); } @@ -1246,7 +1254,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { this.lastLog = newLog; } } - updateStatusBarText() {} + updateStatusBarText() { } async replicate(showMessage?: boolean) { if (this.settings.versionUpFlash != "") { @@ -1757,10 +1765,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin { if (!this.localDatabase.isReady) return; await runWithLock("sweepplugin", true, async () => { const logLevel = showMessage ? LOG_LEVEL.NOTICE : LOG_LEVEL.INFO; - if (!this.settings.encrypt) { - Logger("You have to encrypt the database to use plugin setting sync.", LOG_LEVEL.NOTICE); - return; - } if (!this.deviceAndVaultName) { Logger("You have to set your device and vault name.", LOG_LEVEL.NOTICE); return;