diff --git a/src/lib b/src/lib index 17884bf..189d5cb 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 17884bf91209adf05fef70d6a25fe692e979d352 +Subproject commit 189d5cbff227bf9d314057d5b3ff489143fed804 diff --git a/src/modules/core/ModuleFileHandler.ts b/src/modules/core/ModuleFileHandler.ts index f9a0b93..712428a 100644 --- a/src/modules/core/ModuleFileHandler.ts +++ b/src/modules/core/ModuleFileHandler.ts @@ -266,7 +266,10 @@ export class ModuleFileHandler extends AbstractModule { // Check the file is not corrupted // (Zero is a special case, may be created by some APIs and it might be acceptable). if (docRead.size != 0 && docRead.size !== readAsBlob(docRead).size) { - this._log(`File ${path} seems to be corrupted! Writing prevented.`, LOG_LEVEL_NOTICE); + this._log( + `File ${path} seems to be corrupted! Writing prevented. (${docRead.size} != ${readAsBlob(docRead).size})`, + LOG_LEVEL_NOTICE + ); return false; } } diff --git a/src/modules/core/ReplicateResultProcessor.ts b/src/modules/core/ReplicateResultProcessor.ts index d969aa1..1304195 100644 --- a/src/modules/core/ReplicateResultProcessor.ts +++ b/src/modules/core/ReplicateResultProcessor.ts @@ -342,7 +342,7 @@ export class ReplicateResultProcessor { return; } finally { // Remove from processing queue - this._processingChanges.remove(change); + this._processingChanges = this._processingChanges.filter((e) => e === change); this.triggerTakeSnapshot(); } } diff --git a/src/modules/coreObsidian/storageLib/SerializedFileAccess.ts b/src/modules/coreObsidian/storageLib/SerializedFileAccess.ts index e7ff18c..59d8a32 100644 --- a/src/modules/coreObsidian/storageLib/SerializedFileAccess.ts +++ b/src/modules/coreObsidian/storageLib/SerializedFileAccess.ts @@ -169,7 +169,7 @@ export class SerializedFileAccess { getAbstractFileByPathInsensitive(path: FilePath | string): TAbstractFile | null { //@ts-ignore - return app.vault.getAbstractFileByPathInsensitive(path); + return this.app.vault.getAbstractFileByPathInsensitive(path); } getAbstractFileByPath(path: FilePath | string): TAbstractFile | null { diff --git a/src/modules/essentialObsidian/ModuleObsidianEvents.ts b/src/modules/essentialObsidian/ModuleObsidianEvents.ts index 4682eb1..36bf1a4 100644 --- a/src/modules/essentialObsidian/ModuleObsidianEvents.ts +++ b/src/modules/essentialObsidian/ModuleObsidianEvents.ts @@ -67,6 +67,11 @@ export class ModuleObsidianEvents extends AbstractObsidianModule { // eslint-disable-next-line @typescript-eslint/no-this-alias const _this = this; //@ts-ignore + if (!window.CodeMirrorAdapter) { + this._log("CodeMirrorAdapter is not available"); + return; + } + //@ts-ignore window.CodeMirrorAdapter.commands.save = () => { //@ts-ignore _this.app.commands.executeCommandById("editor:save-file"); diff --git a/src/modules/features/ModuleInteractiveConflictResolver.ts b/src/modules/features/ModuleInteractiveConflictResolver.ts index 6bbeb47..4c1ec63 100644 --- a/src/modules/features/ModuleInteractiveConflictResolver.ts +++ b/src/modules/features/ModuleInteractiveConflictResolver.ts @@ -131,30 +131,36 @@ export class ModuleInteractiveConflictResolver extends AbstractObsidianModule { async _allScanStat(): Promise { const notes: { path: string; mtime: number }[] = []; this._log(`Checking conflicted files`, LOG_LEVEL_VERBOSE); - for await (const doc of this.localDatabase.findAllDocs({ conflicts: true })) { - if (!("_conflicts" in doc)) continue; - notes.push({ path: getPath(doc), mtime: doc.mtime }); - } - if (notes.length > 0) { - this.core.confirm.askInPopup( - `conflicting-detected-on-safety`, - `Some files have been left conflicted! Press {HERE} to resolve them, or you can do it later by "Pick a file to resolve conflict`, - (anchor) => { - anchor.text = "HERE"; - anchor.addEventListener("click", () => { - fireAndForget(() => this.allConflictCheck()); - }); - } - ); - this._log( - `Some files have been left conflicted! Please resolve them by "Pick a file to resolve conflict". The list is written in the log.`, - LOG_LEVEL_VERBOSE - ); - for (const note of notes) { - this._log(`Conflicted: ${note.path}`); + try { + for await (const doc of this.localDatabase.findAllDocs({ conflicts: true })) { + if (!("_conflicts" in doc)) continue; + notes.push({ path: getPath(doc), mtime: doc.mtime }); } - } else { - this._log(`There are no conflicting files`, LOG_LEVEL_VERBOSE); + if (notes.length > 0) { + this.core.confirm.askInPopup( + `conflicting-detected-on-safety`, + `Some files have been left conflicted! Press {HERE} to resolve them, or you can do it later by "Pick a file to resolve conflict`, + (anchor) => { + anchor.text = "HERE"; + anchor.addEventListener("click", () => { + fireAndForget(() => this.allConflictCheck()); + }); + } + ); + this._log( + `Some files have been left conflicted! Please resolve them by "Pick a file to resolve conflict". The list is written in the log.`, + LOG_LEVEL_VERBOSE + ); + for (const note of notes) { + this._log(`Conflicted: ${note.path}`); + } + } else { + this._log(`There are no conflicting files`, LOG_LEVEL_VERBOSE); + } + } catch (e) { + this._log(`Error while scanning conflicted files: ${e}`, LOG_LEVEL_NOTICE); + this._log(e, LOG_LEVEL_VERBOSE); + return false; } return true; } diff --git a/src/modules/features/ModuleLog.ts b/src/modules/features/ModuleLog.ts index a6f31a2..0c64834 100644 --- a/src/modules/features/ModuleLog.ts +++ b/src/modules/features/ModuleLog.ts @@ -15,7 +15,6 @@ import { hiddenFilesEventCount, hiddenFilesProcessingCount, type LogEntry, - logStore, logMessages, } from "../../lib/src/mock_and_interop/stores.ts"; import { eventHub } from "../../lib/src/hub/hub.ts"; @@ -28,7 +27,6 @@ import { import { AbstractObsidianModule } from "../AbstractObsidianModule.ts"; import { addIcon, normalizePath, Notice } from "../../deps.ts"; import { LOG_LEVEL_NOTICE, setGlobalLogFunction } from "octagonal-wheels/common/logger"; -import { QueueProcessor } from "octagonal-wheels/concurrency/processor"; import { LogPaneView, VIEW_TYPE_LOG } from "./Log/LogPaneView.ts"; import { serialized } from "octagonal-wheels/concurrency/lock"; import { $msg } from "src/lib/src/common/i18n.ts"; @@ -45,24 +43,21 @@ import { // This module cannot be a core module because it depends on the Obsidian UI. // DI the log again. +const recentLogEntries = reactiveSource([]); setGlobalLogFunction((message: any, level?: number, key?: string) => { const messageX = message instanceof Error ? new LiveSyncError("[Error Logged]: " + message.message, { cause: message }) : message; const entry = { message: messageX, level, key } as LogEntry; - logStore.enqueue(entry); + recentLogEntries.value = [...recentLogEntries.value, entry]; }); let recentLogs = [] as string[]; -// Recent log splicer -const recentLogProcessor = new QueueProcessor( - (logs: string[]) => { - recentLogs = [...recentLogs, ...logs].splice(-200); - logMessages.value = recentLogs; - }, - { batchSize: 25, delay: 10, suspended: false, concurrentLimit: 1 } -).resumePipeLine(); +function addLog(log: string) { + recentLogs = [...recentLogs, log].splice(-200); + logMessages.value = recentLogs; +} // logStore.intercept(e => e.slice(Math.min(e.length - 200, 0))); const showDebugLog = false; @@ -373,16 +368,12 @@ export class ModuleLog extends AbstractObsidianModule { return Promise.resolve(true); } private _everyOnloadAfterLoadSettings(): Promise { - logStore - .pipeTo( - new QueueProcessor((logs) => logs.forEach((e) => this.__addLog(e.message, e.level, e.key)), { - suspended: false, - batchSize: 20, - concurrentLimit: 1, - delay: 0, - }) - ) - .startPipeline(); + recentLogEntries.onChanged((entries) => { + if (entries.value.length === 0) return; + const newEntries = [...entries.value]; + recentLogEntries.value = []; + newEntries.forEach((e) => this.__addLog(e.message, e.level, e.key)); + }); eventHub.onEvent(EVENT_FILE_RENAMED, (data) => { void this.setFileStatus(); }); @@ -464,7 +455,7 @@ export class ModuleLog extends AbstractObsidianModule { if (this.settings?.writeLogToTheFile) { this.writeLogToTheFile(now, vaultName, newMessage); } - recentLogProcessor.enqueue(newMessage); + addLog(newMessage); this.logLines.push({ ttl: now.getTime() + 3000, message: newMessage }); if (level >= LOG_LEVEL_NOTICE) {