This commit is contained in:
57
cmd/gui/main.go
Normal file
57
cmd/gui/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cloudsave/cmd/gui/window/mainwindow"
|
||||
"cloudsave/pkg/data"
|
||||
"cloudsave/pkg/repository"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := app.NewWithID("com.thelilfrog.CloudSave")
|
||||
|
||||
roaming, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
panic("failed to get user config path: " + err.Error())
|
||||
}
|
||||
|
||||
datastorepath := filepath.Join(roaming, "cloudsave", "data")
|
||||
err = os.MkdirAll(datastorepath, 0740)
|
||||
if err != nil {
|
||||
d := dialog.NewError(fmt.Errorf("cannot make the datastore: %w", err), a.NewWindow("CloudSave"))
|
||||
d.Show()
|
||||
d.SetOnClosed(func() {
|
||||
os.Exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
repo, err := repository.NewLazyRepository(datastorepath)
|
||||
if err != nil {
|
||||
d := dialog.NewError(fmt.Errorf("cannot make the datastore: %w", err), a.NewWindow("CloudSave"))
|
||||
d.Show()
|
||||
d.SetOnClosed(func() {
|
||||
os.Exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
s := data.NewService(repo)
|
||||
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user