mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 17:10:49 +08:00
[v2] Do not block during processing of messages
On windows blocking here results in a blocked main thread and a blocked webview.
This commit is contained in:
parent
ec1a535acb
commit
155f1fde49
@ -239,6 +239,7 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
go func() {
|
||||||
result, err := f.dispatcher.ProcessMessage(message, f)
|
result, err := f.dispatcher.ProcessMessage(message, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.logger.Error(err.Error())
|
f.logger.Error(err.Error())
|
||||||
@ -256,6 +257,8 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
default:
|
default:
|
||||||
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) Callback(message string) {
|
func (f *Frontend) Callback(message string) {
|
||||||
|
@ -24,11 +24,6 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/wailsapp/wails/v2/internal/binding"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/frontend/assetserver"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/logger"
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -36,6 +31,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/wailsapp/wails/v2/internal/binding"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/frontend/assetserver"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/logger"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Frontend struct {
|
type Frontend struct {
|
||||||
@ -235,6 +236,8 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
//}
|
//}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
result, err := f.dispatcher.ProcessMessage(message, f)
|
result, err := f.dispatcher.ProcessMessage(message, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.logger.Error(err.Error())
|
f.logger.Error(err.Error())
|
||||||
@ -252,6 +255,7 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
default:
|
default:
|
||||||
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) Callback(message string) {
|
func (f *Frontend) Callback(message string) {
|
||||||
|
@ -259,7 +259,9 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) Quit() {
|
func (f *Frontend) Quit() {
|
||||||
winc.Exit()
|
// Exit must be called on the Main-Thread. It calls PostQuitMessage which sends the WM_QUIT message to the thread's
|
||||||
|
// message queue and our message queue runs on the Main-Thread.
|
||||||
|
f.mainWindow.Invoke(winc.Exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) setupChromium() {
|
func (f *Frontend) setupChromium() {
|
||||||
@ -398,6 +400,8 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
result, err := f.dispatcher.ProcessMessage(message, f)
|
result, err := f.dispatcher.ProcessMessage(message, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.logger.Error(err.Error())
|
f.logger.Error(err.Error())
|
||||||
@ -415,6 +419,7 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
default:
|
default:
|
||||||
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
f.logger.Info("Unknown message returned from dispatcher: %+v", result)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) Callback(message string) {
|
func (f *Frontend) Callback(message string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user