Open browser when starting server with --webui

Close #15
This commit is contained in:
Joshua Ramon Enslin 2025-03-04 14:26:35 +01:00
parent e3ac9e9b41
commit 1f81d48aad
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 37 additions and 7 deletions

View File

@ -357,7 +357,7 @@ class App {
const aside = document.createElement("div");
aside.classList.add("sec-aside");
aside.appendChild(this.generateTextElement("h3", this.tls.parser));
aside.appendChild(this.generateTextElement("h3", this.tls.parser + ": " + parser.title));
const div = document.createElement("div");
div.classList.add("parser-desc");

View File

@ -4,12 +4,35 @@ import (
"fmt"
"log"
"net/http"
"os/exec"
"runtime"
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
)
var config configloader.MDWebDavUploaderConfig
var setupRequired bool
// Opens the application in the default browser.
func openInBrowser(port string) {
var err error
target := "localhost:" + port
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", target).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", target).Start()
case "darwin":
err = exec.Command("open", target).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
fmt.Println(err)
}
}
// Sets up the server and manages routing.
func Run() {
@ -29,12 +52,19 @@ func Run() {
http.HandleFunc("/logo.svg", serveLogo) // Logo.
port := "8080"
go func() {
// Set port to listen on
fmt.Println("Server started at port " + string(port))
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
// Set port to listen on
fmt.Println("Server started at port " + string(port))
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}();
go func() {
openInBrowser(port)
}();
select {}
}