Browse Source

Move calculation of when refresh is to setting the value

master
Elis Hirwing 2 years ago
parent
commit
e73fe6ea40
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
1 changed files with 6 additions and 8 deletions
  1. +6
    -8
      src/statusscreen/SL.go

+ 6
- 8
src/statusscreen/SL.go View File

@@ -16,7 +16,7 @@ import (
type SL struct {
Config *Config
lastResponse SLResponse
lastRefresh int64
nextRefresh int64
}

// SLResponse is a struct to get the interesting data from API Responses
@@ -56,18 +56,16 @@ func (sl *SL) GetOutput() string {
})

// Check if it's time to refresh yet
if (sl.lastRefresh + sl.Config.SL.RefreshDelay) <= time.Now().Unix() {
// If it is, refresh
if sl.nextRefresh <= time.Now().Unix() {
// If it is, refresh the data
sldata, err := sl.getTimeTable()

// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.lastRefresh = time.Now().Unix()
}

if err != nil {
log.Fatal(err)
sl.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
}



Loading…
Cancel
Save