From 909271549cb042ee50bb29cec75ce666914d7e4a Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 21 Sep 2018 23:45:28 +0000 Subject: [PATCH] Fix puzzles on iOS --- res/puzzle.html | 53 ++++++++++++++++++------- src/maintenance.go | 43 +++++++++++--------- src/static.go | 97 ++++++++++++++++++++++++---------------------- 3 files changed, 115 insertions(+), 78 deletions(-) diff --git a/res/puzzle.html b/res/puzzle.html index cb68e8e..87723b8 100644 --- a/res/puzzle.html +++ b/res/puzzle.html @@ -7,17 +7,6 @@ @@ -46,7 +71,9 @@ document.addEventListener("DOMContentLoaded", init);

Puzzle

- +
Loading...
+ +

Puzzle by

diff --git a/src/maintenance.go b/src/maintenance.go index e6d7be3..0879d68 100644 --- a/src/maintenance.go +++ b/src/maintenance.go @@ -119,20 +119,6 @@ func (ctx *Instance) tidy() { // Do they want to reset everything? ctx.MaybeInitialize() - // Skip if we've expired - untilspec, err := ioutil.ReadFile(ctx.StatePath("until")) - if err == nil { - until, err := time.Parse(time.RFC3339, string(untilspec)) - if err != nil { - log.Printf("Unparseable date in until file: %v", until) - } else { - if until.Before(time.Now()) { - log.Print("until file time reached, suspending maintenance") - return - } - } - } - // Refresh all current categories for categoryName, mb := range ctx.Categories { if err := mb.Refresh(); err != nil { @@ -216,13 +202,34 @@ func (ctx *Instance) collectPoints() { } } +func (ctx *Instance) isEnabled() bool { + // Skip if we've been disabled + if _, err := os.Stat(ctx.StatePath("disabled")); err == nil { + log.Print("Suspended: disabled file found") + return false + } + + untilspec, err := ioutil.ReadFile(ctx.StatePath("until")) + if err == nil { + untilspecs := strings.TrimSpace(string(untilspec)) + until, err := time.Parse(time.RFC3339, untilspecs) + if err != nil { + log.Printf("Suspended: Unparseable until date: %s", untilspec) + return false + } + if until.Before(time.Now()) { + log.Print("Suspended: until time reached, suspending maintenance") + return false + } + } + + return true +} + // maintenance is the goroutine that runs a periodic maintenance task func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) { for { - // Skip if we've been disabled - if _, err := os.Stat(ctx.StatePath("disabled")); err == nil { - log.Print("disabled file found, suspending maintenance") - } else { + if ctx.isEnabled() { ctx.tidy() ctx.collectPoints() ctx.generatePuzzleList() diff --git a/src/static.go b/src/static.go index 138ef23..1630c50 100644 --- a/src/static.go +++ b/src/static.go @@ -333,61 +333,64 @@ func staticPuzzleList(w http.ResponseWriter) {
`,