add default setting to noteshare.space
This commit is contained in:
parent
b3a2995a79
commit
6e00255a8b
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user