79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/wailsapp/wails/v2"
|
|
"github.com/wailsapp/wails/v2/pkg/options"
|
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
|
"gitlab.com/revoluterra-dev/common/helpers/trace"
|
|
)
|
|
|
|
//go:embed all:frontend/dist
|
|
var assets embed.FS
|
|
|
|
func main() {
|
|
// Create an instance of the app structure
|
|
app := NewApp()
|
|
|
|
echo := NewEcho(context.Background(), nil)
|
|
backendGroup := echo.Group("/backend")
|
|
|
|
RegisterApi(backendGroup.Group(""))
|
|
|
|
go StartServer(context.Background(),
|
|
8888,
|
|
echo,
|
|
func() {})
|
|
|
|
// Create application with options
|
|
err := wails.Run(&options.App{
|
|
Title: "Timon",
|
|
Width: 1024,
|
|
Height: 768,
|
|
AssetServer: &assetserver.Options{
|
|
Assets: assets,
|
|
},
|
|
BackgroundColour: options.NewRGB(255, 255, 255),
|
|
OnStartup: app.startup,
|
|
Bind: []interface{}{
|
|
app,
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
println("Error:", err.Error())
|
|
}
|
|
}
|
|
|
|
func StartServer(ctx context.Context, port int64, router http.Handler, doneCallback func()) {
|
|
srv := &http.Server{
|
|
Addr: fmt.Sprintf(":%d", port),
|
|
Handler: router,
|
|
BaseContext: func(net.Listener) context.Context { return ctx },
|
|
}
|
|
|
|
go func() {
|
|
var err error
|
|
|
|
err = srv.ListenAndServe()
|
|
|
|
if err != nil && !trace.Is(err, http.ErrServerClosed) {
|
|
println(fmt.Sprintf("listen failed: %s\n", err))
|
|
}
|
|
doneCallback()
|
|
}()
|
|
|
|
<-ctx.Done()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
|
defer cancel()
|
|
if err := srv.Shutdown(ctx); err != nil {
|
|
println(fmt.Sprintf("service shutdown failed: %s\n", err))
|
|
}
|
|
}
|