Tell admin that automated check failed when necessary

This keeps track when automated update check fails, and displays a
relevant message to the admin on /admin/updates

Ref T572
admin-dashboard-redesign
Matt Baer 5 years ago
parent c2ece926e0
commit 37b7755c08
  1. 2
      admin.go
  2. 5
      less/core.less
  3. 6
      templates/user/admin/app-updates.tmpl
  4. 4
      updates.go

@ -612,6 +612,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re
LatestVersion string LatestVersion string
LatestReleaseURL string LatestReleaseURL string
LatestReleaseNotesURL string LatestReleaseNotesURL string
CheckFailed bool
}{ }{
UserPage: NewUserPage(app, r, u, "Updates", nil), UserPage: NewUserPage(app, r, u, "Updates", nil),
AdminPage: NewAdminPage(app), AdminPage: NewAdminPage(app),
@ -624,6 +625,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re
p.LatestReleaseURL = app.updates.ReleaseURL() p.LatestReleaseURL = app.updates.ReleaseURL()
p.LatestReleaseNotesURL = app.updates.ReleaseNotesURL() p.LatestReleaseNotesURL = app.updates.ReleaseNotesURL()
p.UpdateAvailable = app.updates.AreAvailable() p.UpdateAvailable = app.updates.AreAvailable()
p.CheckFailed = app.updates.checkError != nil
} }
showUserPage(w, "app-updates", p) showUserPage(w, "app-updates", p)

@ -1350,6 +1350,11 @@ div.row {
color: #71D571; color: #71D571;
} }
.ex.failure {
font-weight: bold;
color: @dangerCol;
}
@media all and (max-width: 450px) { @media all and (max-width: 450px) {
body#post { body#post {
header { header {

@ -15,7 +15,11 @@
{{template "admin-header" .}} {{template "admin-header" .}}
{{ if .UpdateChecks }} {{ if .UpdateChecks }}
{{if not .UpdateAvailable}} {{if .CheckFailed}}
<p class="intro"><span class="ex failure">&times;</span> Automated update check failed.</p>
<p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.CurReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p>
<p>Learn about latest releases on the <a href="https://blog.writefreely.org/tag:release" target="changelog-wf">WriteFreely blog</a> or <a href="https://discuss.write.as/c/writefreely/updates" target="forum-wf">forum</a>.</p>
{{else if not .UpdateAvailable}}
<p class="intro"><span class="check">&check;</span> WriteFreely is <strong>up to date</strong>.</p> <p class="intro"><span class="check">&check;</span> WriteFreely is <strong>up to date</strong>.</p>
<p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.LatestReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p> <p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.LatestReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p>
{{else}} {{else}}

@ -30,6 +30,7 @@ type updatesCache struct {
lastCheck time.Time lastCheck time.Time
latestVersion string latestVersion string
currentVersion string currentVersion string
checkError error
} }
// CheckNow asks for the latest released version of writefreely and updates // CheckNow asks for the latest released version of writefreely and updates
@ -38,11 +39,12 @@ type updatesCache struct {
func (uc *updatesCache) CheckNow() error { func (uc *updatesCache) CheckNow() error {
uc.mu.Lock() uc.mu.Lock()
defer uc.mu.Unlock() defer uc.mu.Unlock()
uc.lastCheck = time.Now()
latestRemote, err := newVersionCheck() latestRemote, err := newVersionCheck()
if err != nil { if err != nil {
uc.checkError = err
return err return err
} }
uc.lastCheck = time.Now()
if CompareSemver(latestRemote, uc.latestVersion) == 1 { if CompareSemver(latestRemote, uc.latestVersion) == 1 {
uc.latestVersion = latestRemote uc.latestVersion = latestRemote
} }

Loading…
Cancel
Save