Configure line-endings

This commit is contained in:
Andras Schmelczer 2025-03-22 12:01:27 +00:00
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 type { WorkspaceLeaf } from "obsidian";
import { Plugin } from "obsidian"; import { Platform, Plugin } from "obsidian";
import "./styles.scss"; import "./styles.scss";
import "../manifest.json"; import "../manifest.json";
import { SyncSettingsTab } from "./views/settings-tab"; import { SyncSettingsTab } from "./views/settings-tab";
@ -37,13 +37,14 @@ export default class VaultLinkPlugin extends Plugin {
} }
public async onload(): Promise<void> { public async onload(): Promise<void> {
this.client = await SyncClient.create( this.client = await SyncClient.create({
new ObsidianFileSystemOperations(this.app.vault), fs: new ObsidianFileSystemOperations(this.app.vault),
{ persistence: {
load: this.loadData.bind(this), load: this.loadData.bind(this),
save: this.saveData.bind(this) save: this.saveData.bind(this)
} },
); nativeLineEndings: Platform.isWin ? "\r\n" : "\n"
});
VaultLinkPlugin.registerConsoleForLogging(this.client); VaultLinkPlugin.registerConsoleForLogging(this.client);

View file

@ -40,16 +40,22 @@ export class SyncClient {
return this._database.length; return this._database.length;
} }
public static async create( public static async create({
fs: FileSystemOperations, fs,
persistence,
fetch = globalThis.fetch,
nativeLineEndings = "\n"
}: {
fs: FileSystemOperations;
persistence: PersistenceProvider< persistence: PersistenceProvider<
Partial<{ Partial<{
settings: Partial<SyncSettings>; settings: Partial<SyncSettings>;
database: Partial<StoredDatabase>; database: Partial<StoredDatabase>;
}> }>
>, >;
fetch: typeof globalThis.fetch = globalThis.fetch fetch?: typeof globalThis.fetch;
): Promise<SyncClient> { nativeLineEndings?: string;
}): Promise<SyncClient> {
const logger = new Logger(); const logger = new Logger();
logger.info("Starting SyncClient"); logger.info("Starting SyncClient");
@ -91,7 +97,7 @@ export class SyncClient {
database, database,
settings, settings,
syncService, syncService,
new FileOperations(logger, database, fs), new FileOperations(logger, database, fs, nativeLineEndings),
history history
); );

View file

@ -19,14 +19,14 @@ export class MockClient implements FileSystemOperations {
public async init( public async init(
fetchImplementation: typeof globalThis.fetch fetchImplementation: typeof globalThis.fetch
): Promise<void> { ): Promise<void> {
this.client = await SyncClient.create( this.client = await SyncClient.create({
this, fs: this,
{ persistence: {
load: async () => this.data, load: async () => this.data,
save: async (data) => void (this.data = data) save: async (data) => void (this.data = data)
}, },
fetchImplementation fetch: fetchImplementation
); });
await Promise.all( await Promise.all(
Object.keys(this.initialSettings).map(async (key) => { Object.keys(this.initialSettings).map(async (key) => {