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

View file

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

View file

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

View file

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

View file

@ -39,7 +39,7 @@ export class Settings {
private readonly onSettingsChangeHandlers: ((
newSettings: SyncSettings,
oldSettings: SyncSettings
) => Promise<unknown> | unknown)[] = [];
) => unknown)[] = [];
public constructor(
private readonly logger: Logger,
@ -86,7 +86,9 @@ export class Settings {
public async setSettings(value: Partial<SyncSettings>): Promise<void> {
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;
this.settings = {
...this.settings,

View file

@ -4,6 +4,8 @@ import assert from "node:assert";
import { WebSocketManager } from "./websocket-manager";
import type { Logger } from "../tracing/logger";
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 {
public code: number;

View file

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