Improve settings (#168)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
e75298c4f1
commit
c08feba0ad
19 changed files with 301 additions and 127 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue