forked from Elara6331/itd
Add fatal error dialog
This commit is contained in:
parent
316e113e5d
commit
5bc63b7864
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"os"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
@ -10,7 +11,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
func guiErr(err error, msg string, parent fyne.Window) {
|
func guiErr(err error, msg string, fatal bool, parent fyne.Window) {
|
||||||
// Create new label containing message
|
// Create new label containing message
|
||||||
msgLbl := widget.NewLabel(msg)
|
msgLbl := widget.NewLabel(msg)
|
||||||
// Text formatting settings
|
// Text formatting settings
|
||||||
@ -33,6 +34,20 @@ func guiErr(err error, msg string, parent fyne.Window) {
|
|||||||
widget.NewAccordionItem("More Details", errLbl),
|
widget.NewAccordionItem("More Details", errLbl),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
if fatal {
|
||||||
|
// Create new error dialog
|
||||||
|
errDlg := dialog.NewCustom("Error", "Close", content, parent)
|
||||||
|
// On close, exit with code 1
|
||||||
|
errDlg.SetOnClosed(func() {
|
||||||
|
os.Exit(1)
|
||||||
|
})
|
||||||
|
// Show dialog
|
||||||
|
errDlg.Show()
|
||||||
|
// Run app prematurely to stop further execution
|
||||||
|
parent.ShowAndRun()
|
||||||
|
} else {
|
||||||
// Show error dialog
|
// Show error dialog
|
||||||
dialog.NewCustom("Error", "Ok", content, parent).Show()
|
dialog.NewCustom("Error", "Ok", content, parent).Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -58,7 +58,7 @@ func infoTab(parent fyne.Window) *fyne.Container {
|
|||||||
|
|
||||||
fwVerString, err := get(types.ReqTypeFwVersion)
|
fwVerString, err := get(types.ReqTypeFwVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
guiErr(err, "Error getting firmware string", true, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fwVer := container.NewVBox(
|
fwVer := container.NewVBox(
|
||||||
@ -99,7 +99,7 @@ func watch(req int, onRecv func(data interface{}), parent fyne.Window) error {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
res, err := getResp(scanner.Bytes())
|
res, err := getResp(scanner.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting response from connection", parent)
|
guiErr(err, "Error getting response from connection", false, parent)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
onRecv(res.Value)
|
onRecv(res.Value)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
)
|
)
|
||||||
@ -13,6 +15,11 @@ func main() {
|
|||||||
// Create new window with title "itgui"
|
// Create new window with title "itgui"
|
||||||
window := a.NewWindow("itgui")
|
window := a.NewWindow("itgui")
|
||||||
|
|
||||||
|
_, err := net.Dial("unix", SockPath)
|
||||||
|
if err != nil {
|
||||||
|
guiErr(err, "Error dialing itd socket", true, window)
|
||||||
|
}
|
||||||
|
|
||||||
// Create new app tabs container
|
// Create new app tabs container
|
||||||
tabs := container.NewAppTabs(
|
tabs := container.NewAppTabs(
|
||||||
container.NewTabItem("Info", infoTab(window)),
|
container.NewTabItem("Info", infoTab(window)),
|
||||||
|
@ -25,7 +25,7 @@ func notifyTab(parent fyne.Window) *fyne.Container {
|
|||||||
// Dial itd UNIX socket
|
// Dial itd UNIX socket
|
||||||
conn, err := net.Dial("unix", SockPath)
|
conn, err := net.Dial("unix", SockPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error dialing socket", parent)
|
guiErr(err, "Error dialing socket", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Encode notify request on connection
|
// Encode notify request on connection
|
||||||
|
@ -29,7 +29,7 @@ func timeTab(parent fyne.Window) *fyne.Container {
|
|||||||
// Parse time as RFC1123 string
|
// Parse time as RFC1123 string
|
||||||
parsedTime, err := time.Parse(time.RFC1123, timeEntry.Text)
|
parsedTime, err := time.Parse(time.RFC1123, timeEntry.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error parsing time string", parent)
|
guiErr(err, "Error parsing time string", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Set time to parsed time
|
// Set time to parsed time
|
||||||
|
@ -92,7 +92,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
|||||||
// If archive path does not exist and both init packet and firmware paths
|
// If archive path does not exist and both init packet and firmware paths
|
||||||
// also do not exist, return error
|
// also do not exist, return error
|
||||||
if archivePath == "" && (initPktPath == "" && fiwmarePath == "") {
|
if archivePath == "" && (initPktPath == "" && fiwmarePath == "") {
|
||||||
guiErr(nil, "Upgrade requires archive or files selected", parent)
|
guiErr(nil, "Upgrade requires archive or files selected", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
|||||||
// Dial itd UNIX socket
|
// Dial itd UNIX socket
|
||||||
conn, err := net.Dial("unix", SockPath)
|
conn, err := net.Dial("unix", SockPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error dialing socket", parent)
|
guiErr(err, "Error dialing socket", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@ -150,18 +150,18 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
|||||||
// Decode scanned line into response struct
|
// Decode scanned line into response struct
|
||||||
err = json.Unmarshal(scanner.Bytes(), &res)
|
err = json.Unmarshal(scanner.Bytes(), &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error decoding response", parent)
|
guiErr(err, "Error decoding response", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if res.Error {
|
if res.Error {
|
||||||
guiErr(err, "Error returned in response", parent)
|
guiErr(err, "Error returned in response", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var event types.DFUProgress
|
var event types.DFUProgress
|
||||||
// Decode response data into progress struct
|
// Decode response data into progress struct
|
||||||
err = mapstructure.Decode(res.Value, &event)
|
err = mapstructure.Decode(res.Value, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error decoding response value", parent)
|
guiErr(err, "Error decoding response value", false, parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If transfer finished, break
|
// If transfer finished, break
|
||||||
|
Loading…
Reference in New Issue
Block a user