Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Kvitinskii <aleksei.kvitinskii@gmail.com>2019-12-19 21:23:18 +0300
committerAleksei Kvitinskii <aleksei.kvitinskii@gmail.com>2019-12-19 21:23:18 +0300
commit0cb39c2e0ca608b629f1cf269020d464913d7429 (patch)
tree1b07970046327f78ed68c86669e402c92c4e9216
parentfc33e3a0f986cef3105fbada95870bcdb9b54b61 (diff)
bug fix for memory leak issues: #10, #56, #58
-rw-r--r--ui/splash.go26
-rw-r--r--ui/ui.go40
2 files changed, 51 insertions, 15 deletions
diff --git a/ui/splash.go b/ui/splash.go
index 6114aad..f94f06a 100644
--- a/ui/splash.go
+++ b/ui/splash.go
@@ -6,7 +6,8 @@ import (
type SplashPanel struct {
CommonPanel
- Label *gtk.Label
+ Label *gtk.Label
+ RetryButton *gtk.Button
}
func NewSplashPanel(ui *UI) *SplashPanel {
@@ -42,6 +43,13 @@ func (m *SplashPanel) createActionBar() gtk.IWidget {
bar := MustBox(gtk.ORIENTATION_HORIZONTAL, 5)
bar.SetHAlign(gtk.ALIGN_END)
+ m.RetryButton = MustButtonImageStyle("Retry", "refresh.svg", "color2", m.releaseFromHold)
+ m.RetryButton.SetProperty("width-request", m.Scaled(100))
+ m.RetryButton.SetProperty("visible", true)
+ bar.Add(m.RetryButton)
+ ctx, _ := m.RetryButton.GetStyleContext()
+ ctx.AddClass("hidden")
+
sys := MustButtonImageStyle("System", "info.svg", "color3", m.showSystem)
sys.SetProperty("width-request", m.Scaled(100))
bar.Add(sys)
@@ -53,6 +61,22 @@ func (m *SplashPanel) createActionBar() gtk.IWidget {
return bar
}
+func (m *SplashPanel) putOnHold() {
+ m.RetryButton.Show()
+ ctx, _ := m.RetryButton.GetStyleContext()
+ ctx.RemoveClass("hidden")
+ m.Label.SetText("Cannot connect initialize the printer. Tap \"Retry\" to try again.")
+}
+
+func (m *SplashPanel) releaseFromHold() {
+ m.RetryButton.Hide()
+ ctx, _ := m.RetryButton.GetStyleContext()
+ ctx.AddClass("hidden")
+
+ m.Label.SetText("Loading...")
+ m.UI.connectionAttempts = 0
+}
+
func (m *SplashPanel) showNetwork() {
m.UI.Add(NetworkPanel(m.UI, m))
}
diff --git a/ui/ui.go b/ui/ui.go
index 13bd890..73f36d0 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -26,11 +26,12 @@ const (
)
type UI struct {
- Current Panel
- Printer *octoprint.Client
- State octoprint.ConnectionState
- Settings *octoprint.GetSettingsResponse
- UIState string
+ Current Panel
+ Printer *octoprint.Client
+ State octoprint.ConnectionState
+ Settings *octoprint.GetSettingsResponse
+ UIState string
+
OctoPrintPlugin bool
Notifications *Notifications
@@ -38,12 +39,12 @@ type UI struct {
s *SplashPanel
b *BackgroundTask
g *gtk.Grid
- o *gtk.Overlay
w *gtk.Window
t time.Time
- width, height int
- scaleFactor int
+ width, height int
+ scaleFactor int
+ connectionAttempts int
sync.Mutex
}
@@ -95,11 +96,11 @@ func (ui *UI) initialize() {
gtk.MainQuit()
})
- ui.o = MustOverlay()
- ui.w.Add(ui.o)
+ o := MustOverlay()
+ ui.w.Add(o)
ui.g = MustGrid()
- ui.o.Add(ui.g)
+ o.Add(ui.g)
ui.sdNotify("READY=1")
}
@@ -123,7 +124,7 @@ func (ui *UI) verifyConnection() {
ui.sdNotify("WATCHDOG=1")
newUiState := "splash"
- splashMessage := "Loading..."
+ splashMessage := "Initializing..."
s, err := (&octoprint.ConnectionRequest{}).Do(ui.Printer)
if err == nil {
@@ -138,7 +139,7 @@ func (ui *UI) verifyConnection() {
case s.Current.State.IsOffline():
if err := (&octoprint.ConnectRequest{}).Do(ui.Printer); err != nil {
newUiState = "splash"
- splashMessage = fmt.Sprintf("Error connecting to printer: %s", err)
+ splashMessage = "Loading..."
}
case s.Current.State.IsConnecting():
splashMessage = string(s.Current.State)
@@ -190,20 +191,31 @@ func (m *UI) checkNotification() {
func (m *UI) loadSettings() {
n, err := (&octoprint.GetSettingsRequest{}).Do(m.Printer)
if err != nil {
+ fmt.Println("Error")
Logger.Error(err)
return
}
+ fmt.Println("Settings Loaded")
m.Settings = n
}
func (m *UI) update() {
- m.verifyConnection()
+ if m.connectionAttempts > 8 {
+ m.s.putOnHold()
+ return
+ } else if m.UIState == "splash" {
+ m.connectionAttempts += 1
+ } else {
+ m.connectionAttempts = 0
+ }
if m.OctoPrintPlugin {
m.checkNotification()
m.loadSettings()
}
+
+ m.verifyConnection()
}
func (ui *UI) sdNotify(m string) {