From d67c1cfcf1dbe1dd9d3cfb9967ac5b55d3998d8c Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 16 Jan 2022 18:33:27 -0800 Subject: [PATCH] Send User-Agent of version/os/arch on update check --- pkg/branding/branding.go | 23 +++++++++++++++++++++-- pkg/main_scene.go | 20 ++++++++++++++++++++ pkg/modal/loadscreen/loadscreen.go | 2 -- pkg/updater/updater.go | 9 +++++++-- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/pkg/branding/branding.go b/pkg/branding/branding.go index 4cfab31..aa16918 100644 --- a/pkg/branding/branding.go +++ b/pkg/branding/branding.go @@ -1,15 +1,34 @@ package branding +import ( + "fmt" + "runtime" +) + // Constants for branding and version information. const ( AppName = "Sketchy Maze" Summary = "A drawing-based maze game" - Version = "0.10.1" + Version = "0.10.2" Website = "https://www.sketchymaze.com" - Copyright = "2021 Noah Petherbridge" + Copyright = "2022 Noah Petherbridge" Byline = "a game by Noah Petherbridge." // Update check URL UpdateCheckJSON = "https://download.sketchymaze.com/version.json" GuidebookURL = "https://www.sketchymaze.com/guidebook/" ) + +// UserAgent controls the HTTP User-Agent header when the game checks +// for updates on startup, to collect basic statistics of which game +// versions are out in the wild. Only static data (the --version string) +// about version, architecture, build number is included but no user +// specific data. +func UserAgent() string { + return fmt.Sprintf("%s v%s on %s/%s", + AppName, + Version, + runtime.GOOS, + runtime.GOARCH, + ) +} diff --git a/pkg/main_scene.go b/pkg/main_scene.go index d7facfd..ad4389e 100644 --- a/pkg/main_scene.go +++ b/pkg/main_scene.go @@ -47,6 +47,7 @@ type MainScene struct { updateInfo updater.VersionInfo // Lazy scroll variables. See LoopLazyScroll(). + PauseLazyScroll bool // exported for dev console lazyScrollBounce bool lazyScrollTrajectory render.Point lazyScrollLastValue render.Point @@ -379,6 +380,21 @@ func (s *MainScene) Resized(width, height int) { }) } +// ButtonFrame returns the main button frame. +func (s *MainScene) ButtonFrame() *ui.Frame { + return s.frame +} + +// LabelVersion returns the version widget. +func (s *MainScene) LabelVersion() *ui.Label { + return s.labelVersion +} + +// LabelHint returns the hint widget. +func (s *MainScene) LabelHint() *ui.Label { + return s.labelHint +} + // Move things into position for the main menu. This function arranges // the Title, Subtitle, Buttons, etc. into screen relative positions every // tick. This function sets their 'default' values, but if the window is @@ -459,6 +475,10 @@ func (s *MainScene) positionMenuLandscape(d *Doodle) { // LoopLazyScroll gently scrolls the title screen demo level, called each Loop. func (s *MainScene) LoopLazyScroll() { + if s.PauseLazyScroll { + return + } + // The v1 basic sauce algorithm: // 1. We scroll diagonally downwards and rightwards. // 2. When we scroll downwards far enough, we change direction. diff --git a/pkg/modal/loadscreen/loadscreen.go b/pkg/modal/loadscreen/loadscreen.go index 3724c1e..710558e 100644 --- a/pkg/modal/loadscreen/loadscreen.go +++ b/pkg/modal/loadscreen/loadscreen.go @@ -7,7 +7,6 @@ import ( "git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/level" - "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/shmem" "git.kirsle.net/apps/doodle/pkg/uix" "git.kirsle.net/go/render" @@ -222,7 +221,6 @@ func PreloadAllChunkBitmaps(chunker *level.Chunker) { for { remaining := chunker.PrerenderN(10) - log.Debug("Remain: %d", remaining) // Set the load screen progress % based on number of chunks to render. if loadChunksTarget > 0 { diff --git a/pkg/updater/updater.go b/pkg/updater/updater.go index 4fe2a7d..8ec08c3 100644 --- a/pkg/updater/updater.go +++ b/pkg/updater/updater.go @@ -72,9 +72,14 @@ func Check() (VersionInfo, error) { Timeout: 10 * time.Second, } - log.Debug("Checking for app updates") + req, err := http.NewRequest("GET", branding.UpdateCheckJSON, nil) + if err != nil { + return result, fmt.Errorf("updater.Check: HTTP error getting %s: %s", branding.UpdateCheckJSON, err) + } + req.Header.Add("User-Agent", branding.UserAgent()) - resp, err := client.Get(branding.UpdateCheckJSON) + log.Debug("Checking for app updates") + resp, err := client.Do(req) if err != nil { return result, fmt.Errorf("updater.Check: HTTP error: %s", err) }