Improve settings (#168)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Andras Schmelczer 2025-11-19 19:53:10 +00:00 committed by GitHub
parent e75298c4f1
commit c08feba0ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 302 additions and 128 deletions

View file

@ -11,8 +11,6 @@ import { HistoryView } from "./views/history/history-view";
import { StatusBar } from "./views/status-bar/status-bar";
import { LogsView } from "./views/logs/logs-view";
import { StatusDescription } from "./views/status-description/status-description";
import * as Sentry from "@sentry/browser";
import { init as plausibleInit } from "@plausible-analytics/tracker";
import {
SyncClient,
rateLimit,
@ -50,45 +48,6 @@ export default class VaultLinkPlugin extends Plugin {
".trash/**"
);
plausibleInit({
domain: "vault-link",
endpoint: "https://stats.schmelczer.dev/status",
autoCapturePageviews: true,
captureOnLocalhost: true,
logging: true
});
Sentry.init({
dsn: "https://56accd39d92442e788a457a04623cf57@bugs.schmelczer.dev/1",
skipBrowserExtensionCheck: false
});
const onError = (event: ErrorEvent): void => {
Sentry.captureException(event.error, {
extra: {
message: event.message,
filename: event.filename,
lineno: event.lineno,
colno: event.colno
}
});
};
window.addEventListener("error", onError);
this.disposables.push(() => {
window.removeEventListener("error", onError);
});
const onUnhandledRejection = (event: PromiseRejectionEvent): void => {
Sentry.captureException(event.reason);
};
window.addEventListener("unhandledrejection", onUnhandledRejection);
this.disposables.push(() => {
window.removeEventListener(
"unhandledrejection",
onUnhandledRejection
);
});
const isDebugBuild = process.env.NODE_ENV === "development";
const debugOptions = isDebugBuild
? {

View file

@ -33,7 +33,7 @@ export class RemoteCursorsPluginValue implements PluginValue {
isOutdated: boolean;
}[] = [];
private static app: App;
private static app?: App;
public decorations: DecorationSet = RangeSet.of([]);
public static setCursors(
@ -88,7 +88,7 @@ export class RemoteCursorsPluginValue implements PluginValue {
private static findFileForEditor(
editor: EditorView
): RelativePath | undefined {
return RemoteCursorsPluginValue.app.workspace
return RemoteCursorsPluginValue.app?.workspace
.getLeavesOfType("markdown")
.map((leaf) => leaf.view)
.filter((view) => view instanceof MarkdownView)

View file

@ -72,6 +72,7 @@ export class SyncSettingsTab extends PluginSettingTab {
this.renderSettingsHeader(containerEl);
this.renderConnectionSettings(containerEl);
this.renderSyncSettings(containerEl);
this.renderMiscSettings(containerEl);
}
public hide(): void {
@ -193,38 +194,28 @@ export class SyncSettingsTab extends PluginSettingTab {
})
);
new Setting(containerEl)
.addButton((button) =>
button.setButtonText("Apply").onClick(async () => {
new Setting(containerEl).addButton((button) =>
button
.setButtonText("Apply & test connection")
.onClick(async () => {
if (this.areThereUnsavedChanges()) {
await this.syncClient.setSettings({
vaultName: this.editedVaultName,
remoteUri: this.editedServerUri,
token: this.editedToken
});
new Notice("Checking connection to the server...");
new Notice(
"The changes have been applied successfully!"
(
await this.syncClient.checkConnection()
).serverMessage
);
await this.statusDescription.updateConnectionState();
} else {
new Notice("No changes to apply");
}
})
)
.addButton((button) =>
button.setButtonText("Test connection").onClick(async () => {
if (this.areThereUnsavedChanges()) {
new Notice(
"There are unsaved changes, testing with the currently saved settings"
);
}
new Notice(
(await this.syncClient.checkConnection()).serverMessage
);
await this.statusDescription.updateConnectionState();
})
);
);
}
private areThereUnsavedChanges(): boolean {
@ -339,6 +330,26 @@ export class SyncSettingsTab extends PluginSettingTab {
);
}
private renderMiscSettings(containerEl: HTMLElement): void {
containerEl.createEl("h3", { text: "Other" });
new Setting(containerEl)
.setName("Enable telemetry")
.setDesc(
"Allow sending anonymous usage data & error reports to help improve the plugin. The data collected is never shared with third parties."
)
.setTooltip(
"Allow sending anonymous usage data & error reports to help improve the plugin. The data collected is never shared with third parties."
)
.addToggle((toggle) =>
toggle
.setValue(this.syncClient.getSettings().enableTelemetry)
.onChange(async (value) =>
this.syncClient.setSetting("enableTelemetry", value)
)
);
}
private setStatusDescriptionSubscription(
newSubscription?: () => unknown
): void {