Run lint & fmt

This commit is contained in:
Andras Schmelczer 2025-11-30 14:52:20 +00:00
parent c7c96b787a
commit 9349afc00f
7 changed files with 73 additions and 47 deletions

View file

@ -43,12 +43,14 @@ export default class VaultLinkPlugin extends Plugin {
public async onload(): Promise<void> { public async onload(): Promise<void> {
this.app.workspace.onLayoutReady(async () => { this.app.workspace.onLayoutReady(async () => {
// eslint-disable-next-line
if ((globalThis as any).VAULT_LINK_RUNNING_INSTANCE) { if ((globalThis as any).VAULT_LINK_RUNNING_INSTANCE) {
new Notice( new Notice(
"Another instance of VaultLink is already running. Please disable the duplicate instance." "Another instance of VaultLink is already running. Please disable the duplicate instance."
); );
throw new Error("VaultLink instance already running"); throw new Error("VaultLink instance already running");
} }
// eslint-disable-next-line
(globalThis as any).VAULT_LINK_RUNNING_INSTANCE = this; (globalThis as any).VAULT_LINK_RUNNING_INSTANCE = this;
const client = await this.createSyncClient(); const client = await this.createSyncClient();
@ -199,6 +201,7 @@ export default class VaultLinkPlugin extends Plugin {
}); });
this.register(() => { this.register(() => {
// eslint-disable-next-line
(globalThis as any).VAULT_LINK_RUNNING_INSTANCE = null; (globalThis as any).VAULT_LINK_RUNNING_INSTANCE = null;
}); });
} }

View file

@ -78,14 +78,18 @@ export class LogsView extends ItemView {
text: "VaultLink logs" text: "VaultLink logs"
}); });
const controls = verbositySection.createDiv({ cls: "logs-controls" }); const controls = verbositySection.createDiv({
cls: "logs-controls"
});
const copyButton = controls.createEl("button", { const copyButton = controls.createEl("button", {
text: "Copy logs", text: "Copy logs",
cls: "clickable-icon" cls: "clickable-icon"
}); });
setIcon(copyButton, "clipboard-copy"); setIcon(copyButton, "clipboard-copy");
copyButton.addEventListener("click", () => { this.copyLogsToClipboard(); }); copyButton.addEventListener("click", () => {
this.copyLogsToClipboard();
});
controls.createEl("select", {}, (dropdown) => { controls.createEl("select", {}, (dropdown) => {
logLevels.forEach(({ label, value }) => logLevels.forEach(({ label, value }) =>
@ -127,12 +131,15 @@ export class LogsView extends ItemView {
}) })
.join("\n"); .join("\n");
navigator.clipboard.writeText(formattedLogs) navigator.clipboard
.writeText(formattedLogs)
.then(() => { .then(() => {
new Notice(`Copied ${logs.length} log entries to clipboard`); new Notice(`Copied ${logs.length} log entries to clipboard`);
}) })
.catch((error: unknown) => { .catch((error: unknown) => {
this.client.logger.error(`Failed to copy logs to clipboard: ${error}`); this.client.logger.error(
`Failed to copy logs to clipboard: ${error}`
);
new Notice("Failed to copy logs to clipboard"); new Notice("Failed to copy logs to clipboard");
}); });
} }

View file

@ -73,7 +73,7 @@ export class SyncSettingsTab extends PluginSettingTab {
private set isApplyingChanges(value: boolean) { private set isApplyingChanges(value: boolean) {
this._isApplyingChanges = value; this._isApplyingChanges = value;
this.display() this.display();
} }
public display(): void { public display(): void {
@ -157,10 +157,10 @@ export class SyncSettingsTab extends PluginSettingTab {
text: "Show history" text: "Show history"
}, },
(button) => (button) =>
(button.onclick = async (): Promise<void> => { (button.onclick = async (): Promise<void> => {
this.plugin.closeSettings(); this.plugin.closeSettings();
await this.plugin.activateView(HistoryView.TYPE); await this.plugin.activateView(HistoryView.TYPE);
}) })
); );
buttonContainer.createEl( buttonContainer.createEl(
@ -169,10 +169,10 @@ export class SyncSettingsTab extends PluginSettingTab {
text: "Show logs" text: "Show logs"
}, },
(button) => (button) =>
(button.onclick = async (): Promise<void> => { (button.onclick = async (): Promise<void> => {
this.plugin.closeSettings(); this.plugin.closeSettings();
await this.plugin.activateView(LogsView.TYPE); await this.plugin.activateView(LogsView.TYPE);
}) })
); );
} }
); );
@ -251,7 +251,7 @@ export class SyncSettingsTab extends PluginSettingTab {
) )
.onClick(() => { .onClick(() => {
// don't show loader within the button // don't show loader within the button
void (async () => { void (async (): Promise<void> => {
if (this.areThereUnsavedChanges()) { if (this.areThereUnsavedChanges()) {
new Notice("Applying changes to the server..."); new Notice("Applying changes to the server...");
@ -302,24 +302,31 @@ export class SyncSettingsTab extends PluginSettingTab {
) )
.addToggle((toggle) => .addToggle((toggle) =>
toggle toggle
.setValue(this.syncEnabledOverride ?? this.syncClient.getSettings().isSyncEnabled) .setValue(
this.syncEnabledOverride ??
this.syncClient.getSettings().isSyncEnabled
)
.setDisabled(this.isApplyingChanges) .setDisabled(this.isApplyingChanges)
.setTooltip( .setTooltip(
this.isApplyingChanges this.isApplyingChanges
? "Waiting for applying changes to finish..." ? "Waiting for applying changes to finish..."
: "Enable or disable syncing." : "Enable or disable syncing."
) )
.onChange((value) => void (async () => { .onChange(
this.syncEnabledOverride = value; (value) =>
this.isApplyingChanges = true; void (async (): Promise<void> => {
try { this.syncEnabledOverride = value;
await this.syncClient.setSetting("isSyncEnabled", value); this.isApplyingChanges = true;
} finally { try {
this.syncEnabledOverride = undefined; await this.syncClient.setSetting(
this.isApplyingChanges = false; "isSyncEnabled",
} value
} );
)() } finally {
this.syncEnabledOverride = undefined;
this.isApplyingChanges = false;
}
})()
) )
); );
@ -407,18 +414,21 @@ export class SyncSettingsTab extends PluginSettingTab {
: "Reset sync state" : "Reset sync state"
) )
.setButtonText("Reset sync state") .setButtonText("Reset sync state")
.onClick(() => void (async () => { .onClick(
this.isApplyingChanges = true; () =>
try { void (async (): Promise<void> => {
await this.syncClient.reset(); this.isApplyingChanges = true;
} finally { try {
this.isApplyingChanges = false; await this.syncClient.reset();
} } finally {
this.isApplyingChanges = false;
}
new Notice( new Notice(
"Sync state has been reset, you will need to resync" "Sync state has been reset, you will need to resync"
); );
})()) })()
)
); );
} }
@ -533,9 +543,9 @@ export class SyncSettingsTab extends PluginSettingTab {
name: string, name: string,
settingName: keyof SyncSettings settingName: keyof SyncSettings
): [ ): [
DocumentFragment, DocumentFragment,
(newValue: SyncSettings[keyof SyncSettings]) => unknown (newValue: SyncSettings[keyof SyncSettings]) => unknown
] { ] {
const titleContainer = document.createDocumentFragment(); const titleContainer = document.createDocumentFragment();
const title = titleContainer.createEl("div", { const title = titleContainer.createEl("div", {
text: name, text: name,
@ -545,10 +555,11 @@ export class SyncSettingsTab extends PluginSettingTab {
const updateTitle = ( const updateTitle = (
currentValue: SyncSettings[keyof SyncSettings] currentValue: SyncSettings[keyof SyncSettings]
): void => { ): void => {
title.innerText = `${name}${currentValue !== this.syncClient.getSettings()[settingName] title.innerText = `${name}${
? " (unsaved)" currentValue !== this.syncClient.getSettings()[settingName]
: "" ? " (unsaved)"
}`; : ""
}`;
}; };
return [titleContainer, updateTitle]; return [titleContainer, updateTitle];

View file

@ -268,6 +268,7 @@ export class FileOperations {
let newName = path; let newName = path;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) { while (true) {
currentCount++; currentCount++;
newName = `${directory}${stem} (${currentCount})${extension}`; newName = `${directory}${stem} (${currentCount})${extension}`;

View file

@ -39,7 +39,7 @@ export class Settings {
private readonly onSettingsChangeHandlers: (( private readonly onSettingsChangeHandlers: ((
newSettings: SyncSettings, newSettings: SyncSettings,
oldSettings: SyncSettings oldSettings: SyncSettings
) => Promise<unknown> | unknown)[] = []; ) => unknown)[] = [];
public constructor( public constructor(
private readonly logger: Logger, private readonly logger: Logger,
@ -86,7 +86,9 @@ export class Settings {
public async setSettings(value: Partial<SyncSettings>): Promise<void> { public async setSettings(value: Partial<SyncSettings>): Promise<void> {
await this.lock.withLock(async () => { await this.lock.withLock(async () => {
this.logger.debug(`Updating settings with: ${JSON.stringify(value)}`); this.logger.debug(
`Updating settings with: ${JSON.stringify(value)}`
);
const oldSettings = this.settings; const oldSettings = this.settings;
this.settings = { this.settings = {
...this.settings, ...this.settings,

View file

@ -4,6 +4,8 @@ import assert from "node:assert";
import { WebSocketManager } from "./websocket-manager"; import { WebSocketManager } from "./websocket-manager";
import type { Logger } from "../tracing/logger"; import type { Logger } from "../tracing/logger";
import type { Settings } from "../persistence/settings"; import type { Settings } from "../persistence/settings";
// eslint-disable-next-line @typescript-eslint/no-require-imports
const WebSocket = require("ws") as typeof globalThis.WebSocket;
class MockCloseEvent extends Event { class MockCloseEvent extends Event {
public code: number; public code: number;

View file

@ -173,7 +173,7 @@ export class Syncer {
// in that case, we mustn't move it again. // in that case, we mustn't move it again.
if ( if (
this.database.getLatestDocumentByRelativePath(relativePath) === this.database.getLatestDocumentByRelativePath(relativePath) ===
undefined || undefined ||
this.database.getLatestDocumentByRelativePath(relativePath) this.database.getLatestDocumentByRelativePath(relativePath)
?.isDeleted === true ?.isDeleted === true
) { ) {