diff --git a/main.go b/main.go index 373a1aa..8523cae 100644 --- a/main.go +++ b/main.go @@ -38,9 +38,10 @@ type timerConfig struct { } type config struct { - Osc map[string]string - Web map[string]string - Timers []timerConfig + Osc map[string]string + Web map[string]string + Darkmode bool + Timers []timerConfig } func main() { @@ -123,7 +124,7 @@ func main() { if err != nil { log.Fatalf("Unable to parse port for web server from '%s': %s", Config.Web["port"], err) } - runWebServer(Config.Web["bind"], webPort, ctx) + runWebServer(Config.Web["bind"], webPort, Config.Darkmode, ctx) oscPort, err := strconv.Atoi(Config.Osc["port"]) if err != nil { diff --git a/timers.html b/templates/base.html similarity index 97% rename from timers.html rename to templates/base.html index 9618c5d..d99aa49 100644 --- a/timers.html +++ b/templates/base.html @@ -1,5 +1,7 @@ - +{{block "theme" .}} + +{{end}} diff --git a/templates/darkmode.html b/templates/darkmode.html new file mode 100644 index 0000000..77ed71f --- /dev/null +++ b/templates/darkmode.html @@ -0,0 +1,3 @@ +{{define "theme"}} + +{{end}} \ No newline at end of file diff --git a/webserver.go b/webserver.go index 2b084f5..717aed7 100644 --- a/webserver.go +++ b/webserver.go @@ -7,6 +7,7 @@ import ( "html/template" "log" "net/http" + "path/filepath" "strings" ) @@ -19,7 +20,10 @@ type timerValue struct { Running bool `json:"running"` } -func runWebServer(bindAddr string, bindPort int, ctx context.Context) { +var dm bool + +func runWebServer(bindAddr string, bindPort int, darkmode bool, ctx context.Context) { + dm = darkmode staticServer := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", staticServer)) http.HandleFunc("/timer/", timerValueHandler) @@ -43,7 +47,11 @@ func runWebServer(bindAddr string, bindPort int, ctx context.Context) { } func webHandler(w http.ResponseWriter, r *http.Request) { - t, err := template.ParseFiles("timers.html") + files := []string{filepath.Join("templates", "base.html")} + if dm { + files = append(files, filepath.Join("templates", "darkmode.html")) + } + t, err := template.ParseFiles(files...) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return