5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 09:09:28 +08:00

Application: increase message buffer sizes, process all messages in goroutine, Add IsDebug to environment info.

This commit is contained in:
Lea Anthony 2023-12-29 12:48:26 +11:00
parent 7f8c1c8a68
commit 9f567fe2bc
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
11 changed files with 56 additions and 74 deletions

View File

@ -49,22 +49,23 @@ function addWMLEventListeners() {
});
}
/**
* Calls a method on the window object.
*
* @param {string} method - The name of the method to call on the window object.
*
* @return {void}
* Calls a method on a specified window.
* @param {string} windowName - The name of the window to call the method on.
* @param {string} method - The name of the method to call.
*/
function callWindowMethod(method) {
// TODO: Make this a parameter!
let windowName = '';
let targetWindow = Get('');
function callWindowMethod(windowName, method) {
let targetWindow = Get(windowName);
let methodMap = WindowMethods(targetWindow);
if (!methodMap.has(method)) {
console.log("Window method " + method + " not found");
}
methodMap.get(method)();
try {
methodMap.get(method)();
} catch (e) {
console.error("Error calling window method '" + method + "': " + e);
}
}
/**
@ -78,18 +79,19 @@ function addWMLWindowListeners() {
elements.forEach(function (element) {
const windowMethod = element.getAttribute('wml-window');
const confirm = element.getAttribute('wml-confirm');
const trigger = element.getAttribute('wml-trigger') || "click";
const trigger = element.getAttribute('wml-trigger') || 'click';
const targetWindow = element.getAttribute('wml-target-window') || '';
let callback = function () {
if (confirm) {
Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
if (result !== "No") {
callWindowMethod(windowMethod);
callWindowMethod(targetWindow, windowMethod);
}
});
return;
}
callWindowMethod(windowMethod);
callWindowMethod(targetWindow, windowMethod);
};
// Remove existing listeners

View File

@ -179,14 +179,14 @@ type windowMessage struct {
message string
}
var windowMessageBuffer = make(chan *windowMessage)
var windowMessageBuffer = make(chan *windowMessage, 5)
type dragAndDropMessage struct {
windowId uint
filenames []string
}
var windowDragAndDropBuffer = make(chan *dragAndDropMessage)
var windowDragAndDropBuffer = make(chan *dragAndDropMessage, 5)
func addDragAndDropMessage(windowId uint, filenames []string) {
windowDragAndDropBuffer <- &dragAndDropMessage{
@ -206,7 +206,7 @@ type webViewAssetRequest struct {
windowName string
}
var windowKeyEvents = make(chan *windowKeyEvent)
var windowKeyEvents = make(chan *windowKeyEvent, 5)
type windowKeyEvent struct {
windowId uint
@ -224,7 +224,7 @@ func (r *webViewAssetRequest) Header() (http.Header, error) {
return hh, nil
}
var webviewRequests = make(chan *webViewAssetRequest)
var webviewRequests = make(chan *webViewAssetRequest, 5)
type eventHook struct {
callback func(event *Event)
@ -435,44 +435,44 @@ func (a *App) Run() error {
go func() {
for {
event := <-applicationEvents
a.handleApplicationEvent(event)
go a.handleApplicationEvent(event)
}
}()
go func() {
for {
event := <-windowEvents
a.handleWindowEvent(event)
go a.handleWindowEvent(event)
}
}()
go func() {
for {
request := <-webviewRequests
a.handleWebViewRequest(request)
go a.handleWebViewRequest(request)
}
}()
go func() {
for {
event := <-windowMessageBuffer
a.handleWindowMessage(event)
go a.handleWindowMessage(event)
}
}()
go func() {
for {
event := <-windowKeyEvents
a.handleWindowKeyEvent(event)
go a.handleWindowKeyEvent(event)
}
}()
go func() {
for {
dragAndDropMessage := <-windowDragAndDropBuffer
a.handleDragAndDropMessage(dragAndDropMessage)
go a.handleDragAndDropMessage(dragAndDropMessage)
}
}()
go func() {
for {
menuItemID := <-menuItemClicked
a.handleMenuItemClicked(menuItemID)
go a.handleMenuItemClicked(menuItemID)
}
}()
@ -828,7 +828,8 @@ func (a *App) BrowserOpenFile(path string) error {
func (a *App) Environment() EnvironmentInfo {
return EnvironmentInfo{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
Debug: a.isDebugMode,
}
}

View File

@ -1,6 +1,13 @@
package application
// EnvironmentInfo represents information about the current environment.
//
// Fields:
// - OS: the operating system that the program is running on.
// - Arch: the architecture of the operating system.
// - Debug: indicates whether debug mode is enabled.
type EnvironmentInfo struct {
OS string
Arch string
OS string
Arch string
Debug bool
}

View File

@ -29,16 +29,16 @@ func (w *Event) Cancel() {
w.Cancelled = true
}
var applicationEvents = make(chan *Event)
var applicationEvents = make(chan *Event, 5)
type windowEvent struct {
WindowID uint
EventID uint
}
var windowEvents = make(chan *windowEvent)
var windowEvents = make(chan *windowEvent, 5)
var menuItemClicked = make(chan uint)
var menuItemClicked = make(chan uint, 5)
type WailsEvent struct {
Name string `json:"name"`

View File

@ -65,41 +65,12 @@ func (m *MessageProcessor) getTargetWindow(r *http.Request) (Window, string) {
func (m *MessageProcessor) HandleRuntimeCall(rw http.ResponseWriter, r *http.Request) {
object := r.URL.Query().Get("object")
if object != "" {
m.HandleRuntimeCallWithIDs(rw, r)
if object == "" {
m.httpError(rw, "Invalid runtime call")
return
}
//// Read "method" from query string
//method := r.URL.Query().Get("method")
//if method == "" {
// m.httpError(rw, "No method specified")
// return
//}
//splitMethod := strings.Split(method, ".")
//if len(splitMethod) != 2 {
// m.httpError(rw, "Invalid method format")
// return
//}
//// Get the object
//object = splitMethod[0]
//// Get the method
//method = splitMethod[1]
//
//params := QueryParams(r.URL.Query())
//
//targetWindow := m.getTargetWindow(r)
//if targetWindow == nil {
// m.httpError(rw, "No valid window found")
// return
//}
//
//switch object {
//case "call":
// m.processCallMethod(method, rw, r, targetWindow, params)
//default:
// m.httpError(rw, "Unknown runtime call: %s", object)
//}
m.HandleRuntimeCallWithIDs(rw, r)
}
func (m *MessageProcessor) HandleRuntimeCallWithIDs(rw http.ResponseWriter, r *http.Request) {

View File

@ -35,6 +35,6 @@ func (m *MessageProcessor) processContextMenuMethod(method int, rw http.Response
m.httpError(rw, "Unknown contextmenu method: %d", method)
}
m.Info("Runtime:", "method", "ContextMenu."+contextmenuMethodNames[method])
m.Info("Runtime Call:", "method", "ContextMenu."+contextmenuMethodNames[method])
}

View File

@ -91,7 +91,7 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
dialog.AddButtons(options.Buttons)
dialog.Show()
m.ok(rw)
m.Info("Runtime:", "method", methodName, "options", options)
m.Info("Runtime Call:", "method", methodName, "options", options)
case DialogOpenFile:
var options OpenFileDialogOptions
@ -119,7 +119,7 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
return
}
m.dialogCallback(window, dialogID, string(result), true)
m.Info("Runtime:", "method", methodName, "result", result)
m.Info("Runtime Call:", "method", methodName, "result", result)
}
} else {
file, err := dialog.PromptForSingleSelection()
@ -128,11 +128,11 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
return
}
m.dialogCallback(window, dialogID, file, false)
m.Info("Runtime:", "method", methodName, "result", file)
m.Info("Runtime Call:", "method", methodName, "result", file)
}
}()
m.ok(rw)
m.Info("Runtime:", "method", methodName, "options", options)
m.Info("Runtime Call:", "method", methodName, "options", options)
case DialogSaveFile:
var options SaveFileDialogOptions
@ -154,10 +154,10 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
return
}
m.dialogCallback(window, dialogID, file, false)
m.Info("Runtime:", "method", methodName, "result", file)
m.Info("Runtime Call:", "method", methodName, "result", file)
}()
m.ok(rw)
m.Info("Runtime:", "method", methodName, "options", options)
m.Info("Runtime Call:", "method", methodName, "options", options)
default:
m.httpError(rw, "Unknown dialog method: %d", method)

View File

@ -35,6 +35,6 @@ func (m *MessageProcessor) processEventsMethod(method int, rw http.ResponseWrite
return
}
m.Info("Runtime:", "method", "Events."+eventsMethodNames[method], "name", event.Name, "sender", event.Sender, "data", event.Data, "cancelled", event.Cancelled)
m.Info("Runtime Call:", "method", "Events."+eventsMethodNames[method], "name", event.Name, "sender", event.Sender, "data", event.Data, "cancelled", event.Cancelled)
}

View File

@ -44,6 +44,6 @@ func (m *MessageProcessor) processScreensMethod(method int, rw http.ResponseWrit
m.httpError(rw, "Unknown screens method: %d", method)
}
m.Info("Runtime:", "method", "Screens."+screensMethodNames[method])
m.Info("Runtime Call:", "method", "Screens."+screensMethodNames[method])
}

View File

@ -11,6 +11,7 @@ const (
var systemMethodNames = map[int]string{
SystemIsDarkMode: "IsDarkMode",
Environment: "Environment",
}
func (m *MessageProcessor) processSystemMethod(method int, rw http.ResponseWriter, r *http.Request, window Window, params QueryParams) {
@ -24,6 +25,6 @@ func (m *MessageProcessor) processSystemMethod(method int, rw http.ResponseWrite
m.httpError(rw, "Unknown system method: %d", method)
}
m.Info("Runtime:", "method", "System."+systemMethodNames[method])
m.Info("Runtime Call:", "method", "System."+systemMethodNames[method])
}

View File

@ -255,5 +255,5 @@ func (m *MessageProcessor) processWindowMethod(method int, rw http.ResponseWrite
m.httpError(rw, "Unknown window method id: %d", method)
}
m.Info("Runtime:", "method", "Window."+windowMethodNames[method])
m.Info("Runtime Call:", "method", "Window."+windowMethodNames[method])
}