This commit is contained in:
Andras Schmelczer 2025-11-23 15:13:30 +00:00
parent 5a0c64d39c
commit fb2d82a06e
6 changed files with 18 additions and 16 deletions

View file

@ -1,8 +1,9 @@
import type { Stat, Vault, Workspace } from "obsidian"; import type { Stat, Vault, Workspace } from "obsidian";
import { MarkdownView, normalizePath } from "obsidian"; import { MarkdownView, normalizePath } from "obsidian";
import { import type {
CursorPosition, CursorPosition,
TextWithCursors, TextWithCursors} from "sync-client";
import {
utils, utils,
type FileSystemOperations, type FileSystemOperations,
type RelativePath type RelativePath

View file

@ -38,7 +38,7 @@ export default class VaultLinkPlugin extends Plugin {
() => Promise<unknown> () => Promise<unknown>
>(); >();
private syncClient: SyncClient | undefined; private readonly syncClient: SyncClient | undefined;
private settingsTab: SyncSettingsTab | undefined; private settingsTab: SyncSettingsTab | undefined;
public async onload(): Promise<void> { public async onload(): Promise<void> {
@ -152,7 +152,7 @@ export default class VaultLinkPlugin extends Plugin {
this.registerView(HistoryView.TYPE, (leaf) => { this.registerView(HistoryView.TYPE, (leaf) => {
const view = new HistoryView(client, leaf); const view = new HistoryView(client, leaf);
this.register(() => view.onClose()); this.register(async () => view.onClose());
return view; return view;
}); });
@ -180,7 +180,7 @@ export default class VaultLinkPlugin extends Plugin {
this.app.workspace, this.app.workspace,
client client
); );
this.register(() => editorStatusDisplayManager.dispose()); this.register(() => { editorStatusDisplayManager.dispose(); });
} }
private addRibbonIcons(): void { private addRibbonIcons(): void {

View file

@ -106,7 +106,7 @@ describe("FetchController", () => {
const controller = new FetchController(true, logger); const controller = new FetchController(true, logger);
assert.throws( assert.throws(
() => controller.finishReset(), () => { controller.finishReset(); },
(error: unknown) => (error: unknown) =>
error instanceof Error && error instanceof Error &&
error.message === "Cannot finish reset when not resetting" error.message === "Cannot finish reset when not resetting"

View file

@ -5,7 +5,7 @@ import type { WebSocketClientMessage } from "./types/WebSocketClientMessage";
import type { CursorPositionFromClient } from "./types/CursorPositionFromClient"; import type { CursorPositionFromClient } from "./types/CursorPositionFromClient";
import type { ClientCursors } from "./types/ClientCursors"; import type { ClientCursors } from "./types/ClientCursors";
import { createPromise } from "../utils/create-promise"; import { createPromise } from "../utils/create-promise";
import { WebSocketVaultUpdate } from "./types/WebSocketVaultUpdate"; import type { WebSocketVaultUpdate } from "./types/WebSocketVaultUpdate";
export class WebSocketManager { export class WebSocketManager {
private readonly webSocketStatusChangeListeners: (( private readonly webSocketStatusChangeListeners: ((
@ -26,7 +26,7 @@ export class WebSocketManager {
private resolveDisconnectingPromise: null | (() => unknown) = null; private resolveDisconnectingPromise: null | (() => unknown) = null;
private reconnectTimeoutId: ReturnType<typeof setTimeout> | undefined; private reconnectTimeoutId: ReturnType<typeof setTimeout> | undefined;
private readonly outstandingPromises: Array<Promise<unknown>> = []; private readonly outstandingPromises: Promise<unknown>[] = [];
private readonly webSocketFactoryImplementation: typeof globalThis.WebSocket; private readonly webSocketFactoryImplementation: typeof globalThis.WebSocket;
public constructor( public constructor(
@ -104,7 +104,7 @@ export class WebSocketManager {
public sendHandshakeMessage( public sendHandshakeMessage(
message: WebSocketClientMessage & { type: "handshake" } message: WebSocketClientMessage & { type: "handshake" }
): void { ): void {
const webSocket = this.webSocket; const {webSocket} = this;
if (!webSocket) { if (!webSocket) {
throw new Error( throw new Error(
"WebSocket is not connected, cannot send handshake message" "WebSocket is not connected, cannot send handshake message"
@ -126,7 +126,7 @@ export class WebSocketManager {
type: "cursorPositions", type: "cursorPositions",
...cursorPositions ...cursorPositions
}; };
const webSocket = this.webSocket; const {webSocket} = this;
if (!webSocket) { if (!webSocket) {
this.logger.warn( this.logger.warn(
"WebSocket is not connected, cannot send cursor positions" "WebSocket is not connected, cannot send cursor positions"
@ -194,7 +194,7 @@ export class WebSocketManager {
): Promise<void> { ): Promise<void> {
if (message.type === "vaultUpdate") { if (message.type === "vaultUpdate") {
this.outstandingPromises.push( this.outstandingPromises.push(
...this.remoteVaultUpdateListeners.map((listener) => ...this.remoteVaultUpdateListeners.map(async (listener) =>
listener(message) listener(message)
) )
); );
@ -204,7 +204,7 @@ export class WebSocketManager {
`Received cursor positions for ${JSON.stringify(message.clients)}` `Received cursor positions for ${JSON.stringify(message.clients)}`
); );
this.outstandingPromises.push( this.outstandingPromises.push(
...this.remoteCursorsUpdateListeners.map((listener) => ...this.remoteCursorsUpdateListeners.map(async (listener) =>
listener( listener(
message.clients.filter( message.clients.filter(
(client) => client.deviceId !== this.deviceId (client) => client.deviceId !== this.deviceId

View file

@ -77,7 +77,7 @@ export class SyncClient {
// Missing values will be filled in from DEFAULT_SETTINGS rather than // Missing values will be filled in from DEFAULT_SETTINGS rather than
// retaining current in-memory settings. // retaining current in-memory settings.
public async reloadSettings(): Promise<void> { public async reloadSettings(): Promise<void> {
let state = (await this.persistence.load()) ?? { const state = (await this.persistence.load()) ?? {
settings: undefined settings: undefined
}; };

View file

@ -1,11 +1,12 @@
import type { StoredDatabase } from "sync-client"; import type { StoredDatabase ,
TextWithCursors
} from "sync-client";
import { assert } from "../utils/assert"; import { assert } from "../utils/assert";
import { import {
type RelativePath, type RelativePath,
type FileSystemOperations, type FileSystemOperations,
type SyncSettings, type SyncSettings,
SyncClient, SyncClient
TextWithCursors
} from "sync-client"; } from "sync-client";
export class MockClient implements FileSystemOperations { export class MockClient implements FileSystemOperations {