From ebcb059d998d59d94e1a069c4d2fa3d822338604 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Tue, 11 Jan 2022 13:17:35 +0900 Subject: [PATCH] Modified: - Plugins and settings is now in beta. Implemented: - Show the count of the pending processes into the status. --- README.md | 2 ++ README_ja.md | 2 ++ manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/ObsidianLiveSyncSettingTab.ts | 2 +- src/main.ts | 9 +++++++-- src/utils.ts | 27 +++++++++++++++++++++++++++ 8 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43c4962..6eecb66 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ Synchronization status is shown in statusbar. - ⚠ Error occurred. - ↑ Uploaded pieces - ↓ Downloaded pieces +- ⏳ Count of the pending process +If you have deleted or renamed files, please wait until this disappears. # More supplements diff --git a/README_ja.md b/README_ja.md index da020ce..60a8a09 100644 --- a/README_ja.md +++ b/README_ja.md @@ -78,6 +78,8 @@ Self-hosted LiveSync用にWebClipperも作りました。Chrome Web Storeから - ⚠ エラーが発生しています - ↑ 送信したデータ数 - ↓ 受信したデータ数 +- ⏳ 保留している処理の数です +ファイルを削除したりリネームした場合、この表示が消えるまでお待ちください。 # さらなる補足 - ファイルは同期された後、タイムスタンプを比較して新しければいったん新しい方で上書きされます。その後、衝突が発生したかによって、マージが行われます。 diff --git a/manifest.json b/manifest.json index cea5902..cffd314 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-livesync", "name": "Self-hosted LiveSync", - "version": "0.4.1", + "version": "0.5.0", "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", diff --git a/package-lock.json b/package-lock.json index 0e80d45..21d1b05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-livesync", - "version": "0.4.1", + "version": "0.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-livesync", - "version": "0.4.1", + "version": "0.5.0", "license": "MIT", "dependencies": { "diff-match-patch": "^1.0.5", diff --git a/package.json b/package.json index e1d99d2..0ee336a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-livesync", - "version": "0.4.1", + "version": "0.5.0", "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", "scripts": { diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index 0945dc8..f034e03 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -811,7 +811,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { // With great respect, thank you TfTHacker! // refered: https://github.com/TfTHacker/obsidian42-brat/blob/main/src/features/BetaPlugins.ts const containerPluginSettings = containerEl.createDiv(); - containerPluginSettings.createEl("h3", { text: "Plugins and settings (bleeding edge)" }); + containerPluginSettings.createEl("h3", { text: "Plugins and settings (beta)" }); const updateDisabledOfDeviceAndVaultName = () => { vaultName.setDisabled(this.plugin.settings.autoSweepPlugins || this.plugin.settings.autoSweepPluginsPeriodic); diff --git a/src/main.ts b/src/main.ts index 559ec18..8c3f4ba 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ import { diff_result, FLAGMD_REDFLAG, } from "./types"; -import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock, shouldBeIgnored } from "./utils"; +import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock, shouldBeIgnored, getProcessingCounts, setLockNotifier } from "./utils"; import { Logger, setLogger } from "./logger"; import { LocalPouchDB } from "./LocalPouchDB"; import { LogDisplayModal } from "./LogDisplayModal"; @@ -205,6 +205,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin { }); this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000); this.triggerCheckPluginUpdate = debounce(this.triggerCheckPluginUpdate.bind(this), 3000); + setLockNotifier(() => { + this.refreshStatusText(); + }); } onunload() { this.localDatabase.onunload(); @@ -787,7 +790,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin { waiting = " " + this.batchFileChange.map((e) => "🛫").join(""); waiting = waiting.replace(/(🛫){10}/g, "🚀"); } - const message = `Sync:${w} ↑${sent} ↓${arrived}${waiting}`; + const procs = getProcessingCounts(); + const procsDisp = procs==0?"":` ⏳${procs}`; + const message = `Sync:${w} ↑${sent} ↓${arrived}${waiting}${procsDisp}`; this.setStatusBarText(message); } setStatusBarText(message: string) { diff --git a/src/utils.ts b/src/utils.ts index 0b42612..3d2e646 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -121,7 +121,28 @@ function objectToKey(key: any): string { const keys = Object.keys(key).sort((a, b) => a.localeCompare(b)); return keys.map((e) => e + objectToKey(key[e])).join(":"); } +export function getProcessingCounts() { + let count = 0; + for (const v in pendingProcs) { + count += pendingProcs[v].length; + } + count += runningProcs.length; + return count; +} +let externalNotifier: () => void = () => {}; +let notifyTimer: number = null; +export function setLockNotifier(fn: () => void) { + externalNotifier = fn; +} +function notifyLock() { + if (notifyTimer != null) { + window.clearTimeout(notifyTimer); + } + notifyTimer = window.setTimeout(() => { + externalNotifier(); + }, 100); +} // Just run async/await as like transacion ISOLATION SERIALIZABLE export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: () => Promise): Promise { // Logger(`Lock:${key}:enter`, LOG_LEVEL.VERBOSE); @@ -130,11 +151,13 @@ export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: ( if (typeof pendingProcs[lockKey] === "undefined") { //simply unlock runningProcs.remove(lockKey); + notifyLock(); // Logger(`Lock:${lockKey}:released`, LOG_LEVEL.VERBOSE); } else { Logger(`Lock:${lockKey}:left ${pendingProcs[lockKey].length}`, LOG_LEVEL.VERBOSE); let nextProc = null; nextProc = pendingProcs[lockKey].shift(); + notifyLock(); if (nextProc) { // left some nextProc() @@ -145,6 +168,7 @@ export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: ( .finally(() => { if (pendingProcs && lockKey in pendingProcs && pendingProcs[lockKey].length == 0) { delete pendingProcs[lockKey]; + notifyLock(); } queueMicrotask(() => { handleNextProcs(); @@ -153,6 +177,7 @@ export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: ( } else { if (pendingProcs && lockKey in pendingProcs && pendingProcs[lockKey].length == 0) { delete pendingProcs[lockKey]; + notifyLock(); } } } @@ -189,10 +214,12 @@ export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: ( }); pendingProcs[lockKey].push(subproc); + notifyLock(); // Logger(`Lock:${lockKey}:queud:left${pendingProcs[lockKey].length}`, LOG_LEVEL.VERBOSE); return responder; } else { runningProcs.push(lockKey); + notifyLock(); // Logger(`Lock:${lockKey}:aqquired`, LOG_LEVEL.VERBOSE); return new Promise((res, rej) => { proc()