This commit is contained in:
@@ -2,8 +2,12 @@ package mainwindow
|
||||
|
||||
import (
|
||||
"cloudsave/cmd/gui/window/about"
|
||||
"cloudsave/cmd/gui/window/credential"
|
||||
"cloudsave/cmd/gui/window/loading"
|
||||
"cloudsave/pkg/data"
|
||||
"cloudsave/pkg/remote"
|
||||
"cloudsave/pkg/remote/client"
|
||||
"cloudsave/pkg/sync"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -103,9 +107,7 @@ func Make(a fyne.App, d *data.Service) fyne.Window {
|
||||
}),
|
||||
widget.NewToolbarSeparator(),
|
||||
widget.NewToolbarAction(theme.UploadIcon(), func() {
|
||||
go func() {
|
||||
fmt.Println("todo")
|
||||
}()
|
||||
doSync(d, w)
|
||||
}),
|
||||
widget.NewToolbarSpacer(),
|
||||
widget.NewToolbarAction(theme.HelpIcon(), func() {
|
||||
@@ -118,3 +120,54 @@ func Make(a fyne.App, d *data.Service) fyne.Window {
|
||||
w.SetContent(content)
|
||||
return w
|
||||
}
|
||||
|
||||
func doSync(d *data.Service, w fyne.Window) error {
|
||||
remotes, err := remote.All()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i := 0
|
||||
nextCh := make(chan struct{})
|
||||
doneCh := make(chan struct{})
|
||||
|
||||
var cd *credential.CredentialDialog
|
||||
|
||||
go func() {
|
||||
nextCh <- struct{}{}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-doneCh:
|
||||
return nil
|
||||
case <-nextCh:
|
||||
{
|
||||
cd = credential.Make(remotes[i].URL, func(v bool) {
|
||||
if !v {
|
||||
return
|
||||
}
|
||||
|
||||
username, password := cd.Credentials()
|
||||
cli := client.New(remotes[i].URL, username, password)
|
||||
|
||||
sync.NewSyncer(cli, d)
|
||||
|
||||
fmt.Println(i)
|
||||
|
||||
if i < len(remotes) {
|
||||
go func() {
|
||||
nextCh <- struct{}{}
|
||||
}()
|
||||
} else {
|
||||
go func() {
|
||||
doneCh <- struct{}{}
|
||||
}()
|
||||
}
|
||||
|
||||
}, w)
|
||||
cd.Show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user