mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 01:10:29 +08:00
Merge pull request #970 from stffabi/feature/use-winc-invoke
[v2] Use invoke to dispatch callbacks on windows
This commit is contained in:
commit
deb1156916
@ -28,7 +28,7 @@ require (
|
||||
github.com/leaanthony/slicer v1.5.0
|
||||
github.com/leaanthony/typescriptify-golang-structs v0.1.7
|
||||
github.com/leaanthony/webview2runtime v1.1.0
|
||||
github.com/leaanthony/winc v0.0.0-20210921073452-54963136bf18
|
||||
github.com/leaanthony/winc v0.0.0-20211124105230-0330cfc6d50c
|
||||
github.com/leaanthony/winicon v1.0.0
|
||||
github.com/matryer/is v1.4.0
|
||||
github.com/olekukonko/tablewriter v0.0.4
|
||||
|
@ -134,6 +134,8 @@ github.com/leaanthony/webview2runtime v1.1.0 h1:N0pv55ift8XtqozIp4PNOtRCJ/Qdd/qz
|
||||
github.com/leaanthony/webview2runtime v1.1.0/go.mod h1:hH9GnWCve3DYzNaPOcPbhHQ7fodXR1QJNsnwixid4Tk=
|
||||
github.com/leaanthony/winc v0.0.0-20210921073452-54963136bf18 h1:5iOd93PZbpH4Iir8QkC4coFD+zEQEZSIRcjwjTFZkr0=
|
||||
github.com/leaanthony/winc v0.0.0-20210921073452-54963136bf18/go.mod h1:KEbMsKoznsebyGHwLk5LqkFOxL5uXSRdvpP4+avmAMs=
|
||||
github.com/leaanthony/winc v0.0.0-20211124105230-0330cfc6d50c h1:TiVq07fzkq0QHJNC2WAb3efpM1R0gPcVgdxcvIu7K84=
|
||||
github.com/leaanthony/winc v0.0.0-20211124105230-0330cfc6d50c/go.mod h1:KEbMsKoznsebyGHwLk5LqkFOxL5uXSRdvpP4+avmAMs=
|
||||
github.com/leaanthony/winicon v1.0.0 h1:ZNt5U5dY71oEoKZ97UVwJRT4e+5xo5o/ieKuHuk8NqQ=
|
||||
github.com/leaanthony/winicon v1.0.0/go.mod h1:en5xhijl92aphrJdmRPlh4NI1L6wq3gEm0LpXAPghjU=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
|
@ -7,15 +7,12 @@ import (
|
||||
"github.com/leaanthony/winc/w32"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Window struct {
|
||||
winc.Form
|
||||
frontendOptions *options.App
|
||||
applicationMenu *menu.Menu
|
||||
m sync.Mutex
|
||||
dispatchq []func()
|
||||
}
|
||||
|
||||
func NewWindow(parent winc.Controller, appoptions *options.App) *Window {
|
||||
@ -86,32 +83,9 @@ func NewWindow(parent winc.Controller, appoptions *options.App) *Window {
|
||||
}
|
||||
|
||||
func (w *Window) Run() int {
|
||||
var m w32.MSG
|
||||
|
||||
for w32.GetMessage(&m, 0, 0, 0) != 0 {
|
||||
if m.Message == w32.WM_APP {
|
||||
// Credit: https://github.com/jchv/go-webview2
|
||||
w.m.Lock()
|
||||
q := append([]func(){}, w.dispatchq...)
|
||||
w.dispatchq = []func(){}
|
||||
w.m.Unlock()
|
||||
for _, v := range q {
|
||||
v()
|
||||
}
|
||||
}
|
||||
if !w.PreTranslateMessage(&m) {
|
||||
w32.TranslateMessage(&m)
|
||||
w32.DispatchMessage(&m)
|
||||
}
|
||||
}
|
||||
|
||||
w32.GdiplusShutdown()
|
||||
return int(m.WParam)
|
||||
return winc.RunMainLoop()
|
||||
}
|
||||
|
||||
func (w *Window) Dispatch(f func()) {
|
||||
w.m.Lock()
|
||||
w.dispatchq = append(w.dispatchq, f)
|
||||
w.m.Unlock()
|
||||
w32.PostMainThreadMessage(w32.WM_APP, 0, 0)
|
||||
w.Invoke(f)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user