Run lint & fmt
This commit is contained in:
parent
c7c96b787a
commit
9349afc00f
7 changed files with 73 additions and 47 deletions
|
|
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -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(
|
||||||
|
(value) =>
|
||||||
|
void (async (): Promise<void> => {
|
||||||
this.syncEnabledOverride = value;
|
this.syncEnabledOverride = value;
|
||||||
this.isApplyingChanges = true;
|
this.isApplyingChanges = true;
|
||||||
try {
|
try {
|
||||||
await this.syncClient.setSetting("isSyncEnabled", value);
|
await this.syncClient.setSetting(
|
||||||
|
"isSyncEnabled",
|
||||||
|
value
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
this.syncEnabledOverride = undefined;
|
this.syncEnabledOverride = undefined;
|
||||||
this.isApplyingChanges = false;
|
this.isApplyingChanges = false;
|
||||||
}
|
}
|
||||||
}
|
})()
|
||||||
)()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -407,7 +414,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
: "Reset sync state"
|
: "Reset sync state"
|
||||||
)
|
)
|
||||||
.setButtonText("Reset sync state")
|
.setButtonText("Reset sync state")
|
||||||
.onClick(() => void (async () => {
|
.onClick(
|
||||||
|
() =>
|
||||||
|
void (async (): Promise<void> => {
|
||||||
this.isApplyingChanges = true;
|
this.isApplyingChanges = true;
|
||||||
try {
|
try {
|
||||||
await this.syncClient.reset();
|
await this.syncClient.reset();
|
||||||
|
|
@ -418,7 +427,8 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
new Notice(
|
new Notice(
|
||||||
"Sync state has been reset, you will need to resync"
|
"Sync state has been reset, you will need to resync"
|
||||||
);
|
);
|
||||||
})())
|
})()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -545,7 +555,8 @@ 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}${
|
||||||
|
currentValue !== this.syncClient.getSettings()[settingName]
|
||||||
? " (unsaved)"
|
? " (unsaved)"
|
||||||
: ""
|
: ""
|
||||||
}`;
|
}`;
|
||||||
|
|
|
||||||
|
|
@ -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}`;
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue