From 6e00255a8bb9afabf0829725e864adef4ece4b7c Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Wed, 6 Jul 2022 18:16:51 +0200 Subject: [PATCH] add default setting to noteshare.space --- plugin/main.ts | 4 +- plugin/src/obsidian/PluginSettings.ts | 4 +- plugin/src/obsidian/SettingsTab.ts | 53 +++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/plugin/main.ts b/plugin/main.ts index 8d14162..801b2dd 100644 --- a/plugin/main.ts +++ b/plugin/main.ts @@ -13,10 +13,8 @@ import { SharedNoteSuccessModal } from "src/ui/SharedNoteSuccessModal"; import type { EventRef } from "obsidian"; import type { PluginSettings } from "src/obsidian/PluginSettings"; -// Remember to rename these classes and interfaces! - export default class NoteSharingPlugin extends Plugin { - private settings: PluginSettings; + public settings: PluginSettings; private noteSharingService: NoteSharingService; private eventRef: EventRef; diff --git a/plugin/src/obsidian/PluginSettings.ts b/plugin/src/obsidian/PluginSettings.ts index 43cc087..735352c 100644 --- a/plugin/src/obsidian/PluginSettings.ts +++ b/plugin/src/obsidian/PluginSettings.ts @@ -1,7 +1,9 @@ export interface PluginSettings { serverUrl: string; + selfHosted: boolean; } export const DEFAULT_SETTINGS: PluginSettings = { - serverUrl: "http://localhost:8080", + serverUrl: "https://noteshare.space", + selfHosted: false, }; diff --git a/plugin/src/obsidian/SettingsTab.ts b/plugin/src/obsidian/SettingsTab.ts index 0df1994..5a60f6c 100644 --- a/plugin/src/obsidian/SettingsTab.ts +++ b/plugin/src/obsidian/SettingsTab.ts @@ -1,12 +1,18 @@ -import NoteSharingPlugin from "main"; -import { App, PluginSettingTab, Setting } from "obsidian"; +import type NoteSharingPlugin from "main"; +import { App, PluginSettingTab, Setting, TextComponent } from "obsidian"; +import { DEFAULT_SETTINGS } from "./PluginSettings"; export default class SettingsTab extends PluginSettingTab { plugin: NoteSharingPlugin; + private selfHostSettings: HTMLElement; + private hideSelfHosted: boolean; + private selfHostedUrl: TextComponent; + constructor(app: App, plugin: NoteSharingPlugin) { super(app, plugin); this.plugin = plugin; + this.hideSelfHosted = !plugin.settings.selfHosted; } display(): void { @@ -17,16 +23,49 @@ export default class SettingsTab extends PluginSettingTab { containerEl.createEl("h2", { text: "Obsidian Note Sharing" }); 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") .setDesc("Server URL hosting the encrypted notes.") - .addText((text) => - text - .setPlaceholder("enter URL") + .addText((text) => { + this.selfHostedUrl = text; + text.setPlaceholder("enter URL") .setValue(this.plugin.settings.serverUrl) .onChange(async (value) => { this.plugin.settings.serverUrl = value; await this.plugin.saveSettings(); - }) - ); + }); + }); + this.showSelfhostedSettings(this.plugin.settings.selfHosted); + } + + private showSelfhostedSettings(show: boolean) { + this.selfHostSettings.hidden = !show; } }