From 0e62a3b46b25e7c101b14ed44235f3c276982fc0 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 19 Mar 2021 21:19:42 -0400 Subject: Sweeping changes to switch to bootstrap and make the UI overall a bit more user friendly --- cmd/web/app.go | 4 +- cmd/web/handlers.go | 11 +- cmd/web/main.go | 16 +- cmd/web/static/main.js | 14 +- cmd/web/static/style.css | 81 -------- cmd/web/templates/index.html | 466 +++++++++++++++++++++++++++++++++++-------- readme.md | 9 + steam/steam.go | 8 + 8 files changed, 429 insertions(+), 180 deletions(-) delete mode 100644 cmd/web/static/style.css diff --git a/cmd/web/app.go b/cmd/web/app.go index 8f6df89..b0749b5 100644 --- a/cmd/web/app.go +++ b/cmd/web/app.go @@ -1,8 +1,8 @@ package main import ( - "sync" "html/template" + "sync" "time" "riedstra.dev/mitch/steam-export/steam" @@ -23,7 +23,6 @@ type statusInfo struct { Start *time.Time } - type App struct { Library *steamLib Status *statusInfo @@ -72,4 +71,3 @@ func (a *App) LibraryReload() { a.LibrarySet(cur) return } - diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index b8fa705..b9b863a 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -1,13 +1,13 @@ package main import ( - "fmt" - "strings" - "net/url" - "os" "encoding/json" + "fmt" "io" "net/http" + "net/url" + "os" + "strings" "time" "github.com/gorilla/mux" @@ -197,11 +197,10 @@ func (a *App) HandleSetLib(w http.ResponseWriter, r *http.Request) { func HandleQuit(w http.ResponseWriter, r *http.Request) { Logger.Println("Quit was called, exiting") w.Header().Add("Content-type", "text/plain") - w.Write([]byte("Shutting down...")) + w.Write([]byte("Shutting down... feel free to close this")) go func() { time.Sleep(time.Second * 2) os.Exit(0) }() return } - diff --git a/cmd/web/main.go b/cmd/web/main.go index 45b64ae..da0bebd 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -5,10 +5,10 @@ import ( "flag" "fmt" "log" - "math/rand" "net/http" "os" - "time" + "strconv" + "strings" "github.com/gorilla/mux" ) @@ -66,8 +66,16 @@ func main() { err = s.ListenAndServe() if err != nil { Logger.Printf("Encountered: %s", err) - rand.Seed(time.Now().UnixNano()) - Listen = fmt.Sprintf(":%d", rand.Intn(9000)+1024) + + parts := strings.Split(Listen, ":") + port, err := strconv.Atoi(parts[1]) + if err != nil { + panic(err) + } + port += 1 + + Listen = fmt.Sprintf("%s:%d", parts[0], port) + Logger.Printf("Trying: %s", Listen) s.Addr = Listen } diff --git a/cmd/web/static/main.js b/cmd/web/static/main.js index 55edf0c..b793be4 100644 --- a/cmd/web/static/main.js +++ b/cmd/web/static/main.js @@ -22,7 +22,8 @@ function formatDuration(dur) { } function setStatus(stat) { - var elem = document.getElementById("installBar"); + var barContainer = document.getElementById("installBarContainer"); + var elem = document.getElementById("installBar"); var msg = document.getElementById("message"); // console.log(stat) @@ -42,7 +43,9 @@ function setStatus(stat) { elem.style.width = percent + "%"; elem.innerHTML = percent + "%"; - elem.style.display = ""; + barContainer.style.display = ""; + + elem.ariaValueNow = percent; // in seconds var eta = Math.round(((stat.Size - trans)/1024/1024) / rate); @@ -56,8 +59,11 @@ function setStatus(stat) { if(!stat.Running && stat.Transferred >= 50 && stat.Error == null) { elem.style.width = 100 + "%"; elem.innerHTML = 100 + "%"; + elem.ariaValueNow = 100; + msg.innerHTML = "Completed install for: " + stat.Url; - elem.style.display = ""; + + barContainer.style.display = ""; msg.style.display = ""; } @@ -65,7 +71,7 @@ function setStatus(stat) { msg.innerHTML = "Errors encountered while installing from: \n\n" + stat.Url + "\n\n" + JSON.stringify(stat.Error, undefined, 2); - elem.style.display = "hidden"; + barContainer.style.display = "hidden"; msg.style.display = ""; } } diff --git a/cmd/web/static/style.css b/cmd/web/static/style.css deleted file mode 100644 index ba648e3..0000000 --- a/cmd/web/static/style.css +++ /dev/null @@ -1,81 +0,0 @@ -nav { - border-bottom: 3px solid #000; - padding-bottom: 10px; -} -a { - text-decoration: none; - color: #268bd2; -} -a:visited { - color: #d22653; -} -a:hover { - text-decoration: underline; -} -pre code { - line-height: 1.1; - overflow: auto; -} - -code { - color: #9672d5; - font-size: .8em; - font-family: "Roboto Mono", "Monaco", "Lucida Console", "DejaVu Sans Mono", -"monospace"; -} - -pre code { - color: #000; - background-color: #FFFFEA; - display: block; - padding: 10px; - border: 1px solid; -} - -blockquote { - border-left: 4px solid #aaa; - padding-left: 1em; -} - -body { - margin: 40px auto; - max-width: 80%; - line-height: 1.6; - font-size: 1em; - color: #444; - padding: 0 10px; - /* Added because some browsers don't default to white */ - background-color: #fff; -} - -img { - width: 100%; - height: auto; -} - -h1,h2,h3 { - line-height: 1.2 -} - -@media screen and (min-width: 1200px) { - body { - max-width: 960px; - } -} - - -#status { - width: 100%; - background-color: #ddd; -} - -.installBar { - width: 0%; - height: 30px; - /* background-color: #4CAF50; */ - background-color: #268bd2; - text-align: center; - line-height: 30px; - color: white; -} - diff --git a/cmd/web/templates/index.html b/cmd/web/templates/index.html index 74f2298..eaaf722 100644 --- a/cmd/web/templates/index.html +++ b/cmd/web/templates/index.html @@ -2,115 +2,417 @@ - + + Steam Game index -