2021-08-26 04:18:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
2021-08-27 15:47:24 +00:00
|
|
|
"os"
|
2021-08-26 04:18:24 +00:00
|
|
|
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/canvas"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/dialog"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
2021-08-27 15:47:24 +00:00
|
|
|
func guiErr(err error, msg string, fatal bool, parent fyne.Window) {
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new label containing message
|
2021-08-26 04:18:24 +00:00
|
|
|
msgLbl := widget.NewLabel(msg)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Text formatting settings
|
2021-08-26 04:18:24 +00:00
|
|
|
msgLbl.Wrapping = fyne.TextWrapWord
|
|
|
|
msgLbl.Alignment = fyne.TextAlignCenter
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new rectangle to set the size of the dialog
|
2021-08-26 04:18:24 +00:00
|
|
|
rect := canvas.NewRectangle(color.Transparent)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Set minimum size of rectangle to 350x0
|
2021-08-26 04:18:24 +00:00
|
|
|
rect.SetMinSize(fyne.NewSize(350, 0))
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new container containing message and rectangle
|
2021-08-26 04:18:24 +00:00
|
|
|
content := container.NewVBox(
|
|
|
|
msgLbl,
|
|
|
|
rect,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new label containing error text
|
2021-08-26 04:18:24 +00:00
|
|
|
errLbl := widget.NewLabel(err.Error())
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new dropdown containing error label
|
2021-08-26 04:18:24 +00:00
|
|
|
content.Add(widget.NewAccordion(
|
|
|
|
widget.NewAccordionItem("More Details", errLbl),
|
|
|
|
))
|
|
|
|
}
|
2021-08-27 15:47:24 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2021-08-26 04:18:24 +00:00
|
|
|
}
|