From d885646f396b86f12c8c87d900849c47e7c323a0 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 22 Mar 2025 12:01:27 +0000 Subject: [PATCH] Configure line-endings --- .../obsidian-plugin/src/vault-link-plugin.ts | 13 +++++++------ frontend/sync-client/src/sync-client.ts | 18 ++++++++++++------ frontend/test-client/src/agent/mock-client.ts | 10 +++++----- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/frontend/obsidian-plugin/src/vault-link-plugin.ts b/frontend/obsidian-plugin/src/vault-link-plugin.ts index bf19d37c..435cecd1 100644 --- a/frontend/obsidian-plugin/src/vault-link-plugin.ts +++ b/frontend/obsidian-plugin/src/vault-link-plugin.ts @@ -1,5 +1,5 @@ import type { WorkspaceLeaf } from "obsidian"; -import { Plugin } from "obsidian"; +import { Platform, Plugin } from "obsidian"; import "./styles.scss"; import "../manifest.json"; import { SyncSettingsTab } from "./views/settings-tab"; @@ -37,13 +37,14 @@ export default class VaultLinkPlugin extends Plugin { } public async onload(): Promise { - this.client = await SyncClient.create( - new ObsidianFileSystemOperations(this.app.vault), - { + this.client = await SyncClient.create({ + fs: new ObsidianFileSystemOperations(this.app.vault), + persistence: { load: this.loadData.bind(this), save: this.saveData.bind(this) - } - ); + }, + nativeLineEndings: Platform.isWin ? "\r\n" : "\n" + }); VaultLinkPlugin.registerConsoleForLogging(this.client); diff --git a/frontend/sync-client/src/sync-client.ts b/frontend/sync-client/src/sync-client.ts index 3def68f9..86d634ab 100644 --- a/frontend/sync-client/src/sync-client.ts +++ b/frontend/sync-client/src/sync-client.ts @@ -40,16 +40,22 @@ export class SyncClient { return this._database.length; } - public static async create( - fs: FileSystemOperations, + public static async create({ + fs, + persistence, + fetch = globalThis.fetch, + nativeLineEndings = "\n" + }: { + fs: FileSystemOperations; persistence: PersistenceProvider< Partial<{ settings: Partial; database: Partial; }> - >, - fetch: typeof globalThis.fetch = globalThis.fetch - ): Promise { + >; + fetch?: typeof globalThis.fetch; + nativeLineEndings?: string; + }): Promise { const logger = new Logger(); logger.info("Starting SyncClient"); @@ -91,7 +97,7 @@ export class SyncClient { database, settings, syncService, - new FileOperations(logger, database, fs), + new FileOperations(logger, database, fs, nativeLineEndings), history ); diff --git a/frontend/test-client/src/agent/mock-client.ts b/frontend/test-client/src/agent/mock-client.ts index 9d4d457e..9f3483cb 100644 --- a/frontend/test-client/src/agent/mock-client.ts +++ b/frontend/test-client/src/agent/mock-client.ts @@ -19,14 +19,14 @@ export class MockClient implements FileSystemOperations { public async init( fetchImplementation: typeof globalThis.fetch ): Promise { - this.client = await SyncClient.create( - this, - { + this.client = await SyncClient.create({ + fs: this, + persistence: { load: async () => this.data, save: async (data) => void (this.data = data) }, - fetchImplementation - ); + fetch: fetchImplementation + }); await Promise.all( Object.keys(this.initialSettings).map(async (key) => {