82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/op"
|
|
"gioui.org/unit"
|
|
|
|
"softbox.local/app-modern/platform/windows"
|
|
softboxgio "softbox.local/app-modern/ui/gio"
|
|
"softbox.local/core"
|
|
"softbox.local/core/application"
|
|
)
|
|
|
|
const applicationEventCapacity = 32
|
|
|
|
func main() {
|
|
go func() {
|
|
if err := run(); err != nil {
|
|
log.Printf("%s stopped: %v", core.ProductName, err)
|
|
}
|
|
os.Exit(0)
|
|
}()
|
|
app.Main()
|
|
}
|
|
|
|
func run() error {
|
|
platform := windows.New()
|
|
window := new(app.Window)
|
|
window.Option(
|
|
app.Title(core.ProductName),
|
|
app.Size(unit.Dp(1080), unit.Dp(720)),
|
|
)
|
|
|
|
theme := softboxgio.NewTheme()
|
|
shell := softboxgio.NewAppShell(string(platform.Edition()))
|
|
runtime := application.NewRuntime(applicationEventCapacity)
|
|
relay, err := application.NewEventRelay(applicationEventCapacity)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
eventContext, cancelEvents := context.WithCancel(context.Background())
|
|
pumpDone := make(chan error, 1)
|
|
go func() {
|
|
pumpDone <- application.PumpEvents(
|
|
eventContext,
|
|
runtime.Events(),
|
|
relay,
|
|
window.Invalidate,
|
|
)
|
|
}()
|
|
defer func() {
|
|
cancelEvents()
|
|
runtime.Close()
|
|
relay.Close()
|
|
if pumpErr := <-pumpDone; pumpErr != nil &&
|
|
!errors.Is(pumpErr, context.Canceled) &&
|
|
!errors.Is(pumpErr, application.ErrEventRelayClosed) {
|
|
log.Printf("application event pump stopped: %v", pumpErr)
|
|
}
|
|
}()
|
|
var operations op.Ops
|
|
|
|
for {
|
|
switch event := window.Event().(type) {
|
|
case app.DestroyEvent:
|
|
return event.Err
|
|
case app.FrameEvent:
|
|
if err := relay.Drain(shell.ApplyEvent); err != nil {
|
|
log.Printf("apply application event: %v", err)
|
|
}
|
|
context := app.NewContext(&operations, event)
|
|
shell.Layout(context, theme)
|
|
event.Frame(context.Ops)
|
|
}
|
|
}
|
|
}
|