// Command mpckit is the desktop kit editor for the MPC Sample. package main import ( "embed" "log" "github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/events" "git.monoexp.com/bajdev/mpckit/internal/app" ) // The built Svelte app (frontend/dist), embedded in the binary. // //go:embed all:frontend/dist var assets embed.FS // Window sizes are in device-independent pixels, 16:9 like most displays. const ( maxWidth, maxHeight = 1280, 720 // largest default size minWidth, minHeight = 960, 540 // smallest the layout is designed for screenShare = 0.9 // default size: this share of the screen's work area ) func main() { a := application.New(application.Options{ Name: "mpckit", Description: "Desktop kit editor for the MPC Sample", Services: []application.Service{ application.NewService(app.NewService()), }, Assets: application.AssetOptions{ Handler: application.AssetFileServerFS(assets), }, Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Start hidden and size the window once the screens are known, so it // fits the display instead of being clamped by it. w := a.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "mpckit", Width: maxWidth, Height: maxHeight, MinWidth: minWidth, MinHeight: minHeight, Hidden: true, BackgroundColour: application.NewRGB(0x15, 0x17, 0x1A), URL: "/", }) a.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) { if s := a.Screen.GetPrimary(); s != nil { width, height := fitSize(s.WorkArea.Width, s.WorkArea.Height) w.SetSize(width, height) } w.Center() w.Show() }) if err := a.Run(); err != nil { log.Fatal(err) } } // fitSize returns a 16:9 window size that takes screenShare of the work // area (areaW x areaH), capped at maxWidth x maxHeight and no smaller than // minWidth x minHeight. func fitSize(areaW, areaH int) (int, int) { width := min(maxWidth, int(float64(areaW)*screenShare)) height := width * 9 / 16 if limit := int(float64(areaH) * screenShare); height > limit { height = limit width = height * 16 / 9 } return max(width, minWidth), max(height, minHeight) }