|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"log"
|
|
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
|
+ "github.com/wailsapp/wails/v3/pkg/events"
|
|
|
|
|
|
"git.monoexp.com/bajdev/mpckit/internal/app"
|
|
|
)
|
|
|
@@ -15,6 +16,13 @@ import (
|
|
|
//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",
|
|
|
@@ -30,17 +38,42 @@ func main() {
|
|
|
},
|
|
|
})
|
|
|
|
|
|
- a.Window.NewWithOptions(application.WebviewWindowOptions{
|
|
|
+ // 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: 1280,
|
|
|
- Height: 860,
|
|
|
- MinWidth: 760,
|
|
|
- MinHeight: 600,
|
|
|
+ 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)
|
|
|
+}
|