This commit is contained in:
Simon Cambier
2023-10-13 08:47:35 +02:00
parent fc6df5d36b
commit 9a218167d7
3 changed files with 70 additions and 51 deletions

View File

@@ -1,5 +1,6 @@
import {
Notice,
Platform,
Plugin,
PluginSettingTab,
Setting,
@@ -462,46 +463,48 @@ export class SettingsTab extends PluginSettingTab {
//#region HTTP Server
const httpServerDesc = new DocumentFragment()
httpServerDesc.createSpan({}, span => {
span.innerHTML = `Omnisearch can be used through a simple HTTP server (<a href="https://publish.obsidian.md/omnisearch/Public+API+%26+URL+Scheme#HTTP+Server">more information</a>).`
})
new Setting(containerEl)
.setName('API Access Through HTTP')
.setHeading()
.setDesc(httpServerDesc)
if (!Platform.isMobile) {
const httpServerDesc = new DocumentFragment()
httpServerDesc.createSpan({}, span => {
span.innerHTML = `Omnisearch can be used through a simple HTTP server (<a href="https://publish.obsidian.md/omnisearch/Public+API+%26+URL+Scheme#HTTP+Server">more information</a>).`
})
new Setting(containerEl)
.setName('API Access Through HTTP')
.setHeading()
.setDesc(httpServerDesc)
new Setting(containerEl)
.setName('Enable the HTTP server')
.addToggle(toggle =>
toggle.setValue(settings.httpApiEnabled).onChange(async v => {
settings.httpApiEnabled = v
if (v) {
this.plugin.apiHttpServer.listen(settings.httpApiPort)
} else {
this.plugin.apiHttpServer.close()
}
await saveSettings(this.plugin)
})
)
new Setting(containerEl)
.setName('Enable the HTTP server')
.addToggle(toggle =>
toggle.setValue(settings.httpApiEnabled).onChange(async v => {
settings.httpApiEnabled = v
if (v) {
this.plugin.apiHttpServer.listen(settings.httpApiPort)
} else {
this.plugin.apiHttpServer.close()
}
await saveSettings(this.plugin)
})
)
new Setting(containerEl).setName('HTTP Port').addText(component => {
component
.setValue(settings.httpApiPort)
.setPlaceholder('51361')
.onChange(async v => {
if (parseInt(v) > 65535) {
v = settings.httpApiPort
component.setValue(settings.httpApiPort)
}
settings.httpApiPort = v
if (settings.httpApiEnabled) {
this.plugin.apiHttpServer.close()
this.plugin.apiHttpServer.listen(settings.httpApiPort)
}
await saveSettings(this.plugin)
})
})
new Setting(containerEl).setName('HTTP Port').addText(component => {
component
.setValue(settings.httpApiPort)
.setPlaceholder('51361')
.onChange(async v => {
if (parseInt(v) > 65535) {
v = settings.httpApiPort
component.setValue(settings.httpApiPort)
}
settings.httpApiPort = v
if (settings.httpApiEnabled) {
this.plugin.apiHttpServer.close()
this.plugin.apiHttpServer.listen(settings.httpApiPort)
}
await saveSettings(this.plugin)
})
})
}
//#endregion HTTP Server