mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 21:10:54 +08:00
[windows] Support more runtime methods,
WindowCenter, WindowMaximise,WindowUnmaximise,WindowMinimise,WindowUnminimise, WindowSetPos,WindowSetSize Settings: DisableWindowIcon, StartHidden, HideWindowOnClose
This commit is contained in:
parent
ccda8c5760
commit
0ea135a546
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user