0.24.0.dev-rc2

This commit is contained in:
vorotamoroz
2024-10-17 09:57:42 +01:00
parent 89e23b1bf4
commit 095a3d20fb
13 changed files with 140 additions and 196 deletions

View File

@@ -131,7 +131,7 @@ export function injectModules<T extends ICoreModule>(target: T, modules: ICoreMo
export abstract class AbstractModule {
_log = (msg: any, level: LOG_LEVEL = LOG_LEVEL_INFO, key?: string) => {
if (typeof msg === "string" && level !== LOG_LEVEL_NOTICE) {
msg = `[${this.constructor.name}] ${msg}`;
msg = `[${this.constructor.name}]\u{200A} ${msg}`;
}
// console.log(msg);
Logger(msg, level, key);

View File

@@ -18,10 +18,6 @@ export class ModuleFileAccessObsidian extends AbstractObsidianModule implements
}
$everyOnFirstInitialize(): Promise<boolean> {
this.vaultManager.beginWatch();
this.plugin.totalQueued = this.vaultManager.totalQueued;
this.plugin.batched = this.vaultManager.batched;
this.plugin.processing = this.vaultManager.processing;
return Promise.resolve(true);
}
$allOnUnload(): Promise<boolean> {

View File

@@ -6,7 +6,6 @@ import { delay, fireAndForget } from "../../../lib/src/common/utils.ts";
import { type FileEventItem, type FileEventType } from "../../../common/types.ts";
import { serialized, skipIfDuplicated } from "../../../lib/src/concurrency/lock.ts";
import { finishAllWaitingForTimeout, finishWaitingForTimeout, isWaitingForTimeout, waitForTimeout } from "../../../lib/src/concurrency/task.ts";
import { reactiveSource, type ReactiveSource } from "../../../lib/src/dataobject/reactive.ts";
import { Semaphore } from "../../../lib/src/concurrency/semaphore.ts";
import type { LiveSyncCore } from "../../../main.ts";
import { InternalFileToUXFileInfoStub, TFileToUXFileInfoStub } from "./utilObsidian.ts";
@@ -29,17 +28,12 @@ export abstract class StorageEventManager {
abstract appendQueue(items: FileEvent[], ctx?: any): Promise<void>;
abstract cancelQueue(key: string): void;
abstract isWaiting(filename: FilePath): boolean;
abstract totalQueued: ReactiveSource<number>;
abstract batched: ReactiveSource<number>;
abstract processing: ReactiveSource<number>;
}
export class StorageEventManagerObsidian extends StorageEventManager {
totalQueued = reactiveSource(0);
batched = reactiveSource(0);
processing = reactiveSource(0);
plugin: ObsidianLiveSyncPlugin;
core: LiveSyncCore;
@@ -330,9 +324,10 @@ export class StorageEventManagerObsidian extends StorageEventManager {
}
updateStatus() {
const allItems = this.bufferedQueuedItems.filter(e => !e.cancelled)
this.batched.value = allItems.filter(e => e.batched && !e.skipBatchWait).length;
this.processing.value = this.processingCount;
this.totalQueued.value = allItems.length - this.batched.value;
const batchedCount = allItems.filter(e => e.batched && !e.skipBatchWait).length;
this.core.batched.value = batchedCount
this.core.processing.value = this.processingCount;
this.core.totalQueued.value = allItems.length - batchedCount;
}
async handleFileEvent(queue: FileEventItem): Promise<any> {
@@ -340,7 +335,6 @@ export class StorageEventManagerObsidian extends StorageEventManager {
const lockKey = `handleFile:${file.path}`;
return await serialized(lockKey, async () => {
// TODO CHECK
// console.warn(lockKey);
const key = `file-last-proc-${queue.type}-${file.path}`;
const last = Number(await this.core.kvDB.get(key) || 0);
if (queue.type == "INTERNAL" || file.isInternal) {
@@ -362,77 +356,11 @@ export class StorageEventManagerObsidian extends StorageEventManager {
this.cancelRelativeEvent(queue);
return;
}
// if (queue.type == "CREATE" || queue.type == "CHANGED") {
// // eventHub.emitEvent("event-file-changed", { file: targetFile, automated: true });
// if (!await this.core.updateIntoDB(targetFile, undefined)) {
// Logger(`STORAGE -> DB: failed, cancel the relative operations: ${targetFile.path}`, LOG_LEVEL_INFO);
// // cancel running queues and remove one of atomic operation
// this.cancelRelativeEvent(queue);
// return;
// }
// }
// if (queue.type == "RENAME") {
// // Obsolete , can be called?
// await this.renameVaultItem(targetFile, queue.args.oldPath);
// }
// }
// await this.core.deleteFromDBbyPath(file.path);
// mtime = file.stat.mtime - 1;
// const keyD1 = `file-last-proc-CREATE-${file.path}`;
// const keyD2 = `file-last-proc-CHANGED-${file.path}`;
// await this.core.kvDB.set(keyD1, mtime);
// await this.core.kvDB.set(keyD2, mtime);
// } else {
// const targetFile = this.core.storageAccess.getFileStub(file.path);
// if (!(targetFile)) {
// Logger(`Target file was not found: ${file.path}`, LOG_LEVEL_INFO);
// return;
// }
// if (file.stat.mtime == last) {
// Logger(`File has been already scanned on ${queue.type}, skip: ${file.path}`, LOG_LEVEL_VERBOSE);
// return;
// }
// // const cache = queue.args.cache;
// if (queue.type == "CREATE" || queue.type == "CHANGED") {
// eventHub.emitEvent("event-file-changed", { file: targetFile, automated: true });
// // fireAndForget(() => this.addOnObsidianUI.checkAndApplySettingFromMarkdown(queue.args.file.path, true));
// const keyD1 = `file-last-proc-DELETED-${file.path}`;
// await this.core.kvDB.set(keyD1, mtime);
// if (!await this.core.updateIntoDB(targetFile, undefined)) {
// Logger(`STORAGE -> DB: failed, cancel the relative operations: ${targetFile.path}`, LOG_LEVEL_INFO);
// // cancel running queues and remove one of atomic operation
// this.cancelRelativeEvent(queue);
// return;
// }
// }
// if (queue.type == "RENAME") {
// // Obsolete , can be called?
// await this.renameVaultItem(targetFile, queue.args.oldPath);
// }
// }
// await this.core.kvDB.set(key, mtime);
}
}
});
}
// async renameVaultItem(file: UXFileInfoStub, oldFile: any, cache?: CacheData): Promise<void> {
// Logger(`${oldFile} renamed to ${file.path}`, LOG_LEVEL_VERBOSE);
// if (!file.isFolder) {
// try {
// // Logger(`RENAMING.. ${file.path} into db`);
// if (await this.core.updateIntoDB(file, cache)) {
// // Logger(`deleted ${oldFile} from db`);
// await this.core.deleteFromDBbyPath(oldFile);
// } else {
// Logger(`Could not save new file: ${file.path} `, LOG_LEVEL_NOTICE);
// }
// } catch (ex) {
// Logger(ex);
// }
// }
// }
cancelRelativeEvent(item: FileEventItem): void {
this.cancelQueue(item.key);
}

View File

@@ -115,19 +115,8 @@ export class ModuleObsidianAPI extends AbstractObsidianModule implements IObsidi
}
}
// -old implementation
try {
// const orgHeaders = opts?.headers;
// const newHeaders = new Headers();
// newHeaders.append("authorization", authHeader);
// if (orgHeaders && typeof orgHeaders.forEach !== "string") {
// const items = Object.entries(orgHeaders);
// items.forEach(([key, value]) => newHeaders.append(key, value));
// }
// newHeaders.append("ngrok-skip-browser-warning", "123");
// opts!.headers = newHeaders;
DEV: {
if (this.settings.enableDebugTools) {
// Issue #407
(opts!.headers as Headers).append("ngrok-skip-browser-warning", "123");
}

View File

@@ -212,13 +212,14 @@ export class ModuleLog extends AbstractObsidianModule implements IObsidianModule
const { message, status } = this.statusBarLabels.value;
// const recent = logMessages.value;
const newMsg = message;
const newLog = this.settings?.showOnlyIconsOnEditor ? "" : status;
let newLog = this.settings?.showOnlyIconsOnEditor ? "" : status;
const moduleTagEnd = newLog.indexOf(`]\u{200A}`);
if (moduleTagEnd != -1) {
newLog = newLog.substring(moduleTagEnd + 2);
}
this.statusBar?.setText(newMsg.split("\n")[0]);
if (this.settings?.showStatusOnEditor && this.statusDiv) {
// const root = activeDocument.documentElement;
// root.style.setProperty("--sls-log-text", "'" + (newMsg + "\\A " + newLog) + "'");
// this.statusDiv.innerText = newMsg + "\\A " + newLog;
if (this.settings.showLongerLogInsideEditor) {
const now = new Date().getTime();
this.logLines = this.logLines.filter(e => e.ttl > now);