diff --git a/src/CmdConfigSync.ts b/src/CmdConfigSync.ts index 3b89da6..b3330a3 100644 --- a/src/CmdConfigSync.ts +++ b/src/CmdConfigSync.ts @@ -4,7 +4,7 @@ import { Notice, type PluginManifest, parseYaml, normalizePath } from "./deps"; import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry, SavingEntry } from "./lib/src/types"; import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE } from "./lib/src/types"; import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types"; -import { createTextBlob, delay, getDocData } from "./lib/src/utils"; +import { createTextBlob, delay, getDocData, sendSignal, waitForSignal } from "./lib/src/utils"; import { Logger } from "./lib/src/logger"; import { WrappedNotice } from "./lib/src/wrapper"; import { readString, decodeBinary, arrayBufferToBase64, sha1 } from "./lib/src/strbin"; @@ -335,7 +335,9 @@ export class ConfigSync extends LiveSyncCommands { return; }, { suspended: true, batchSize: 1, concurrentLimit: 5, delay: 300, yieldThreshold: 10 }).pipeTo( new QueueProcessor( - (pluginDataList) => { + async (pluginDataList) => { + // Concurrency is two, therefore, we can unlock the previous awaiting. + sendSignal("plugin-next-load"); let newList = [...this.pluginList]; for (const item of pluginDataList) { newList = newList.filter(x => x.documentPath != item.documentPath); @@ -343,9 +345,13 @@ export class ConfigSync extends LiveSyncCommands { } this.pluginList = newList; pluginList.set(newList); + if (pluginDataList.length != 10) { + // If the queue is going to be empty, await subsequent for a while. + await waitForSignal("plugin-next-load", 1000); + } return; } - , { suspended: true, batchSize: 1000, concurrentLimit: 10, delay: 200, yieldThreshold: 25, totalRemainingReactiveSource: pluginScanningCount })).startPipeline().root.onIdle(() => { + , { suspended: true, batchSize: 10, concurrentLimit: 2, delay: 250, yieldThreshold: 25, totalRemainingReactiveSource: pluginScanningCount })).startPipeline().root.onIdle(() => { Logger(`All files enumerated`, LOG_LEVEL_INFO, "get-plugins"); this.createMissingConfigurationEntry(); }); diff --git a/src/StorageEventManager.ts b/src/StorageEventManager.ts index d9a3ede..80f8edb 100644 --- a/src/StorageEventManager.ts +++ b/src/StorageEventManager.ts @@ -4,6 +4,7 @@ import { Logger } from "./lib/src/logger"; import { isPlainText, shouldBeIgnored } from "./lib/src/path"; import type { KeyedQueueProcessor } from "./lib/src/processor"; import { LOG_LEVEL_NOTICE, type FilePath, type ObsidianLiveSyncSettings } from "./lib/src/types"; +import { delay } from "./lib/src/utils"; import { type FileEventItem, type FileEventType, type FileInfo, type InternalFileInfo } from "./types"; @@ -110,6 +111,8 @@ export class StorageEventManagerObsidian extends StorageEventManager { let cache: null | string | ArrayBuffer; // new file or something changed, cache the changes. if (file instanceof TFile && (type == "CREATE" || type == "CHANGED")) { + // Wait for a bit while to let the writer has marked `touched` at the file. + await delay(10); if (this.plugin.vaultAccess.recentlyTouched(file)) { continue; } diff --git a/src/lib b/src/lib index ee376a8..dc9cbfe 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit ee376a80a59a266145efed7247d2bdb0f8780aa6 +Subproject commit dc9cbfe007ec4532a8494d7d289a25fa4c7c3c3e diff --git a/src/main.ts b/src/main.ts index 42f37cc..aa351a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1010,8 +1010,8 @@ Note: We can always able to read V1 format. It will be progressively converted. async checkAndApplySettingFromMarkdown(filename: string, automated?: boolean) { if (automated && !this.settings.notifyAllSettingSyncFile) { - if (this.settings.settingSyncFile != filename) { - Logger(`Setting file (${filename}) is not matched to the current configuration. skipped.`, LOG_LEVEL_INFO); + if (!this.settings.settingSyncFile || this.settings.settingSyncFile != filename) { + Logger(`Setting file (${filename}) is not matched to the current configuration. skipped.`, LOG_LEVEL_VERBOSE); return; } } @@ -1291,10 +1291,11 @@ We can perform a command in this file. } pendingFileEventCount = reactiveSource(0); + processingFileEventCount = reactiveSource(0); fileEventQueue = new KeyedQueueProcessor( (items: FileEventItem[]) => this.handleFileEvent(items[0]), - { suspended: true, batchSize: 1, concurrentLimit: 5, delay: 100, yieldThreshold: FileWatchEventQueueMax, totalRemainingReactiveSource: this.pendingFileEventCount } + { suspended: true, batchSize: 1, concurrentLimit: 5, delay: 100, yieldThreshold: FileWatchEventQueueMax, totalRemainingReactiveSource: this.pendingFileEventCount, processingEntitiesReactiveSource: this.processingFileEventCount } ).replaceEnqueueProcessor((items, newItem) => this.queueNextFileEvent(items, newItem)); @@ -1764,7 +1765,7 @@ We can perform a command in this file. }) const waitingLabel = reactive(() => { const e = this.pendingFileEventCount.value; - const proc = this.fileEventQueue.processingEntities; + const proc = this.processingFileEventCount.value; const pend = e - proc; const labelProc = proc != 0 ? `⏳${proc} ` : ""; const labelPend = pend != 0 ? ` 🛫${pend}` : ""; @@ -1805,13 +1806,19 @@ We can perform a command in this file. const newLog = log; // scheduleTask("update-display", 50, () => { this.statusBar?.setText(newMsg.split("\n")[0]); + const selector = `.CodeMirror-wrap,` + + `.markdown-preview-view.cm-s-obsidian,` + + `.markdown-source-view.cm-s-obsidian,` + + `.canvas-wrapper,` + + `.empty-state` + ; if (this.settings.showStatusOnEditor) { const root = activeDocument.documentElement; - const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`); + const q = root.querySelectorAll(selector); q.forEach(e => e.setAttr("data-log", '' + (newMsg + "\n" + newLog) + '')) } else { const root = activeDocument.documentElement; - const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`); + const q = root.querySelectorAll(selector); q.forEach(e => e.setAttr("data-log", '')) } // }, true); diff --git a/styles.css b/styles.css index 972904c..f5c6c91 100644 --- a/styles.css +++ b/styles.css @@ -98,8 +98,10 @@ } .CodeMirror-wrap::before, -.cm-s-obsidian > .cm-editor::before, -.canvas-wrapper::before { +.markdown-preview-view.cm-s-obsidian::before, +.markdown-source-view.cm-s-obsidian::before, +.canvas-wrapper::before, +.empty-state::before { content: attr(data-log); text-align: right; white-space: pre-wrap; @@ -115,6 +117,19 @@ filter: grayscale(100%); } +.empty-state::before, +.markdown-preview-view.cm-s-obsidian::before, +.markdown-source-view.cm-s-obsidian::before { + top: var(--header-height); + right: 1em; +} + +.is-mobile .empty-state::before, +.is-mobile .markdown-preview-view.cm-s-obsidian::before, +.is-mobile .markdown-source-view.cm-s-obsidian::before { + top: var(--view-header-height); + right: 1em; +} .canvas-wrapper::before { right: 48px; } @@ -292,7 +307,7 @@ span.ls-mark-cr::after { position: absolute; top: 0; left: 0; - animation: ls-blink-diff 0.5s cubic-bezier(0.4, 0, 1, 1) infinite alternate; + animation: ls-blink-diff 0.5s cubic-bezier(0.4, 0, 1, 1) infinite alternate; } @keyframes ls-blink-diff { 0% {