add default setting to noteshare.space

This commit is contained in:
Maxime Cannoodt 2022-07-06 18:16:51 +02:00
parent b3a2995a79
commit 6e00255a8b
3 changed files with 50 additions and 11 deletions

View File

@ -13,10 +13,8 @@ import { SharedNoteSuccessModal } from "src/ui/SharedNoteSuccessModal";
import type { EventRef } from "obsidian"; import type { EventRef } from "obsidian";
import type { PluginSettings } from "src/obsidian/PluginSettings"; import type { PluginSettings } from "src/obsidian/PluginSettings";
// Remember to rename these classes and interfaces!
export default class NoteSharingPlugin extends Plugin { export default class NoteSharingPlugin extends Plugin {
private settings: PluginSettings; public settings: PluginSettings;
private noteSharingService: NoteSharingService; private noteSharingService: NoteSharingService;
private eventRef: EventRef; private eventRef: EventRef;

View File

@ -1,7 +1,9 @@
export interface PluginSettings { export interface PluginSettings {
serverUrl: string; serverUrl: string;
selfHosted: boolean;
} }
export const DEFAULT_SETTINGS: PluginSettings = { export const DEFAULT_SETTINGS: PluginSettings = {
serverUrl: "http://localhost:8080", serverUrl: "https://noteshare.space",
selfHosted: false,
}; };

View File

@ -1,12 +1,18 @@
import NoteSharingPlugin from "main"; import type NoteSharingPlugin from "main";
import { App, PluginSettingTab, Setting } from "obsidian"; import { App, PluginSettingTab, Setting, TextComponent } from "obsidian";
import { DEFAULT_SETTINGS } from "./PluginSettings";
export default class SettingsTab extends PluginSettingTab { export default class SettingsTab extends PluginSettingTab {
plugin: NoteSharingPlugin; plugin: NoteSharingPlugin;
private selfHostSettings: HTMLElement;
private hideSelfHosted: boolean;
private selfHostedUrl: TextComponent;
constructor(app: App, plugin: NoteSharingPlugin) { constructor(app: App, plugin: NoteSharingPlugin) {
super(app, plugin); super(app, plugin);
this.plugin = plugin; this.plugin = plugin;
this.hideSelfHosted = !plugin.settings.selfHosted;
} }
display(): void { display(): void {
@ -17,16 +23,49 @@ export default class SettingsTab extends PluginSettingTab {
containerEl.createEl("h2", { text: "Obsidian Note Sharing" }); containerEl.createEl("h2", { text: "Obsidian Note Sharing" });
new Setting(containerEl) new Setting(containerEl)
.setName("Use noteshare.space")
.setDesc(
"Noteshare.space is the official service for hosting your encrypted notes. Uncheck if you want to self-host."
)
.addToggle((text) =>
text
.setValue(!this.plugin.settings.selfHosted)
.onChange(async (value) => {
this.plugin.settings.selfHosted = !value;
this.showSelfhostedSettings(
this.plugin.settings.selfHosted
);
if (value === false) {
this.plugin.settings.serverUrl =
DEFAULT_SETTINGS.serverUrl;
this.selfHostedUrl.setValue(
this.plugin.settings.serverUrl
);
}
await this.plugin.saveSettings();
})
);
this.selfHostSettings = containerEl.createDiv();
this.selfHostSettings.createEl("h3", { text: "Self-hosting options" });
new Setting(this.selfHostSettings)
.setName("Server URL") .setName("Server URL")
.setDesc("Server URL hosting the encrypted notes.") .setDesc("Server URL hosting the encrypted notes.")
.addText((text) => .addText((text) => {
text this.selfHostedUrl = text;
.setPlaceholder("enter URL") text.setPlaceholder("enter URL")
.setValue(this.plugin.settings.serverUrl) .setValue(this.plugin.settings.serverUrl)
.onChange(async (value) => { .onChange(async (value) => {
this.plugin.settings.serverUrl = value; this.plugin.settings.serverUrl = value;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}) });
); });
this.showSelfhostedSettings(this.plugin.settings.selfHosted);
}
private showSelfhostedSettings(show: boolean) {
this.selfHostSettings.hidden = !show;
} }
} }