diff --git a/Makefile b/Makefile index 8b525719..09e0b5cb 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.1 +VERSION := 2.7.2 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 a42476d1..133716f0 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.1/octoscreen_2.7.1_armhf.deb -sudo dpkg -i octoscreen_2.7.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb +sudo dpkg -i octoscreen_2.7.2_armhf.deb ``` Or to update an existing version of OctoScreen: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb sudo dpkg -r octoscreen -sudo dpkg -i octoscreen_2.7.1_armhf.deb +sudo dpkg -i octoscreen_2.7.2_armhf.deb sudo reboot now ``` @@ -153,6 +153,7 @@ The basic configuration is handled via environment variables, if you are using t - `OCTOSCREEN_RESOLUTION` - Resolution of the application, and should be configured to the resolution of your screen. Optimal resolution for OctoScreen is no less than 800x480, so if the physical resolution of your screen is 480x320, it's recommended to set the software resolution 800x533. If you are using Raspbian you can do it by changing [`hdmi_cvt`](https://www.raspberrypi.org/documentation/configuration/config-txt/video.md) param in `/boot/config.txt` file. Please see [Setting Up OctoScreen and Your Display](https://github.com/Z-Bolt/OctoScreen/wiki/Setting-Up-OctoScreen-and-Your-Display) and [Installing OctoScreen with a 3.5" 480x320 TFT screen](https://github.com/Z-Bolt/OctoScreen/wiki/Installing-OctoScreen-with-a-3.5%22-480x320-TFT-screen) for more information. +- `DISPLAY_CURSOR` - To display the cursor, add `DISPLAY_CURSOR=true` to your config file. In order to display the cursor, you will also need to edit `/lib/systemd/system/octoscreen.service` and remove `-nocursor` diff --git a/debian/local/octoscreen/config b/debian/local/octoscreen/config index 002dd806..85f7ea7d 100755 --- a/debian/local/octoscreen/config +++ b/debian/local/octoscreen/config @@ -50,3 +50,8 @@ OCTOSCREEN_LOG_LEVEL=Error OCTOSCREEN_RESOLUTION=800x480 # OCTOSCREEN_RESOLUTION is optional and defaults to 800x480 if missing # (defined in globalVars.go) + + +# To display the cursor, uncomment the following line and set to true. +#DISPLAY_CURSOR=true +# You will also need to edit /lib/systemd/system/octoscreen.service and remove "-nocursor" diff --git a/debian/octoscreen.service b/debian/octoscreen.service index 6391ef1c..1d144f8c 100644 --- a/debian/octoscreen.service +++ b/debian/octoscreen.service @@ -11,7 +11,7 @@ ExecStart=/usr/bin/xinit /usr/bin/OctoScreen -- :0 -nolisten tcp -nocursor ExecStartPost=/bin/bash /etc/octoscreen/disablescreenblank.sh 0 StandardOutput=journal Restart=always -WatchdogSec=20s +WatchdogSec=40s [Install] WantedBy=graphical.target diff --git a/main.go b/main.go index 18a0ec32..dc344935 100755 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" + "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/gtk" "github.com/sirupsen/logrus" @@ -123,6 +124,8 @@ func main() { utils.DumpEnvironmentVariables() + setCursor() + if initSucceeded != true { // readConfig() logs any errors it encounters. Don't display // the error here, because the error could be long, and we don't @@ -368,3 +371,51 @@ func getSize() (width int, height int, err error) { logger.TraceLeave("main.getSize()") return } + +func setCursor() { + // For reference, see "How to turn on a pointer" + // https://github.com/Z-Bolt/OctoScreen/issues/285 + // and "No mouse pointer when running xinit" + // https://www.raspberrypi.org/forums/viewtopic.php?t=139546 + + displayCursor := strings.ToLower(os.Getenv("DISPLAY_CURSOR")) + if displayCursor != "true" { + return + } + + window, err := getRootWindow() + if err != nil { + return + } + + cursor, err := getDefaultCursor() + if err != nil { + return + } + + window.SetCursor(cursor) +} + +func getRootWindow() (*gdk.Window, error) { + screen, err := gdk.ScreenGetDefault() + if err != nil { + return nil, err + } + + window, err := screen.GetRootWindow() + + return window, err +} + +func getDefaultCursor() (*gdk.Cursor, error) { + display, err := gdk.DisplayGetDefault() + if err != nil { + return nil, err + } + + // Examples of the different cursors can be found at + // https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-new-from-name + cursor, err := gdk.CursorNewFromName(display, "default") + + return cursor, err +} diff --git a/octoprintApis/BedOffsetRequest.go b/octoprintApis/BedOffsetRequest.go index d0fff548..da794c84 100755 --- a/octoprintApis/BedOffsetRequest.go +++ b/octoprintApis/BedOffsetRequest.go @@ -19,12 +19,12 @@ type BedOffsetRequest struct { // Do sends an API request and returns an error if any. func (cmd *BedOffsetRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/BedStateRequest.go b/octoprintApis/BedStateRequest.go index 893e9ad9..ef3920be 100755 --- a/octoprintApis/BedStateRequest.go +++ b/octoprintApis/BedStateRequest.go @@ -29,15 +29,15 @@ type BedStateRequest struct { // Do sends an API request and returns the API response. func (cmd *BedStateRequest) Do(c *Client) (*dataModels.TemperatureStateResponse, error) { uri := fmt.Sprintf("%s?history=%t&limit=%d", PrinterBedApiUri, cmd.IncludeHistory, cmd.Limit) - b, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors) + bytes, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors, true) if err != nil { return nil, err } - r := &dataModels.TemperatureStateResponse{} - if err := json.Unmarshal(b, &r); err != nil { + response := &dataModels.TemperatureStateResponse{} + if err := json.Unmarshal(bytes, &response); err != nil { return nil, err } - return r, err + return response, err } diff --git a/octoprintApis/BedTargetRequest.go b/octoprintApis/BedTargetRequest.go index 64936ea9..975e1b33 100755 --- a/octoprintApis/BedTargetRequest.go +++ b/octoprintApis/BedTargetRequest.go @@ -19,12 +19,12 @@ type BedTargetRequest struct { // Do sends an API request and returns an error if any. func (cmd *BedTargetRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterBedApiUri, b, PrintBedErrors) + _, err := c.doJsonRequest("POST", PrinterBedApiUri, buffer, PrintBedErrors, true) return err } diff --git a/octoprintApis/CancelRequest.go b/octoprintApis/CancelRequest.go index 4b4ed193..af457891 100755 --- a/octoprintApis/CancelRequest.go +++ b/octoprintApis/CancelRequest.go @@ -21,6 +21,6 @@ func (cmd *CancelRequest) Do(c *Client) error { return err } - _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors) + _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true) return err } diff --git a/octoprintApis/CommandRequest.go b/octoprintApis/CommandRequest.go index 758a6360..ae46ad1e 100755 --- a/octoprintApis/CommandRequest.go +++ b/octoprintApis/CommandRequest.go @@ -21,11 +21,11 @@ type CommandRequest struct { // Do sends an API request and returns an error if any. func (cmd *CommandRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := json.NewEncoder(b).Encode(cmd); err != nil { + buffer := bytes.NewBuffer(nil) + if err := json.NewEncoder(buffer).Encode(cmd); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterCommandApiUri, b, nil) + _, err := c.doJsonRequest("POST", PrinterCommandApiUri, buffer, nil, true) return err } diff --git a/octoprintApis/ConnectRequest.go b/octoprintApis/ConnectRequest.go index 2b7d2f2d..22fe044b 100755 --- a/octoprintApis/ConnectRequest.go +++ b/octoprintApis/ConnectRequest.go @@ -39,14 +39,14 @@ type ConnectRequest struct { func (cmd *ConnectRequest) Do(client *Client) error { logger.TraceEnter("ConnectRequest.Do()") - bytes := bytes.NewBuffer(nil) - if err := cmd.encode(bytes); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { logger.LogError("ConnectRequest.Do()", "cmd.encode()", err) logger.TraceLeave("ConnectRequest.Do()") return err } - _, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors) + _, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true) if err != nil { logger.LogError("ConnectRequest.go()", "client.doJsonRequest(POST)", err) } diff --git a/octoprintApis/ConnectionRequest.go b/octoprintApis/ConnectionRequest.go index 49b4e15a..ce9024cc 100755 --- a/octoprintApis/ConnectionRequest.go +++ b/octoprintApis/ConnectionRequest.go @@ -19,7 +19,7 @@ type ConnectionRequest struct{} func (cmd *ConnectionRequest) Do(client *Client) (*dataModels.ConnectionResponse, error) { logger.TraceEnter("ConnectionRequest.Do()") - bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil) + bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil, true) if err != nil { logger.LogError("ConnectionRequest.Do()", "client.doJsonRequest(GET)", err) logger.TraceLeave("ConnectionRequest.Do()") diff --git a/octoprintApis/CustomCommandsRequest.go b/octoprintApis/CustomCommandsRequest.go index 485533bd..95f32f63 100755 --- a/octoprintApis/CustomCommandsRequest.go +++ b/octoprintApis/CustomCommandsRequest.go @@ -16,15 +16,15 @@ type CustomCommandsRequest struct{} // Do sends an API request and returns the API response. func (cmd *CustomCommandsRequest) Do(c *Client) (*dataModels.CustomCommandsResponse, error) { - b, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil) + bytes, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil, true) if err != nil { return nil, err } - r := &dataModels.CustomCommandsResponse{} - if err := json.Unmarshal(b, r); err != nil { + response := &dataModels.CustomCommandsResponse{} + if err := json.Unmarshal(bytes, response); err != nil { return nil, err } - return r, err + return response, err } diff --git a/octoprintApis/DeleteFileRequest.go b/octoprintApis/DeleteFileRequest.go index 0f033dc2..ec945290 100755 --- a/octoprintApis/DeleteFileRequest.go +++ b/octoprintApis/DeleteFileRequest.go @@ -21,7 +21,7 @@ type DeleteFileRequest struct { // Do sends an API request and returns error if any. func (req *DeleteFileRequest) Do(c *Client) error { uri := fmt.Sprintf("%s/%s/%s", FilesApiUri, req.Location, req.Path) - if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors); err != nil { + if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors, true); err != nil { return err } diff --git a/octoprintApis/DisconnectRequest.go b/octoprintApis/DisconnectRequest.go index 3cdf7b6e..e0e4a18a 100755 --- a/octoprintApis/DisconnectRequest.go +++ b/octoprintApis/DisconnectRequest.go @@ -19,14 +19,14 @@ type DisconnectRequest struct{} func (this *DisconnectRequest) Do(client *Client) error { logger.TraceEnter("DisconnectRequest.Do()") - bytes := bytes.NewBuffer(nil) - if err := this.encode(bytes); err != nil { + buffer := bytes.NewBuffer(nil) + if err := this.encode(buffer); err != nil { logger.LogError("DisconnectRequest.Do()", "this.encode(bytes)", err) logger.TraceLeave("DisconnectRequest.Do()") return err } - _, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors) + _, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true) if err != nil { logger.LogError("DisconnectRequest.Do()", "client.doJsonRequest(POST)", err) } diff --git a/octoprintApis/FakesAckRequest.go b/octoprintApis/FakesAckRequest.go index 939b1aea..b60a638e 100755 --- a/octoprintApis/FakesAckRequest.go +++ b/octoprintApis/FakesAckRequest.go @@ -23,14 +23,14 @@ type FakesAckRequest struct{} func (this *FakesAckRequest) Do(client *Client) error { logger.TraceEnter("FakesAckRequest.Do()") - bytes := bytes.NewBuffer(nil) - if err := this.encode(bytes); err != nil { + buffer := bytes.NewBuffer(nil) + if err := this.encode(buffer); err != nil { logger.LogError("FakesAckRequest.Do()", "this.encode(bytes)", err) logger.TraceLeave("FakesAckRequest.Do()") return err } - _, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors) + _, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true) if err != nil { logger.LogError("FakesAckRequest.Do()", "client.doJsonRequest(POST)", err) logger.LogError("main.findConfigFile()", "Current()", err) diff --git a/octoprintApis/FileRequest.go b/octoprintApis/FileRequest.go index cc872b9e..223e66bb 100755 --- a/octoprintApis/FileRequest.go +++ b/octoprintApis/FileRequest.go @@ -39,7 +39,7 @@ func (request *FileRequest) Do(c *Client) (*dataModels.FileResponse, error) { request.Recursive, ) - bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors) + bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true) if err != nil { return nil, err } diff --git a/octoprintApis/FilesRequest.go b/octoprintApis/FilesRequest.go index 335fb2aa..29d31581 100755 --- a/octoprintApis/FilesRequest.go +++ b/octoprintApis/FilesRequest.go @@ -29,19 +29,19 @@ func (cmd *FilesRequest) Do(c *Client) (*dataModels.FilesResponse, error) { uri = fmt.Sprintf("%s/%s?recursive=%t", FilesApiUri, cmd.Location, cmd.Recursive) } - b, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors) + bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true) if err != nil { return nil, err } - r := &dataModels.FilesResponse{} - if err := json.Unmarshal(b, r); err != nil { + response := &dataModels.FilesResponse{} + if err := json.Unmarshal(bytes, response); err != nil { return nil, err } - if len(r.Children) > 0 { - r.Files = r.Children + if len(response.Children) > 0 { + response.Files = response.Children } - return r, err + return response, err } diff --git a/octoprintApis/FullStateRequest.go b/octoprintApis/FullStateRequest.go index f77f11b7..19033414 100755 --- a/octoprintApis/FullStateRequest.go +++ b/octoprintApis/FullStateRequest.go @@ -69,7 +69,7 @@ func (cmd *FullStateRequest) Do(c *Client) (*dataModels.FullStateResponse, error */ - bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors) + bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors, true) if err != nil { return nil, err } diff --git a/octoprintApis/JobRequest.go b/octoprintApis/JobRequest.go index c8a6808e..773669d1 100755 --- a/octoprintApis/JobRequest.go +++ b/octoprintApis/JobRequest.go @@ -15,7 +15,7 @@ type JobRequest struct{} // Do sends an API request and returns the API response. func (cmd *JobRequest) Do(client *Client) (*dataModels.JobResponse, error) { - bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil) + bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil, true) if err != nil { return nil, err } diff --git a/octoprintApis/NotificationRequest.go b/octoprintApis/NotificationRequest.go index 3da608d1..91d42348 100755 --- a/octoprintApis/NotificationRequest.go +++ b/octoprintApis/NotificationRequest.go @@ -19,7 +19,7 @@ func (this *NotificationRequest) Do(client *Client, uiState string) (*dataModels } target := fmt.Sprintf("%s?command=get_notification", PluginZBoltOctoScreenApiUri) - bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors) + bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, true) if err != nil { return nil, err } diff --git a/octoprintApis/OctoScreenSettingsRequest.go b/octoprintApis/OctoScreenSettingsRequest.go index 0ca89741..858aa46d 100755 --- a/octoprintApis/OctoScreenSettingsRequest.go +++ b/octoprintApis/OctoScreenSettingsRequest.go @@ -17,7 +17,7 @@ type OctoScreenSettingsRequest struct { func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) { target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri) - bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors) + bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, false) if err != nil { return nil, err } diff --git a/octoprintApis/PauseRequest.go b/octoprintApis/PauseRequest.go index e4b97ebf..9f9d64d1 100755 --- a/octoprintApis/PauseRequest.go +++ b/octoprintApis/PauseRequest.go @@ -25,7 +25,7 @@ func (cmd *PauseRequest) Do(c *Client) error { return err } - _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors) + _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true) return err } diff --git a/octoprintApis/PluginManagerInfoRequest.go b/octoprintApis/PluginManagerInfoRequest.go index 8d93abd8..126c8632 100755 --- a/octoprintApis/PluginManagerInfoRequest.go +++ b/octoprintApis/PluginManagerInfoRequest.go @@ -26,7 +26,7 @@ func (this *PluginManagerInfoRequest) Do(client *Client, uiState string) (*dataM return nil, err } - bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors) + bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors, true) if err != nil { logger.LogError("PluginManagerInfoRequest.Do()", "client.doJsonRequest()", err) return nil, err diff --git a/octoprintApis/PrintHeadHomeRequest.go b/octoprintApis/PrintHeadHomeRequest.go index 2a677678..0755a089 100755 --- a/octoprintApis/PrintHeadHomeRequest.go +++ b/octoprintApis/PrintHeadHomeRequest.go @@ -19,12 +19,12 @@ type PrintHeadHomeRequest struct { // Do sends an API request and returns an error if any. func (cmd *PrintHeadHomeRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, b, PrintHeadJobErrors) + _, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, buffer, PrintHeadJobErrors, true) return err } diff --git a/octoprintApis/PrintHeadJogRequest.go b/octoprintApis/PrintHeadJogRequest.go index bd4b93e0..a7ac2097 100755 --- a/octoprintApis/PrintHeadJogRequest.go +++ b/octoprintApis/PrintHeadJogRequest.go @@ -38,12 +38,12 @@ type PrintHeadJogRequest struct { // Do sends an API request and returns an error if any. func (cmd *PrintHeadJogRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, b, PrintHeadJobErrors) + _, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, buffer, PrintHeadJobErrors, true) return err } diff --git a/octoprintApis/PrinterProfilesRequest.go b/octoprintApis/PrinterProfilesRequest.go index 675f5bae..6c8b6224 100755 --- a/octoprintApis/PrinterProfilesRequest.go +++ b/octoprintApis/PrinterProfilesRequest.go @@ -16,15 +16,15 @@ type PrinterProfilesRequest struct { // Do sends an API request and returns the API response. func (cmd *PrinterProfilesRequest) Do(c *Client) (*dataModels.PrinterProfileResponse, error) { uri := fmt.Sprintf("/api/printerprofiles/%s", cmd.Id) - b, err := c.doJsonRequest("GET", uri, nil, nil) + bytes, err := c.doJsonRequest("GET", uri, nil, nil, true) if err != nil { return nil, err } - r := &dataModels.PrinterProfileResponse{} - if err := json.Unmarshal(b, r); err != nil { + response := &dataModels.PrinterProfileResponse{} + if err := json.Unmarshal(bytes, response); err != nil { return nil, err } - return r, err + return response, err } diff --git a/octoprintApis/RestartRequest.go b/octoprintApis/RestartRequest.go index df117ce6..07e00fea 100755 --- a/octoprintApis/RestartRequest.go +++ b/octoprintApis/RestartRequest.go @@ -23,6 +23,6 @@ func (cmd *RestartRequest) Do(c *Client) error { return err } - _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors) + _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true) return err } diff --git a/octoprintApis/RunZOffsetCalibrationRequest.go b/octoprintApis/RunZOffsetCalibrationRequest.go index 18d9d46f..dfbd71f3 100755 --- a/octoprintApis/RunZOffsetCalibrationRequest.go +++ b/octoprintApis/RunZOffsetCalibrationRequest.go @@ -16,12 +16,12 @@ type RunZOffsetCalibrationRequest struct { func (this *RunZOffsetCalibrationRequest) Do(client *Client) error { this.Command = "run_zoffset_calibration" - bytes := bytes.NewBuffer(nil) - if err := json.NewEncoder(bytes).Encode(this); err != nil { + buffer := bytes.NewBuffer(nil) + if err := json.NewEncoder(buffer).Encode(this); err != nil { logger.LogError("RunZOffsetCalibrationRequest.Do()", "json.NewEncoder(params).Encode(this)", err) return err } - _, err := client.doJsonRequest("POST", PluginZBoltOctoScreenApiUri, bytes, ConnectionErrors) + _, err := client.doJsonRequest("POST", PluginZBoltOctoScreenApiUri, buffer, ConnectionErrors, true) return err } diff --git a/octoprintApis/SdStateRequest.go b/octoprintApis/SdStateRequest.go index 87c87179..2a86fd63 100755 --- a/octoprintApis/SdStateRequest.go +++ b/octoprintApis/SdStateRequest.go @@ -17,15 +17,16 @@ type SdStateRequest struct{} // Do sends an API request and returns the API response. func (cmd *SdStateRequest) Do(c *Client) (*dataModels.SdState, error) { - b, err := c.doJsonRequest("GET", PrinterSdApiUri, nil, PrintSdErrors) + bytes, err := c.doJsonRequest("GET", PrinterSdApiUri, nil, PrintSdErrors, true) if err != nil { return nil, err } - r := &dataModels.SdState{} - if err := json.Unmarshal(b, r); err != nil { + // TODO: rename SdState to SdStateResponse or something. + response := &dataModels.SdState{} + if err := json.Unmarshal(bytes, response); err != nil { return nil, err } - return r, err + return response, err } diff --git a/octoprintApis/SelectFileRequest.go b/octoprintApis/SelectFileRequest.go index 7e50289e..ce6b89c1 100755 --- a/octoprintApis/SelectFileRequest.go +++ b/octoprintApis/SelectFileRequest.go @@ -29,13 +29,13 @@ type SelectFileRequest struct { // Do sends an API request and returns an error if any. func (cmd *SelectFileRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } uri := fmt.Sprintf("%s/%s/%s", FilesApiUri, cmd.Location, cmd.Path) - _, err := c.doJsonRequest("POST", uri, b, FilesLocationPathPOSTErrors) + _, err := c.doJsonRequest("POST", uri, buffer, FilesLocationPathPOSTErrors, true) return err } diff --git a/octoprintApis/StartRequest.go b/octoprintApis/StartRequest.go index b1a7638f..37aeea6f 100755 --- a/octoprintApis/StartRequest.go +++ b/octoprintApis/StartRequest.go @@ -21,6 +21,6 @@ func (cmd *StartRequest) Do(c *Client) error { return err } - _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors) + _, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true) return err } diff --git a/octoprintApis/TemperatureDataRequest.go b/octoprintApis/TemperatureDataRequest.go index 2bca238e..5c325c1d 100755 --- a/octoprintApis/TemperatureDataRequest.go +++ b/octoprintApis/TemperatureDataRequest.go @@ -52,7 +52,7 @@ func (cmd *TemperatureDataRequest) Do(c *Client) (*dataModels.TemperatureDataRes */ - bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors) + bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors, true) if err != nil { return nil, err } diff --git a/octoprintApis/ToolExtrudeRequest.go b/octoprintApis/ToolExtrudeRequest.go index 58942bf2..f67f4835 100755 --- a/octoprintApis/ToolExtrudeRequest.go +++ b/octoprintApis/ToolExtrudeRequest.go @@ -21,12 +21,12 @@ type ToolExtrudeRequest struct { // Do sends an API request and returns an error if any. func (cmd *ToolExtrudeRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/ToolFlowRateRequest.go b/octoprintApis/ToolFlowRateRequest.go index 804ea5f4..7f96e5a2 100755 --- a/octoprintApis/ToolFlowRateRequest.go +++ b/octoprintApis/ToolFlowRateRequest.go @@ -19,12 +19,12 @@ type ToolFlowRateRequest struct { // Do sends an API request and returns an error if any. func (cmd *ToolFlowRateRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/ToolOffsetRequest.go b/octoprintApis/ToolOffsetRequest.go index 0ae6aa54..c0240841 100755 --- a/octoprintApis/ToolOffsetRequest.go +++ b/octoprintApis/ToolOffsetRequest.go @@ -20,12 +20,12 @@ type ToolOffsetRequest struct { // Do sends an API request and returns an error if any. func (cmd *ToolOffsetRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/ToolSelectRequest.go b/octoprintApis/ToolSelectRequest.go index 2451457a..d68f39e8 100755 --- a/octoprintApis/ToolSelectRequest.go +++ b/octoprintApis/ToolSelectRequest.go @@ -20,12 +20,12 @@ type ToolSelectRequest struct { // Do sends an API request and returns an error if any. func (cmd *ToolSelectRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/ToolStateRequest.go b/octoprintApis/ToolStateRequest.go index b491344a..3cf55f17 100755 --- a/octoprintApis/ToolStateRequest.go +++ b/octoprintApis/ToolStateRequest.go @@ -46,15 +46,15 @@ func (cmd *ToolStateRequest) Do(c *Client) (*dataModels.TemperatureStateResponse } */ - b, err := c.doJsonRequest("GET", uri, nil, nil) + bytes, err := c.doJsonRequest("GET", uri, nil, nil, true) if err != nil { return nil, err } - r := &dataModels.TemperatureStateResponse{} - if err := json.Unmarshal(b, &r); err != nil { + response := &dataModels.TemperatureStateResponse{} + if err := json.Unmarshal(bytes, &response); err != nil { return nil, err } - return r, err + return response, err } diff --git a/octoprintApis/ToolTargetRequest.go b/octoprintApis/ToolTargetRequest.go index 34678c05..125dd422 100755 --- a/octoprintApis/ToolTargetRequest.go +++ b/octoprintApis/ToolTargetRequest.go @@ -20,12 +20,12 @@ type ToolTargetRequest struct { // Do sends an API request and returns an error if any. func (cmd *ToolTargetRequest) Do(c *Client) error { - b := bytes.NewBuffer(nil) - if err := cmd.encode(b); err != nil { + buffer := bytes.NewBuffer(nil) + if err := cmd.encode(buffer); err != nil { return err } - _, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors) + _, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true) return err } diff --git a/octoprintApis/UploadFileRequest.go b/octoprintApis/UploadFileRequest.go index 2b3a581a..8faf7bb6 100755 --- a/octoprintApis/UploadFileRequest.go +++ b/octoprintApis/UploadFileRequest.go @@ -64,17 +64,17 @@ func (req *UploadFileRequest) Do(c *Client) (*dataModels.UploadFileResponse, err req.addSelectPrintAndClose() uri := fmt.Sprintf("%s/%s", FilesApiUri, req.Location) - b, err := c.doRequest("POST", uri, req.w.FormDataContentType(), req.b, FilesLocationPOSTErrors) + bytes, err := c.doRequest("POST", uri, req.w.FormDataContentType(), req.b, FilesLocationPOSTErrors, true) if err != nil { return nil, err } - r := &dataModels.UploadFileResponse{} - if err := json.Unmarshal(b, r); err != nil { + response := &dataModels.UploadFileResponse{} + if err := json.Unmarshal(bytes, response); err != nil { return nil, err } - return r, err + return response, err } func (req *UploadFileRequest) addSelectPrintAndClose() error { diff --git a/octoprintApis/ZOffsetRequest.go b/octoprintApis/ZOffsetRequest.go index bd456dc4..eb73e31f 100755 --- a/octoprintApis/ZOffsetRequest.go +++ b/octoprintApis/ZOffsetRequest.go @@ -24,8 +24,8 @@ func (this *ZOffsetRequest) Do(client *Client) (*dataModels.ZOffsetResponse, err return nil, err } - // b, err := client.doJsonRequest("POST", URIZBoltRequest, params, ConnectionErrors) - bytes, err := client.doJsonRequest("GET", PluginZBoltApiUri, params, ConnectionErrors) + // bytes, err := client.doJsonRequest("POST", URIZBoltRequest, params, ConnectionErrors) + bytes, err := client.doJsonRequest("GET", PluginZBoltApiUri, params, ConnectionErrors, true) if err != nil { logger.LogError("ZOffsetRequest.Do()", "client.doJsonRequest()", err) return nil, err @@ -53,12 +53,12 @@ type SetZOffsetRequest struct { func (this *SetZOffsetRequest) Do(client *Client) error { this.Command = "set_z_offset" - bytes := bytes.NewBuffer(nil) - if err := json.NewEncoder(bytes).Encode(this); err != nil { + buffer := bytes.NewBuffer(nil) + if err := json.NewEncoder(buffer).Encode(this); err != nil { logger.LogError("SetZOffsetRequest.Do()", "json.NewEncoder(params).Encode(this)", err) return err } - _, err := client.doJsonRequest("POST", PluginZBoltApiUri, bytes, ConnectionErrors) + _, err := client.doJsonRequest("POST", PluginZBoltApiUri, buffer, ConnectionErrors, true) return err } diff --git a/octoprintApis/client.go b/octoprintApis/client.go index 9e29ef64..080f8a43 100755 --- a/octoprintApis/client.go +++ b/octoprintApis/client.go @@ -52,12 +52,21 @@ func (this *Client) doJsonRequest( target string, body io.Reader, statusMapping StatusMapping, + isRequired bool, ) ([]byte, error) { logger.TraceEnter("Client.doJsonRequest()") - bytes, err := this.doRequest(method, target, "application/json", body, statusMapping) + bytes, err := this.doRequest(method, target, "application/json", body, statusMapping, isRequired) if err != nil { - logger.LogError("Client.doJsonRequest()", "this.doRequest()", err) + if isRequired { + // Some APIs return an error and the error should be logged. + logger.LogError("Client.doJsonRequest()", "this.doRequest()", err) + } else { + // On the other hand, calls to some APIs are optional, and the result should be logged + // as info and leave it up to the caller to determine whether it's an error or not. + logger.Infof("Client.doJsonRequest() - this.doRequest() returned %q", err) + } + logger.TraceLeave("Client.doJsonRequest()") return nil, err } @@ -78,6 +87,7 @@ func (this *Client) doRequest( contentType string, body io.Reader, statusMapping StatusMapping, + isRequired bool, ) ([]byte, error) { logger.TraceEnter("Client.doRequest()") logger.Debugf("method: %s", method) @@ -109,22 +119,29 @@ func (this *Client) doRequest( // logger.Debugf("API key: %s", this.APIKey) req.Header.Add("X-Api-Key", this.APIKey) - resp, err := this.httpClient.Do(req) + response, err := this.httpClient.Do(req) if err != nil { logger.LogError("Client.doRequest()", "this.httpClient.Do()", err) logger.TraceLeave("Client.doRequest()") return nil, err } - response, err := this.handleResponse(resp, statusMapping) + bytes, err := this.handleResponse(response, statusMapping) if err != nil { - logger.LogError("Client.doRequest()", "this.handleResponse()", err) + if isRequired { + // Some APIs return an error and the error should be logged. + logger.LogError("Client.doRequest()", "this.handleResponse()", err) + } else { + // On the other hand, calls to some APIs are optional, and the result should be logged + // as info and leave it up to the caller to determine whether it's an error or not. + logger.Infof("Client.doRequest() - this.handleResponse() returned %q", err) + } logger.TraceLeave("Client.doRequest()") return nil, err } logger.TraceLeave("Client.doRequest()") - return response, err + return bytes, err } diff --git a/octoprintApis/printer.go b/octoprintApis/printer.go index bf3ef79c..3458e460 100755 --- a/octoprintApis/printer.go +++ b/octoprintApis/printer.go @@ -58,7 +58,7 @@ func doCommandRequest( return err } - _, err := client.doJsonRequest("POST", uri, buffer, statusMapping) + _, err := client.doJsonRequest("POST", uri, buffer, statusMapping, true) return err } diff --git a/octoprintApis/settings.go b/octoprintApis/settings.go index c59b5840..4aee4ba7 100755 --- a/octoprintApis/settings.go +++ b/octoprintApis/settings.go @@ -15,7 +15,7 @@ type SettingsRequest struct{} // Do sends an API request and returns the API response. func (cmd *SettingsRequest) Do(c *Client) (*dataModels.SettingsResponse, error) { - bytes, err := c.doJsonRequest("GET", SettingsApiUri, nil, nil) + bytes, err := c.doJsonRequest("GET", SettingsApiUri, nil, nil, true) if err != nil { return nil, err } diff --git a/octoprintApis/system.go b/octoprintApis/system.go index c879fdb5..ef1da2f5 100755 --- a/octoprintApis/system.go +++ b/octoprintApis/system.go @@ -23,7 +23,7 @@ type SystemCommandsRequest struct{} // Do sends an API request and returns the API response. func (cmd *SystemCommandsRequest) Do(c *Client) (*dataModels.SystemCommandsResponse, error) { - bytes, err := c.doJsonRequest("GET", SystemCommandsApiUri, nil, nil) + bytes, err := c.doJsonRequest("GET", SystemCommandsApiUri, nil, nil, true) if err != nil { return nil, err } @@ -68,6 +68,6 @@ type SystemExecuteCommandRequest struct { // Do sends an API request and returns an error if any. func (cmd *SystemExecuteCommandRequest) Do(c *Client) error { uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, cmd.Source, cmd.Action) - _, err := c.doJsonRequest("POST", uri, nil, ExecuteErrors) + _, err := c.doJsonRequest("POST", uri, nil, ExecuteErrors, true) return err } diff --git a/octoprintApis/version.go b/octoprintApis/version.go index d275f184..948f25d0 100755 --- a/octoprintApis/version.go +++ b/octoprintApis/version.go @@ -15,7 +15,7 @@ type VersionRequest struct{} // Do sends an API request and returns the API response. func (cmd *VersionRequest) Do(c *Client) (*dataModels.VersionResponse, error) { - bytes, err := c.doJsonRequest("GET", VersionApiUri, nil, nil) + bytes, err := c.doJsonRequest("GET", VersionApiUri, nil, nil, true) if err != nil { return nil, err } diff --git a/ui/CommonPanel.go b/ui/CommonPanel.go index 95815c0e..c7b75c2a 100755 --- a/ui/CommonPanel.go +++ b/ui/CommonPanel.go @@ -16,7 +16,7 @@ import ( ) // OctoScreenVersion - set at compilation time. -var OctoScreenVersion = "2.7.1" +var OctoScreenVersion = "2.7.2" type CommonPanel struct { UI *UI diff --git a/ui/ui.go b/ui/ui.go index a60be6ee..2f4b90e2 100755 --- a/ui/ui.go +++ b/ui/ui.go @@ -100,7 +100,7 @@ func New(endpoint, key string, width, height int) *UI { } instance.splashPanel = NewSplashPanel(instance) - instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 10, instance.update) + instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 20, instance.update) instance.initialize() logger.TraceLeave("ui.New()") @@ -159,7 +159,13 @@ func (this *UI) verifyConnection() { newUIState := "<>" splashMessage := "<>" + logger.Debug("ui.verifyConnection() - about to call ConnectionRequest.Do()") + t1 := time.Now() connectionResponse, err := (&octoprintApis.ConnectionRequest{}).Do(this.Client) + t2 := time.Now() + logger.Debug("ui.verifyConnection() - finished calling ConnectionRequest.Do()") + logger.Debugf("time elapsed: %q", t2.Sub(t1)) + if err == nil { logger.Debug("ui.verifyConnection() - ConnectionRequest.Do() succeeded") jsonResponse, err := utils.StructToJson(connectionResponse) @@ -176,8 +182,9 @@ func (this *UI) verifyConnection() { this.loadSettings() } } else { - logger.LogError("ui.verifyConnection()", "Broke into the else condition because Do(ConnectionRequest) returned an error", err) + logger.LogError("ui.verifyConnection()", "Broke into the else condition because ConnectionRequest.Do() returned an error", err) newUIState, splashMessage = this.getUiStateAndMessageFromError(err, newUIState, splashMessage) + logger.Debugf("ui.verifyConnection() - newUIState is now: %s", newUIState) } this.splashPanel.Label.SetText(splashMessage) diff --git a/utils/environment.go b/utils/environment.go index 9fb6a591..c9b9448f 100755 --- a/utils/environment.go +++ b/utils/environment.go @@ -22,10 +22,11 @@ const ( // Optional (but good to have) environment variables const ( - EnvLogLevel = "OCTOSCREEN_LOG_LEVEL" - EnvLogFilePath = "OCTOSCREEN_LOG_FILE_PATH" - EnvResolution = "OCTOSCREEN_RESOLUTION" - EnvConfigFile = "OCTOPRINT_CONFIG_FILE" + EnvLogLevel = "OCTOSCREEN_LOG_LEVEL" + EnvLogFilePath = "OCTOSCREEN_LOG_FILE_PATH" + EnvResolution = "OCTOSCREEN_RESOLUTION" + EnvConfigFile = "OCTOPRINT_CONFIG_FILE" + EnvDisplayCursor = "DISPLAY_CURSOR" ) func RequiredEnvironmentVariablesAreSet(apiKey string) bool { @@ -109,9 +110,12 @@ func DumpEnvironmentVariables() { dumpEnvironmentVariable(EnvConfigFile) dumpEnvironmentVariable(EnvLogFilePath) dumpEnvironmentVariable(EnvLogLevel) + dumpEnvironmentVariable(EnvResolution) // EnvResolution is optional. If not set, the window size will // default to the values defined in globalVars.go. + + dumpEnvironmentVariable(EnvDisplayCursor) } func dumpEnvironmentVariable(key string) {