mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 09:29:30 +08:00
Remove resize debounce setting for windows.
Optimise resizing performance on windows automatically.
This commit is contained in:
parent
0ebb21f0fb
commit
1c34c252cc
@ -137,17 +137,13 @@ func (m *windowsApp) run() error {
|
|||||||
|
|
||||||
// Check if there is 1 parameter passed to the application
|
// Check if there is 1 parameter passed to the application
|
||||||
// and if the extension matches the options.FileAssociations string
|
// and if the extension matches the options.FileAssociations string
|
||||||
println("Checking args")
|
|
||||||
if len(os.Args) == 2 {
|
if len(os.Args) == 2 {
|
||||||
arg := os.Args[1]
|
arg := os.Args[1]
|
||||||
ext := filepath.Ext(arg)
|
ext := filepath.Ext(arg)
|
||||||
println("Got extension: ", ext)
|
|
||||||
if slices.Contains(m.parent.options.FileAssociations, ext) {
|
if slices.Contains(m.parent.options.FileAssociations, ext) {
|
||||||
println("Slices contains")
|
|
||||||
eventContext := newApplicationEventContext()
|
eventContext := newApplicationEventContext()
|
||||||
eventContext.setOpenedWithFile(arg)
|
eventContext.setOpenedWithFile(arg)
|
||||||
// EmitEvent application started event
|
// EmitEvent application started event
|
||||||
println("sending event")
|
|
||||||
applicationEvents <- &ApplicationEvent{
|
applicationEvents <- &ApplicationEvent{
|
||||||
Id: uint(events.Common.ApplicationOpenedWithFile),
|
Id: uint(events.Common.ApplicationOpenedWithFile),
|
||||||
ctx: eventContext,
|
ctx: eventContext,
|
||||||
|
@ -256,11 +256,6 @@ type WindowsWindow struct {
|
|||||||
// Default: false
|
// Default: false
|
||||||
WebviewGpuIsDisabled bool
|
WebviewGpuIsDisabled bool
|
||||||
|
|
||||||
// ResizeDebounceMS is the amount of time to debounce redraws of webview2
|
|
||||||
// when resizing the window
|
|
||||||
// Default: 0
|
|
||||||
ResizeDebounceMS uint16
|
|
||||||
|
|
||||||
// Disable the menu bar for this window
|
// Disable the menu bar for this window
|
||||||
// Default: false
|
// Default: false
|
||||||
DisableMenu bool
|
DisableMenu bool
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -57,9 +58,8 @@ type windowsWebviewWindow struct {
|
|||||||
previousWindowPlacement w32.WINDOWPLACEMENT
|
previousWindowPlacement w32.WINDOWPLACEMENT
|
||||||
|
|
||||||
// Webview
|
// Webview
|
||||||
chromium *edge.Chromium
|
chromium *edge.Chromium
|
||||||
hasStarted bool
|
hasStarted bool
|
||||||
resizeDebouncer func(func())
|
|
||||||
|
|
||||||
// resizeBorder* is the width/height of the resize border in pixels.
|
// resizeBorder* is the width/height of the resize border in pixels.
|
||||||
resizeBorderWidth int32
|
resizeBorderWidth int32
|
||||||
@ -366,10 +366,6 @@ func (w *windowsWebviewWindow) run() {
|
|||||||
w.setWindowMask(options.Windows.WindowMask)
|
w.setWindowMask(options.Windows.WindowMask)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Windows.ResizeDebounceMS > 0 {
|
|
||||||
w.resizeDebouncer = debounce.New(time.Duration(options.Windows.ResizeDebounceMS) * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.InitialPosition == WindowCentered {
|
if options.InitialPosition == WindowCentered {
|
||||||
w.center()
|
w.center()
|
||||||
} else {
|
} else {
|
||||||
@ -1006,6 +1002,8 @@ func (w *windowsWebviewWindow) isActive() bool {
|
|||||||
return w32.GetForegroundWindow() == w.hwnd
|
return w32.GetForegroundWindow() == w.hwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resizePending int32
|
||||||
|
|
||||||
func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||||
switch msg {
|
switch msg {
|
||||||
case w32.WM_ACTIVATE:
|
case w32.WM_ACTIVATE:
|
||||||
@ -1064,20 +1062,24 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
|
|||||||
case w32.SIZE_MINIMIZED:
|
case w32.SIZE_MINIMIZED:
|
||||||
w.parent.emit(events.Windows.WindowMinimise)
|
w.parent.emit(events.Windows.WindowMinimise)
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.parent.options.Frameless && wparam == w32.SIZE_MINIMIZED {
|
if w.parent.options.Frameless && wparam == w32.SIZE_MINIMIZED {
|
||||||
// If the window is frameless, and we are minimizing, then we need to suppress the Resize on the
|
// If the window is frameless, and we are minimizing, then we need to suppress the Resize on the
|
||||||
// WebView2. If we don't do this, restoring does not work as expected and first restores with some wrong
|
// WebView2. If we don't do this, restoring does not work as expected and first restores with some wrong
|
||||||
// size during the restore animation and only fully renders when the animation is done. This highly
|
// size during the restore animation and only fully renders when the animation is done. This highly
|
||||||
// depends on the content in the WebView, see https://github.com/wailsapp/wails/issues/1319
|
// depends on the content in the WebView, see https://github.com/wailsapp/wails/issues/1319
|
||||||
} else if w.resizeDebouncer != nil {
|
|
||||||
w.resizeDebouncer(func() {
|
|
||||||
InvokeSync(func() {
|
|
||||||
w.chromium.Resize()
|
|
||||||
})
|
|
||||||
w.parent.emit(events.Windows.WindowDidResize)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
w.chromium.Resize()
|
if atomic.CompareAndSwapInt32(&resizePending, 0, 1) {
|
||||||
|
go func() {
|
||||||
|
// Wait for next vsync-like interval
|
||||||
|
time.Sleep(time.Millisecond) // ~60fps timing
|
||||||
|
InvokeSync(func() {
|
||||||
|
w.chromium.Resize()
|
||||||
|
atomic.StoreInt32(&resizePending, 0)
|
||||||
|
w.parent.emit(events.Windows.WindowDidResize)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -1491,7 +1493,7 @@ func (w *windowsWebviewWindow) setupChromium() {
|
|||||||
//println(windowName)
|
//println(windowName)
|
||||||
//if windowName == "Chrome_RenderWidgetHostHWND" {
|
//if windowName == "Chrome_RenderWidgetHostHWND" {
|
||||||
err := w32.RegisterDragDrop(hwnd, w.dropTarget)
|
err := w32.RegisterDragDrop(hwnd, w.dropTarget)
|
||||||
if err != nil && err != syscall.Errno(w32.DRAGDROP_E_ALREADYREGISTERED) {
|
if err != nil && !errors.Is(err, syscall.Errno(w32.DRAGDROP_E_ALREADYREGISTERED)) {
|
||||||
globalApplication.error("Error registering drag and drop: " + err.Error())
|
globalApplication.error("Error registering drag and drop: " + err.Error())
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
@ -1547,6 +1549,9 @@ func (w *windowsWebviewWindow) setupChromium() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
globalApplication.fatal(err.Error())
|
globalApplication.fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
if settings == nil {
|
||||||
|
globalApplication.fatal("Error getting settings")
|
||||||
|
}
|
||||||
err = settings.PutAreDefaultContextMenusEnabled(debugMode || !w.parent.options.DefaultContextMenuDisabled)
|
err = settings.PutAreDefaultContextMenusEnabled(debugMode || !w.parent.options.DefaultContextMenuDisabled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globalApplication.fatal(err.Error())
|
globalApplication.fatal(err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user