forked from Elara6331/itd
Add comments to gui
This commit is contained in:
@@ -23,6 +23,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
initPktPath string
|
||||
)
|
||||
|
||||
// Create archive selection dialog
|
||||
archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
|
||||
if e != nil || uc == nil {
|
||||
return
|
||||
@@ -30,9 +31,12 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
uc.Close()
|
||||
archivePath = uc.URI().Path()
|
||||
}, parent)
|
||||
// Limit dialog to .zip files
|
||||
archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"}))
|
||||
// Create button to show dialog
|
||||
archiveBtn := widget.NewButton("Select archive (.zip)", archiveDialog.Show)
|
||||
|
||||
// Create firmware selection dialog
|
||||
firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
|
||||
if e != nil || uc == nil {
|
||||
return
|
||||
@@ -40,9 +44,12 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
uc.Close()
|
||||
fiwmarePath = uc.URI().Path()
|
||||
}, parent)
|
||||
// Limit dialog to .bin files
|
||||
firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"}))
|
||||
// Create button to show dialog
|
||||
firmwareBtn := widget.NewButton("Select init packet (.bin)", firmwareDialog.Show)
|
||||
|
||||
// Create init packet selection dialog
|
||||
initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
|
||||
if e != nil || uc == nil {
|
||||
return
|
||||
@@ -50,19 +57,25 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
uc.Close()
|
||||
initPktPath = uc.URI().Path()
|
||||
}, parent)
|
||||
// Limit dialog to .dat files
|
||||
initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"}))
|
||||
// Create button to show dialog
|
||||
initPktBtn := widget.NewButton("Select init packet (.dat)", initPktDialog.Show)
|
||||
|
||||
// Hide init packet and firmware buttons
|
||||
initPktBtn.Hide()
|
||||
firmwareBtn.Hide()
|
||||
|
||||
// Create dropdown to select upgrade type
|
||||
upgradeTypeSelect := widget.NewSelect([]string{
|
||||
"Archive",
|
||||
"Files",
|
||||
}, func(s string) {
|
||||
// Hide all buttons
|
||||
archiveBtn.Hide()
|
||||
initPktBtn.Hide()
|
||||
firmwareBtn.Hide()
|
||||
// Unhide appropriate button(s)
|
||||
switch s {
|
||||
case "Archive":
|
||||
archiveBtn.Show()
|
||||
@@ -71,26 +84,35 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
firmwareBtn.Show()
|
||||
}
|
||||
})
|
||||
// Select first elemetn
|
||||
upgradeTypeSelect.SetSelectedIndex(0)
|
||||
|
||||
// Create new button to start DFU
|
||||
startBtn := widget.NewButton("Start", func() {
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
|
||||
// Create new label for byte progress
|
||||
progressLbl := widget.NewLabelWithStyle("0 / 0 B", fyne.TextAlignCenter, fyne.TextStyle{})
|
||||
// Create new progress bar
|
||||
progressBar := widget.NewProgressBar()
|
||||
// Create modal dialog containing label and progress bar
|
||||
progressDlg := widget.NewModalPopUp(container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
progressLbl,
|
||||
progressBar,
|
||||
layout.NewSpacer(),
|
||||
), parent.Canvas())
|
||||
// Resize modal to 300x100
|
||||
progressDlg.Resize(fyne.NewSize(300, 100))
|
||||
|
||||
var fwUpgType int
|
||||
var files []string
|
||||
// Get appropriate upgrade type and file paths
|
||||
switch upgradeTypeSelect.Selected {
|
||||
case "Archive":
|
||||
fwUpgType = types.UpgradeTypeArchive
|
||||
@@ -100,6 +122,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
files = append(files, initPktPath, fiwmarePath)
|
||||
}
|
||||
|
||||
// Dial itd UNIX socket
|
||||
conn, err := net.Dial("unix", SockPath)
|
||||
if err != nil {
|
||||
guiErr(err, "Error dialing socket", parent)
|
||||
@@ -107,6 +130,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Encode firmware upgrade request to connection
|
||||
json.NewEncoder(conn).Encode(types.Request{
|
||||
Type: types.ReqTypeFwUpgrade,
|
||||
Data: types.ReqDataFwUpgrade{
|
||||
@@ -115,7 +139,10 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
},
|
||||
})
|
||||
|
||||
// Show progress dialog
|
||||
progressDlg.Show()
|
||||
// Hide progress dialog after completion
|
||||
defer progressDlg.Hide()
|
||||
|
||||
scanner := bufio.NewScanner(conn)
|
||||
for scanner.Scan() {
|
||||
@@ -141,16 +168,17 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
|
||||
if event.Received == event.Total {
|
||||
break
|
||||
}
|
||||
// Set label text to received / total B
|
||||
progressLbl.SetText(fmt.Sprintf("%d / %d B", event.Received, event.Total))
|
||||
// Set progress bar values
|
||||
progressBar.Max = float64(event.Total)
|
||||
progressBar.Value = float64(event.Received)
|
||||
// Refresh progress bar
|
||||
progressBar.Refresh()
|
||||
}
|
||||
conn.Close()
|
||||
|
||||
progressDlg.Hide()
|
||||
})
|
||||
|
||||
// Return container containing all elements
|
||||
return container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
upgradeTypeSelect,
|
||||
|
||||
Reference in New Issue
Block a user