From 437d74280f2057d055e06f7aed8c743da1f55980 Mon Sep 17 00:00:00 2001 From: Juan X Gomez Date: Tue, 19 Jul 2022 23:23:10 -0400 Subject: [PATCH] add a way to manually rotate the image add buttons to hit the orientation endpoint only if autorotate is disabled --- client/index.go | 28 ++++++++++++++++++++++++++++ client/main.go | 9 +++++++-- internal/client/orientation.go | 15 +++++++-------- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/client/index.go b/client/index.go index 4845980..2ab7842 100644 --- a/client/index.go +++ b/client/index.go @@ -27,10 +27,38 @@ html, body { max-height: 100%; max-width: 100%; } +.orientation { + position: absolute; + top: 10px; + left: 10px; +} +.orientation button { + background-color: #04AA6D; + color: white; + padding: 12px 20px; + border: none; + border-radius: 4px; + cursor: pointer; + width: 100%; + margin-bottom: 10px; +}
+ {{ if not .AutoRotate }} +
+ +
+ + +
+
+ + +
+
+ {{end}} diff --git a/client/main.go b/client/main.go index c61106f..6824780 100644 --- a/client/main.go +++ b/client/main.go @@ -2,8 +2,8 @@ package main import ( "compress/zlib" + "html/template" "context" - "fmt" "log" "net/http" @@ -37,7 +37,12 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { - fmt.Fprint(w, index) + t := template.Must(template.New("index").Parse(index)) + err := t.Execute(w, c) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } }) mux.HandleFunc("/favicon.ico", faviconHandler) mux.HandleFunc("/screenshot", g.GetScreenshot) diff --git a/internal/client/orientation.go b/internal/client/orientation.go index 2502acf..0bd8c19 100644 --- a/internal/client/orientation.go +++ b/internal/client/orientation.go @@ -48,14 +48,13 @@ type rotation struct { } func (r *rotation) rotate(img *image.Gray) { - if !r.isActive { - return - } - switch { - case (isPortraitLeft(img.Pix) || isPortraitRight(img.Pix)) && r.orientation != portrait: - r.orientation = portrait - case (isLandscapeLeft(img.Pix) || isLandscapeRight(img.Pix)) && r.orientation != landscape: - r.orientation = landscape + if r.isActive { + switch { + case (isPortraitLeft(img.Pix) || isPortraitRight(img.Pix)) && r.orientation != portrait: + r.orientation = portrait + case (isLandscapeLeft(img.Pix) || isLandscapeRight(img.Pix)) && r.orientation != landscape: + r.orientation = landscape + } } if r.orientation == portrait { rotate(img)