wip
Some checks failed
CloudSave/pipeline/head There was a failure building this commit

This commit is contained in:
2025-09-12 19:06:52 +02:00
parent 57fc77755e
commit b36142c309
5 changed files with 157 additions and 81 deletions

View File

@@ -42,16 +42,5 @@ func main() {
s := data.NewService(repo) s := data.NewService(repo)
w := mainwindow.Make(a, s) w := mainwindow.Make(a, s)
defer func() {
if r := recover(); r != nil {
d := dialog.NewError(fmt.Errorf("the application crashed: %s", r), w)
d.Show()
d.SetOnClosed(func() {
os.Exit(1)
})
}
}()
w.ShowAndRun() w.ShowAndRun()
} }

View File

@@ -18,7 +18,7 @@ type (
) )
func Make(remoteHostname string, callback func(ok bool, username, password string), w fyne.Window) *CredentialDialog { func Make(remoteHostname string, callback func(ok bool, username, password string), w fyne.Window) *CredentialDialog {
label := canvas.NewText("Connexion to "+remoteHostname, color.Black) label := canvas.NewText(remoteHostname, color.Black)
inputUsername := widget.NewEntry() inputUsername := widget.NewEntry()
inputUsername.SetPlaceHolder("Username") inputUsername.SetPlaceHolder("Username")
@@ -29,7 +29,7 @@ func Make(remoteHostname string, callback func(ok bool, username, password strin
formItems := []*widget.FormItem{ formItems := []*widget.FormItem{
{ {
Text: "", Text: "Connexion to ",
Widget: label, Widget: label,
}, },
{ {

View File

@@ -4,6 +4,7 @@ import (
"cloudsave/cmd/gui/window/about" "cloudsave/cmd/gui/window/about"
"cloudsave/cmd/gui/window/credential" "cloudsave/cmd/gui/window/credential"
"cloudsave/cmd/gui/window/loading" "cloudsave/cmd/gui/window/loading"
"cloudsave/cmd/gui/window/properties"
syncdialog "cloudsave/cmd/gui/window/sync" syncdialog "cloudsave/cmd/gui/window/sync"
"cloudsave/pkg/data" "cloudsave/pkg/data"
@@ -36,8 +37,19 @@ func (e *ExtraLabel) SetID(id string) {
func Make(a fyne.App, d *data.Service) fyne.Window { func Make(a fyne.App, d *data.Service) fyne.Window {
w := a.NewWindow("CloudSave") w := a.NewWindow("CloudSave")
w.Resize(fyne.NewSize(1000, 700)) w.Resize(fyne.NewSize(1200, 700))
w.CenterOnScreen() w.CenterOnScreen()
w.SetFixedSize(true)
defer func() {
if r := recover(); r != nil {
d := dialog.NewError(fmt.Errorf("the application crashed: %s", r), w)
d.Show()
d.SetOnClosed(func() {
os.Exit(1)
})
}
}()
games, err := d.AllGames() games, err := d.AllGames()
if err != nil { if err != nil {
@@ -61,74 +73,29 @@ func Make(a fyne.App, d *data.Service) fyne.Window {
}) })
list.OnSelected = func(id widget.ListItemID) { list.OnSelected = func(id widget.ListItemID) {
fmt.Println(id) properties.Make(a, games[id]).Show()
} }
toolbar := widget.NewToolbar( toolbar := widget.NewToolbar(
widget.NewToolbarAction(theme.FolderNewIcon(), func() { makeNewButton(d, w, func() {
folderSelection := dialog.NewFolderOpen(func(lu fyne.ListableURI, err error) {
if err != nil {
d := dialog.NewError(fmt.Errorf("failed to open window: %w", err), w)
d.Show()
return
}
if lu == nil {
return
}
confirmDialog := dialog.NewConfirm("Add", "Do you want to add and scan '"+lu.Path()+"'?", func(accepted bool) {
if !accepted {
return
}
name := filepath.Base(lu.Path())
loadingDialog := loading.Make("Scanning directory", w)
loadingDialog.Show()
go func() {
gameID, err := d.Add(name, lu.Path(), "")
if err != nil {
fyne.Do(func() {
d := dialog.NewError(fmt.Errorf("failed to create metadata the directory: %w", err), w)
d.Show()
loadingDialog.Hide()
})
return
}
_, err = d.Scan(gameID)
if err != nil {
fyne.Do(func() {
d := dialog.NewError(fmt.Errorf("failed to scan the directory: %w", err), w)
d.Show()
loadingDialog.Hide()
})
return
}
games, err = d.AllGames() games, err = d.AllGames()
if err != nil { if err != nil {
fyne.Do(func() { fyne.Do(func() {
d := dialog.NewError(fmt.Errorf("failed to load datastore: %w", err), w) d := dialog.NewError(fmt.Errorf("failed to load datastore: %w", err), w)
d.Show() d.Show()
loadingDialog.Hide()
}) })
return return
} }
fyne.Do(func() { fyne.Do(func() {
list.Refresh() list.Refresh()
loadingDialog.Hide()
}) })
}()
}, w)
confirmDialog.Show()
}, w)
folderSelection.Show()
}), }),
widget.NewToolbarSeparator(), widget.NewToolbarSeparator(),
widget.NewToolbarAction(theme.UploadIcon(), func() { widget.NewToolbarAction(theme.UploadIcon(), func() {
doSync(d, w) doSync(d, w)
}), }),
makeScanButton(d, w),
widget.NewToolbarSpacer(), widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.HelpIcon(), func() { widget.NewToolbarAction(theme.HelpIcon(), func() {
aboutWindow := about.Make(a) aboutWindow := about.Make(a)
@@ -223,3 +190,96 @@ func syncing(it *iterator.Iterator[remote.Remote], d *data.Service, w fyne.Windo
} }
} }
} }
func makeNewButton(d *data.Service, w fyne.Window, callback func()) *widget.ToolbarAction {
return widget.NewToolbarAction(theme.FolderNewIcon(), func() {
folderSelection := dialog.NewFolderOpen(func(lu fyne.ListableURI, err error) {
if err != nil {
d := dialog.NewError(fmt.Errorf("failed to open window: %w", err), w)
d.Show()
return
}
if lu == nil {
return
}
confirmDialog := dialog.NewConfirm("Add", "Do you want to add and scan '"+lu.Path()+"'?", func(accepted bool) {
if !accepted {
return
}
name := filepath.Base(lu.Path())
loadingDialog := loading.Make("Scanning directory", w)
loadingDialog.Show()
go func() {
gameID, err := d.Add(name, lu.Path(), "")
if err != nil {
fyne.Do(func() {
d := dialog.NewError(fmt.Errorf("failed to create metadata the directory: %w", err), w)
d.Show()
loadingDialog.Hide()
})
return
}
_, err = d.Scan(gameID)
if err != nil {
fyne.Do(func() {
d := dialog.NewError(fmt.Errorf("failed to scan the directory: %w", err), w)
d.Show()
loadingDialog.Hide()
})
return
}
loadingDialog.Hide()
callback()
}()
}, w)
confirmDialog.Show()
}, w)
folderSelection.Show()
})
}
func makeScanButton(d *data.Service, w fyne.Window) *widget.ToolbarAction {
return widget.NewToolbarAction(theme.SearchIcon(), func() {
loadingDialog := loading.Make("Scanning directory", w)
loadingDialog.Show()
go func() {
datastore, err := d.AllGames()
if err != nil {
fyne.Do(func() {
dialog.NewError(fmt.Errorf("failed to load datastore: %w", err), w)
loadingDialog.Hide()
})
}
updated := 0
for _, metadata := range datastore {
changed, err := d.Scan(metadata.ID)
if err != nil {
fyne.Do(func() {
dialog.NewError(fmt.Errorf("failed to load datastore: %w", err), w)
loadingDialog.Hide()
})
return
}
if changed {
updated++
}
}
fyne.Do(func() {
loadingDialog.Hide()
if updated == 0 {
dialog.NewInformation("Scan", "Everything is up to date", w).Show()
} else {
dialog.NewInformation("Scan", fmt.Sprintf("%d game updated", updated), w).Show()
}
})
}()
})
}

View File

@@ -0,0 +1,33 @@
package properties
import (
"cloudsave/pkg/repository"
"image/color"
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
)
func Make(a fyne.App, g repository.Metadata) fyne.Window {
w := a.NewWindow(g.Name)
w.Resize(fyne.NewSize(800, 300))
w.CenterOnScreen()
w.SetFixedSize(true)
title := canvas.NewText(g.Name, color.Black)
title.Alignment = fyne.TextAlignCenter
title.TextSize = 32
version := canvas.NewText("Version "+strconv.Itoa(g.Version), color.Black)
version.Alignment = fyne.TextAlignCenter
version.TextSize = 18
c := container.New(layout.NewVBoxLayout(), title, version)
centered := container.New(layout.NewHBoxLayout(), layout.NewSpacer(), c, layout.NewSpacer())
w.SetContent(container.New(layout.NewVBoxLayout(), centered))
return w
}

View File

@@ -15,7 +15,7 @@ type (
SyncDialog struct { SyncDialog struct {
*dialog.CustomDialog *dialog.CustomDialog
label *canvas.Text label *canvas.Text
pg *widget.ProgressBar pg *widget.ProgressBarInfinite
} }
) )
@@ -24,8 +24,7 @@ func Make(total int, w fyne.Window) *SyncDialog {
title := canvas.NewText("Warming up...", color.Black) title := canvas.NewText("Warming up...", color.Black)
title.Alignment = fyne.TextAlignCenter title.Alignment = fyne.TextAlignCenter
pg := widget.NewProgressBar() pg := widget.NewProgressBarInfinite()
pg.Max = float64(total)
c := container.New(layout.NewVBoxLayout(), title, pg) c := container.New(layout.NewVBoxLayout(), title, pg)
d := &SyncDialog{ d := &SyncDialog{
@@ -38,10 +37,5 @@ func Make(total int, w fyne.Window) *SyncDialog {
func (s *SyncDialog) UpdateLabel(msg string) { func (s *SyncDialog) UpdateLabel(msg string) {
s.label.Text = msg s.label.Text = msg
s.Refresh() s.label.Refresh()
}
func (s *SyncDialog) UpdateProgressBar(percentage int) {
s.pg.Value = float64(percentage)
s.Refresh()
} }