From 0ea135a546b41277d878c8566e980d7315580a09 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 24 Jul 2021 06:55:47 +1000 Subject: [PATCH] [windows] Support more runtime methods, WindowCenter, WindowMaximise,WindowUnmaximise,WindowMinimise,WindowUnminimise, WindowSetPos,WindowSetSize Settings: DisableWindowIcon, StartHidden, HideWindowOnClose --- v2/internal/frontend/frontend.go | 16 +++---- v2/internal/frontend/windows/frontend.go | 59 ++++++++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/v2/internal/frontend/frontend.go b/v2/internal/frontend/frontend.go index 55eeede18..3f403bcdf 100644 --- a/v2/internal/frontend/frontend.go +++ b/v2/internal/frontend/frontend.go @@ -18,16 +18,16 @@ type Frontend interface { //MessageDialog(dialogOptions dialog.MessageDialogOptions, callbackID string) // Window - //WindowSetTitle(title string) + WindowSetTitle(title string) WindowShow() WindowHide() - //WindowCenter() - //WindowMaximise() - //WindowUnmaximise() - //WindowMinimise() - //WindowUnminimise() - //WindowPosition(x int, y int) - //WindowSize(width int, height int) + WindowCenter() + WindowMaximise() + WindowUnmaximise() + WindowMinimise() + WindowUnminimise() + WindowSetPos(x int, y int) + WindowSetSize(width int, height int) //WindowSetMinSize(width int, height int) //WindowSetMaxSize(width int, height int) WindowFullscreen() diff --git a/v2/internal/frontend/windows/frontend.go b/v2/internal/frontend/windows/frontend.go index 79977d51f..7407a5ede 100644 --- a/v2/internal/frontend/windows/frontend.go +++ b/v2/internal/frontend/windows/frontend.go @@ -6,7 +6,6 @@ import ( "github.com/wailsapp/wails/v2/internal/logger" "github.com/wailsapp/wails/v2/pkg/options" "runtime" - "time" ) type Frontend struct { @@ -40,19 +39,27 @@ func (f *Frontend) Run() error { mainWindow.SetTranslucentBackground() } + if f.options.Windows.DisableWindowIcon { + mainWindow.DisableIcon() + } + + if f.options.StartHidden { + mainWindow.Hide() + } + if f.options.Fullscreen { mainWindow.Fullscreen() } - mainWindow.Center() - mainWindow.Show() + f.WindowCenter() + + if !f.options.StartHidden { + mainWindow.Show() + } + mainWindow.OnClose().Bind(func(arg *winc.Event) { if f.options.HideWindowOnClose { - - go func() { - time.Sleep(1 * time.Second) - f.WindowShow() - }() + f.WindowHide() } else { f.Quit() } @@ -62,6 +69,26 @@ func (f *Frontend) Run() error { return nil } +func (f *Frontend) WindowCenter() { + runtime.LockOSThread() + f.mainWindow.Center() +} + +func (f *Frontend) WindowSetPos(x, y int) { + runtime.LockOSThread() + f.mainWindow.SetPos(x, y) +} + +func (f *Frontend) WindowSetSize(width, height int) { + runtime.LockOSThread() + f.mainWindow.SetSize(width, height) +} + +func (f *Frontend) WindowSetTitle(title string) { + runtime.LockOSThread() + f.mainWindow.SetText(title) +} + func (f *Frontend) WindowFullscreen() { runtime.LockOSThread() f.mainWindow.Fullscreen() @@ -81,6 +108,22 @@ func (f *Frontend) WindowHide() { runtime.LockOSThread() f.mainWindow.Hide() } +func (f *Frontend) WindowMaximise() { + runtime.LockOSThread() + f.mainWindow.Maximise() +} +func (f *Frontend) WindowUnmaximise() { + runtime.LockOSThread() + f.mainWindow.Restore() +} +func (f *Frontend) WindowMinimise() { + runtime.LockOSThread() + f.mainWindow.Minimise() +} +func (f *Frontend) WindowUnminimise() { + runtime.LockOSThread() + f.mainWindow.Restore() +} func (f *Frontend) Quit() { winc.Exit()