diff --git a/Makefile b/Makefile index 58c48ead..2b607c5c 100755 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14 # Build information #GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7) -VERSION := 2.7.3 +VERSION := 2.7.4 BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S) #BRANCH = $(shell git rev-parse --abbrev-ref HEAD) diff --git a/README.md b/README.md index f7fa9ec9..5ddf45da 100755 --- a/README.md +++ b/README.md @@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t For example, to install on a new RaspberryPi with OctoPi: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb -sudo dpkg -i octoscreen_2.7.3_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.4/octoscreen_2.7.4_armhf.deb +sudo dpkg -i octoscreen_2.7.4_armhf.deb ``` Or to update an existing version of OctoScreen: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.4/octoscreen_2.7.4_armhf.deb sudo dpkg -r octoscreen -sudo dpkg -i octoscreen_2.7.3_armhf.deb +sudo dpkg -i octoscreen_2.7.4_armhf.deb sudo reboot now ``` diff --git a/octoprintApis/client.go b/octoprintApis/client.go index de7d596f..6da7f1a6 100755 --- a/octoprintApis/client.go +++ b/octoprintApis/client.go @@ -140,7 +140,10 @@ func (this *Client) handleResponse( ) ([]byte, error) { logger.TraceEnter("Client.handleResponse()") - defer httpResponse.Body.Close() + defer func() { + io.Copy(ioutil.Discard, httpResponse.Body) + httpResponse.Body.Close() + }() if statusMapping != nil { if err := statusMapping.Error(httpResponse.StatusCode); err != nil { diff --git a/ui/IdleStatusPanel.go b/ui/IdleStatusPanel.go index 0535e465..a2b3882e 100755 --- a/ui/IdleStatusPanel.go +++ b/ui/IdleStatusPanel.go @@ -3,6 +3,8 @@ package ui import ( // "encoding/json" // "fmt" + "os" + "strconv" // "sync" "time" @@ -31,7 +33,23 @@ func IdleStatusPanel(ui *UI) *idleStatusPanel { instance := &idleStatusPanel{ CommonPanel: NewTopLevelCommonPanel("IdleStatusPanel", ui), } - instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 2, instance.update) + + // Default timeout of 20 seconds. + durration := time.Second * 20 + + // Experimental, set the timeout based on config setting, but only if the config is pressent. + updateFrequency := os.Getenv("EXPERIMENTAL_IDLE_UPDATE_FREQUENCY") + if updateFrequency != "" { + logger.Infof("Ui.New() - EXPERIMENTAL_IDLE_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) + val, err := strconv.Atoi(updateFrequency) + if err == nil { + durration = time.Second * time.Duration(val) + } else { + logger.LogError("Ui.New()", "strconv.Atoi()", err) + } + } + + instance.backgroundTask = utils.CreateBackgroundTask(durration, instance.update) instance.initialize() idleStatusPanelInstance = instance diff --git a/ui/NetworkPanel.go b/ui/NetworkPanel.go index 1feab9a5..12d865bb 100755 --- a/ui/NetworkPanel.go +++ b/ui/NetworkPanel.go @@ -3,6 +3,8 @@ package ui import ( "fmt" "net" + "os" + "strconv" "time" "pifke.org/wpasupplicant" @@ -33,7 +35,23 @@ func NetworkPanel( CommonPanel: NewCommonPanel("NetworkPanel", ui), } instance.initialize() - instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 3, instance.update) + + // Default timeout of 30 seconds. + durration := time.Second * 30 + + // Experimental, set the timeout based on config setting, but only if the config is pressent. + updateFrequency := os.Getenv("EXPERIMENTAL_NETWORK_UPDATE_FREQUENCY") + if updateFrequency != "" { + logger.Infof("Ui.New() - EXPERIMENTAL_NETWORK_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) + val, err := strconv.Atoi(updateFrequency) + if err == nil { + durration = time.Second * time.Duration(val) + } else { + logger.LogError("Ui.New()", "strconv.Atoi()", err) + } + } + + instance.backgroundTask = utils.CreateBackgroundTask(durration, instance.update) networkPanelInstance = instance } diff --git a/ui/PrintStatusPanel.go b/ui/PrintStatusPanel.go index cb39cc34..b049c41e 100755 --- a/ui/PrintStatusPanel.go +++ b/ui/PrintStatusPanel.go @@ -2,6 +2,8 @@ package ui import ( "fmt" + "os" + "strconv" "strings" "time" @@ -43,9 +45,24 @@ func PrintStatusPanel(ui *UI) *printStatusPanel { CommonPanel: NewTopLevelCommonPanel("PrintStatusPanel", ui), } + // Default timeout of 20 seconds. + durration := time.Second * 20 + + // Experimental, set the timeout based on config setting, but only if the config is pressent. + updateFrequency := os.Getenv("EXPERIMENTAL_PRINT_UPDATE_FREQUENCY") + if updateFrequency != "" { + logger.Infof("Ui.New() - EXPERIMENTAL_PRINT_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) + val, err := strconv.Atoi(updateFrequency) + if err == nil { + durration = time.Second * time.Duration(val) + } else { + logger.LogError("Ui.New()", "strconv.Atoi()", err) + } + } + // TODO: revisit... some set the background task and then initialize // and others initialize and then set the background task - instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 2, instance.update) + instance.backgroundTask = utils.CreateBackgroundTask(durration, instance.update) instance.initialize() printStatusPanelInstance = instance } diff --git a/ui/ui.go b/ui/ui.go index e5e5aadc..f9310144 100755 --- a/ui/ui.go +++ b/ui/ui.go @@ -107,9 +107,9 @@ func New(endpoint, key string, width, height int) *UI { durration := time.Second * 20 // Experimental, set the timeout based on config setting, but only if the config is pressent. - updateFrequency := os.Getenv("EXPERIMENTAL_UPDATE_FREQUENCY") + updateFrequency := os.Getenv("EXPERIMENTAL_UI_UPDATE_FREQUENCY") if updateFrequency != "" { - logger.Infof("Ui.New() - EXPERIMENTAL_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) + logger.Infof("Ui.New() - EXPERIMENTAL_UI_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) val, err := strconv.Atoi(updateFrequency) if err == nil { durration = time.Second * time.Duration(val) diff --git a/utils/environment.go b/utils/environment.go index 476dcfd0..b35d9a92 100755 --- a/utils/environment.go +++ b/utils/environment.go @@ -11,7 +11,7 @@ import ( // OctoScreenVersion is set during compilation. -var OctoScreenVersion = "2.7.3" +var OctoScreenVersion = "2.7.4" const MISSING_ENV_TOKEN = ">>MISSING<<" const INVALID_ENV_TOKEN = "!!!INVALID!!!" diff --git a/utils/gtk.go b/utils/gtk.go index 67d041e7..feb9167f 100755 --- a/utils/gtk.go +++ b/utils/gtk.go @@ -4,6 +4,8 @@ import ( "bytes" "errors" "fmt" + "io" + "io/ioutil" "net/http" "path/filepath" @@ -261,14 +263,18 @@ func ImageFromUrl(imageUrl string) (*gtk.Image, error) { return nil, errors.New("imageUrl is empty") } - response, getErr:= http.Get(imageUrl) + httpResponse, getErr:= http.Get(imageUrl) if getErr != nil { return nil, getErr } - defer response.Body.Close() - buf := new(bytes.Buffer) - readLength, readErr := buf.ReadFrom(response.Body) + defer func() { + io.Copy(ioutil.Discard, httpResponse.Body) + httpResponse.Body.Close() + }() + + buffer := new(bytes.Buffer) + readLength, readErr := buffer.ReadFrom(httpResponse.Body) if readErr != nil { return nil, readErr } else if readLength < 1 { @@ -281,7 +287,7 @@ func ImageFromUrl(imageUrl string) (*gtk.Image, error) { } defer pixbufLoader.Close() - writeLength, writeErr := pixbufLoader.Write(buf.Bytes()) + writeLength, writeErr := pixbufLoader.Write(buffer.Bytes()) if writeErr != nil { return nil, writeErr } else if writeLength < 1 {