forked from Elara6331/itd
Add resource loading to ITD FS tab
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"go.arsenm.dev/infinitime"
|
||||
"go.arsenm.dev/itd/api"
|
||||
)
|
||||
|
||||
@@ -53,6 +55,52 @@ func fsTab(ctx context.Context, client *api.Client, w fyne.Window, opened chan s
|
||||
refresh(ctx, cwdData, lsData, client, w, c)
|
||||
},
|
||||
),
|
||||
widget.NewToolbarAction(
|
||||
theme.FileApplicationIcon(),
|
||||
func() {
|
||||
dlg := dialog.NewFileOpen(func(uc fyne.URIReadCloser, err error) {
|
||||
if err != nil || uc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
resPath := uc.URI().Path()
|
||||
uc.Close()
|
||||
|
||||
progressDlg := newProgress(w)
|
||||
progressDlg.Show()
|
||||
|
||||
progCh, err := client.LoadResources(ctx, resPath)
|
||||
if err != nil {
|
||||
guiErr(err, "Error loading resources", false, w)
|
||||
return
|
||||
}
|
||||
|
||||
for evt := range progCh {
|
||||
if evt.Err != nil {
|
||||
guiErr(evt.Err, "Error loading resources", false, w)
|
||||
return
|
||||
}
|
||||
|
||||
switch evt.Operation {
|
||||
case infinitime.ResourceOperationRemoveObsolete:
|
||||
progressDlg.SetText("Removing " + evt.Name)
|
||||
case infinitime.ResourceOperationUpload:
|
||||
progressDlg.SetText("Uploading " + evt.Name)
|
||||
progressDlg.SetTotal(float64(evt.Total))
|
||||
progressDlg.SetValue(float64(evt.Sent))
|
||||
}
|
||||
}
|
||||
|
||||
progressDlg.Hide()
|
||||
refresh(ctx, cwdData, lsData, client, w, c)
|
||||
}, w)
|
||||
dlg.SetConfirmText("Upload Resources")
|
||||
dlg.SetFilter(storage.NewExtensionFileFilter([]string{
|
||||
".zip",
|
||||
}))
|
||||
dlg.Show()
|
||||
},
|
||||
),
|
||||
widget.NewToolbarAction(
|
||||
theme.UploadIcon(),
|
||||
func() {
|
||||
@@ -113,7 +161,6 @@ func fsTab(ctx context.Context, client *api.Client, w fyne.Window, opened chan s
|
||||
uploadDlg.Show()
|
||||
}, w)
|
||||
dlg.Show()
|
||||
|
||||
},
|
||||
),
|
||||
widget.NewToolbarAction(
|
||||
|
||||
@@ -11,17 +11,21 @@ import (
|
||||
)
|
||||
|
||||
type progress struct {
|
||||
lbl *widget.Label
|
||||
pb *widget.ProgressBar
|
||||
lbl *widget.Label
|
||||
progLbl *widget.Label
|
||||
pb *widget.ProgressBar
|
||||
*widget.PopUp
|
||||
}
|
||||
|
||||
func newProgress(w fyne.Window) progress {
|
||||
out := progress{}
|
||||
|
||||
out.lbl = widget.NewLabel("")
|
||||
out.lbl.Hide()
|
||||
|
||||
// Create label to show how many bytes transfered and center it
|
||||
out.lbl = widget.NewLabel("0 / 0 B")
|
||||
out.lbl.Alignment = fyne.TextAlignCenter
|
||||
out.progLbl = widget.NewLabel("0 / 0 B")
|
||||
out.progLbl.Alignment = fyne.TextAlignCenter
|
||||
|
||||
// Create new progress bar
|
||||
out.pb = widget.NewProgressBar()
|
||||
@@ -31,20 +35,30 @@ func newProgress(w fyne.Window) progress {
|
||||
sizeRect.SetMinSize(fyne.NewSize(300, 50))
|
||||
|
||||
// Create vbox for label and progress bar
|
||||
l := container.NewVBox(out.lbl, out.pb)
|
||||
l := container.NewVBox(out.lbl, out.progLbl, out.pb)
|
||||
// Create popup
|
||||
out.PopUp = widget.NewModalPopUp(container.NewMax(l, sizeRect), w.Canvas())
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (p progress) SetText(s string) {
|
||||
p.lbl.SetText(s)
|
||||
|
||||
if s == "" {
|
||||
p.lbl.Hide()
|
||||
} else {
|
||||
p.lbl.Show()
|
||||
}
|
||||
}
|
||||
|
||||
func (p progress) SetTotal(v float64) {
|
||||
p.pb.Max = v
|
||||
p.pb.Refresh()
|
||||
p.lbl.SetText(fmt.Sprintf("%.0f / %.0f B", p.pb.Value, v))
|
||||
p.progLbl.SetText(fmt.Sprintf("%.0f / %.0f B", p.pb.Value, v))
|
||||
}
|
||||
|
||||
func (p progress) SetValue(v float64) {
|
||||
p.pb.SetValue(v)
|
||||
p.lbl.SetText(fmt.Sprintf("%.0f / %.0f B", v, p.pb.Max))
|
||||
p.progLbl.SetText(fmt.Sprintf("%.0f / %.0f B", v, p.pb.Max))
|
||||
}
|
||||
|
||||
BIN
cmd/itgui/screenshots/resources.png
Normal file
BIN
cmd/itgui/screenshots/resources.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user