Configure line-endings

This commit is contained in:
Andras Schmelczer 2025-03-22 12:01:27 +00:00
parent 087d38f570
commit d885646f39
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
3 changed files with 24 additions and 17 deletions

View file

@ -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<void> {
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);

View file

@ -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<SyncSettings>;
database: Partial<StoredDatabase>;
}>
>,
fetch: typeof globalThis.fetch = globalThis.fetch
): Promise<SyncClient> {
>;
fetch?: typeof globalThis.fetch;
nativeLineEndings?: string;
}): Promise<SyncClient> {
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
);

View file

@ -19,14 +19,14 @@ export class MockClient implements FileSystemOperations {
public async init(
fetchImplementation: typeof globalThis.fetch
): Promise<void> {
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) => {