forked from Elara6331/itd
Add fatal error dialog
This commit is contained in:
parent
f4d2f4e6eb
commit
44607ba9e2
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"os"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
"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
|
||||
msgLbl := widget.NewLabel(msg)
|
||||
// Text formatting settings
|
||||
@ -33,6 +34,20 @@ func guiErr(err error, msg string, parent fyne.Window) {
|
||||
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
|
||||
dialog.NewCustom("Error", "Ok", content, parent).Show()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func infoTab(parent fyne.Window) *fyne.Container {
|
||||
|
||||
fwVerString, err := get(types.ReqTypeFwVersion)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
guiErr(err, "Error getting firmware string", true, parent)
|
||||
}
|
||||
|
||||
fwVer := container.NewVBox(
|
||||
@ -99,7 +99,7 @@ func watch(req int, onRecv func(data interface{}), parent fyne.Window) error {
|
||||
for scanner.Scan() {
|
||||
res, err := getResp(scanner.Bytes())
|
||||
if err != nil {
|
||||
guiErr(err, "Error getting response from connection", parent)
|
||||
guiErr(err, "Error getting response from connection", false, parent)
|
||||
continue
|
||||
}
|
||||
onRecv(res.Value)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
)
|
||||
@ -13,6 +15,11 @@ func main() {
|
||||
// Create new window with title "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
|
||||
tabs := container.NewAppTabs(
|
||||
container.NewTabItem("Info", infoTab(window)),
|
||||
|
@ -25,7 +25,7 @@ func notifyTab(parent fyne.Window) *fyne.Container {
|
||||
// Dial itd UNIX socket
|
||||
conn, err := net.Dial("unix", SockPath)
|
||||
if err != nil {
|
||||
guiErr(err, "Error dialing socket", parent)
|
||||
guiErr(err, "Error dialing socket", false, parent)
|
||||
return
|
||||
}
|
||||
// Encode notify request on connection
|
||||
|
@ -29,7 +29,7 @@ func timeTab(parent fyne.Window) *fyne.Container {
|
||||
// Parse time as RFC1123 string
|
||||
parsedTime, err := time.Parse(time.RFC1123, timeEntry.Text)
|
||||
if err != nil {
|
||||
guiErr(err, "Error parsing time string", parent)
|
||||
guiErr(err, "Error parsing time string", false, parent)
|
||||
return
|
||||
}
|
||||
// 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
|
||||
// also do not exist, return error
|
||||
if archivePath == "" && (initPktPath == "" && fiwmarePath == "") {
|
||||
guiErr(nil, "Upgrade requires archive or files selected", parent)
|
||||
guiErr(nil, "Upgrade requires archive or files selected", false, parent)
|
||||
return
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
// Dial itd UNIX socket
|
||||
conn, err := net.Dial("unix", SockPath)
|
||||
if err != nil {
|
||||
guiErr(err, "Error dialing socket", parent)
|
||||
guiErr(err, "Error dialing socket", false, parent)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
@ -150,18 +150,18 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
// Decode scanned line into response struct
|
||||
err = json.Unmarshal(scanner.Bytes(), &res)
|
||||
if err != nil {
|
||||
guiErr(err, "Error decoding response", parent)
|
||||
guiErr(err, "Error decoding response", false, parent)
|
||||
return
|
||||
}
|
||||
if res.Error {
|
||||
guiErr(err, "Error returned in response", parent)
|
||||
guiErr(err, "Error returned in response", false, parent)
|
||||
return
|
||||
}
|
||||
var event types.DFUProgress
|
||||
// Decode response data into progress struct
|
||||
err = mapstructure.Decode(res.Value, &event)
|
||||
if err != nil {
|
||||
guiErr(err, "Error decoding response value", parent)
|
||||
guiErr(err, "Error decoding response value", false, parent)
|
||||
return
|
||||
}
|
||||
// If transfer finished, break
|
||||
|
Loading…
Reference in New Issue
Block a user