Skip to content

Commit

Permalink
0.24.0.dev-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtmrz committed Oct 17, 2024
1 parent 89e23b1 commit 095a3d2
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"sourceType": "module",
"project": ["tsconfig.json"]
},
"ignorePatterns": ["src/lib/src/API/*.ts"],
"ignorePatterns": [],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
Expand Down
10 changes: 10 additions & 0 deletions manifest-beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "obsidian-livesync",
"name": "Self-hosted LiveSync",
"version": "0.24.0.dev-rc2",
"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
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-livesync",
"version": "0.24.0.rc1",
"version": "0.24.0.dev-rc2",
"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",
Expand Down Expand Up @@ -73,4 +73,4 @@
"xxhash-wasm": "0.4.2",
"xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2"
}
}
}
2 changes: 1 addition & 1 deletion src/modules/AbstractModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/modules/coreObsidian/ModuleFileAccessObsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
84 changes: 6 additions & 78 deletions src/modules/coreObsidian/storageLib/StorageEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

Expand Down Expand Up @@ -330,17 +324,17 @@ 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> {
const file = queue.args.file;
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) {
Expand All @@ -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);
}
Expand Down
13 changes: 1 addition & 12 deletions src/modules/essentialObsidian/ModuleObsidianAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
9 changes: 5 additions & 4 deletions src/modules/features/ModuleLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"strictFunctionTypes": true
},
"include": ["**/*.ts"],
"exclude": ["pouchdb-browser-webpack", "utils", "src/modules/coreObsidian/devUtil/tests.ts", "src/lib/src/API/**"]
"exclude": ["pouchdb-browser-webpack", "utils"]
}
Loading

0 comments on commit 095a3d2

Please sign in to comment.