diff --git a/.gitignore b/.gitignore index 3b735ec..249fcfe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# ignore site config +showtimer.yaml + # If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # diff --git a/README.md b/README.md index 9d49bb9..6188016 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Currently, most setup and startup of the program must be done from the command line (Windows CMD.EXE, MacOS Terminal, etc.). 1. unzip the bundle in a useful location, like your home directory -2. Edit the `showtimer.yaml` file with your favorite editor +2. Copy `showtimer_example.yaml` to a name of your choice. The default + is `showtimer.yaml`. Edit the file with your favorite editor. 3. Set the port values for the webserver and OSC (or note the defaults) 4. Optionally, if you would like to only listen on a certain interface, enter the IP address of that interface. This is probably not common. 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/showtimer.yaml b/showtimer_example.yaml similarity index 94% rename from showtimer.yaml rename to showtimer_example.yaml index 0e1bf30..be6c4a1 100644 --- a/showtimer.yaml +++ b/showtimer_example.yaml @@ -4,6 +4,7 @@ web: osc: #bind: 0.0.0.0 port: 8000 +darkmode: false timers: - name: Act 1 key: act1 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