mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-07 20:39:16 +08:00
Application: increase message buffer sizes, process all messages in goroutine, Add IsDebug
to environment info.
This commit is contained in:
parent
7f8c1c8a68
commit
9f567fe2bc
@ -49,22 +49,23 @@ function addWMLEventListeners() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls a method on the window object.
|
* 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 on the window object.
|
* @param {string} method - The name of the method to call.
|
||||||
*
|
|
||||||
* @return {void}
|
|
||||||
*/
|
*/
|
||||||
function callWindowMethod(method) {
|
function callWindowMethod(windowName, method) {
|
||||||
// TODO: Make this a parameter!
|
let targetWindow = Get(windowName);
|
||||||
let windowName = '';
|
|
||||||
let targetWindow = Get('');
|
|
||||||
let methodMap = WindowMethods(targetWindow);
|
let methodMap = WindowMethods(targetWindow);
|
||||||
if (!methodMap.has(method)) {
|
if (!methodMap.has(method)) {
|
||||||
console.log("Window method " + method + " not found");
|
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) {
|
elements.forEach(function (element) {
|
||||||
const windowMethod = element.getAttribute('wml-window');
|
const windowMethod = element.getAttribute('wml-window');
|
||||||
const confirm = element.getAttribute('wml-confirm');
|
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 () {
|
let callback = function () {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
|
Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
|
||||||
if (result !== "No") {
|
if (result !== "No") {
|
||||||
callWindowMethod(windowMethod);
|
callWindowMethod(targetWindow, windowMethod);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callWindowMethod(windowMethod);
|
callWindowMethod(targetWindow, windowMethod);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove existing listeners
|
// Remove existing listeners
|
||||||
|
@ -179,14 +179,14 @@ type windowMessage struct {
|
|||||||
message string
|
message string
|
||||||
}
|
}
|
||||||
|
|
||||||
var windowMessageBuffer = make(chan *windowMessage)
|
var windowMessageBuffer = make(chan *windowMessage, 5)
|
||||||
|
|
||||||
type dragAndDropMessage struct {
|
type dragAndDropMessage struct {
|
||||||
windowId uint
|
windowId uint
|
||||||
filenames []string
|
filenames []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var windowDragAndDropBuffer = make(chan *dragAndDropMessage)
|
var windowDragAndDropBuffer = make(chan *dragAndDropMessage, 5)
|
||||||
|
|
||||||
func addDragAndDropMessage(windowId uint, filenames []string) {
|
func addDragAndDropMessage(windowId uint, filenames []string) {
|
||||||
windowDragAndDropBuffer <- &dragAndDropMessage{
|
windowDragAndDropBuffer <- &dragAndDropMessage{
|
||||||
@ -206,7 +206,7 @@ type webViewAssetRequest struct {
|
|||||||
windowName string
|
windowName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var windowKeyEvents = make(chan *windowKeyEvent)
|
var windowKeyEvents = make(chan *windowKeyEvent, 5)
|
||||||
|
|
||||||
type windowKeyEvent struct {
|
type windowKeyEvent struct {
|
||||||
windowId uint
|
windowId uint
|
||||||
@ -224,7 +224,7 @@ func (r *webViewAssetRequest) Header() (http.Header, error) {
|
|||||||
return hh, nil
|
return hh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var webviewRequests = make(chan *webViewAssetRequest)
|
var webviewRequests = make(chan *webViewAssetRequest, 5)
|
||||||
|
|
||||||
type eventHook struct {
|
type eventHook struct {
|
||||||
callback func(event *Event)
|
callback func(event *Event)
|
||||||
@ -435,44 +435,44 @@ func (a *App) Run() error {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
event := <-applicationEvents
|
event := <-applicationEvents
|
||||||
a.handleApplicationEvent(event)
|
go a.handleApplicationEvent(event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
event := <-windowEvents
|
event := <-windowEvents
|
||||||
a.handleWindowEvent(event)
|
go a.handleWindowEvent(event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
request := <-webviewRequests
|
request := <-webviewRequests
|
||||||
a.handleWebViewRequest(request)
|
go a.handleWebViewRequest(request)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
event := <-windowMessageBuffer
|
event := <-windowMessageBuffer
|
||||||
a.handleWindowMessage(event)
|
go a.handleWindowMessage(event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
event := <-windowKeyEvents
|
event := <-windowKeyEvents
|
||||||
a.handleWindowKeyEvent(event)
|
go a.handleWindowKeyEvent(event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
dragAndDropMessage := <-windowDragAndDropBuffer
|
dragAndDropMessage := <-windowDragAndDropBuffer
|
||||||
a.handleDragAndDropMessage(dragAndDropMessage)
|
go a.handleDragAndDropMessage(dragAndDropMessage)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
menuItemID := <-menuItemClicked
|
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 {
|
func (a *App) Environment() EnvironmentInfo {
|
||||||
return EnvironmentInfo{
|
return EnvironmentInfo{
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
|
Debug: a.isDebugMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
package application
|
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 {
|
type EnvironmentInfo struct {
|
||||||
OS string
|
OS string
|
||||||
Arch string
|
Arch string
|
||||||
|
Debug bool
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,16 @@ func (w *Event) Cancel() {
|
|||||||
w.Cancelled = true
|
w.Cancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var applicationEvents = make(chan *Event)
|
var applicationEvents = make(chan *Event, 5)
|
||||||
|
|
||||||
type windowEvent struct {
|
type windowEvent struct {
|
||||||
WindowID uint
|
WindowID uint
|
||||||
EventID 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 {
|
type WailsEvent struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -65,41 +65,12 @@ func (m *MessageProcessor) getTargetWindow(r *http.Request) (Window, string) {
|
|||||||
|
|
||||||
func (m *MessageProcessor) HandleRuntimeCall(rw http.ResponseWriter, r *http.Request) {
|
func (m *MessageProcessor) HandleRuntimeCall(rw http.ResponseWriter, r *http.Request) {
|
||||||
object := r.URL.Query().Get("object")
|
object := r.URL.Query().Get("object")
|
||||||
if object != "" {
|
if object == "" {
|
||||||
m.HandleRuntimeCallWithIDs(rw, r)
|
m.httpError(rw, "Invalid runtime call")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Read "method" from query string
|
m.HandleRuntimeCallWithIDs(rw, r)
|
||||||
//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)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MessageProcessor) HandleRuntimeCallWithIDs(rw http.ResponseWriter, r *http.Request) {
|
func (m *MessageProcessor) HandleRuntimeCallWithIDs(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -35,6 +35,6 @@ func (m *MessageProcessor) processContextMenuMethod(method int, rw http.Response
|
|||||||
m.httpError(rw, "Unknown contextmenu method: %d", method)
|
m.httpError(rw, "Unknown contextmenu method: %d", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Info("Runtime:", "method", "ContextMenu."+contextmenuMethodNames[method])
|
m.Info("Runtime Call:", "method", "ContextMenu."+contextmenuMethodNames[method])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
|
|||||||
dialog.AddButtons(options.Buttons)
|
dialog.AddButtons(options.Buttons)
|
||||||
dialog.Show()
|
dialog.Show()
|
||||||
m.ok(rw)
|
m.ok(rw)
|
||||||
m.Info("Runtime:", "method", methodName, "options", options)
|
m.Info("Runtime Call:", "method", methodName, "options", options)
|
||||||
|
|
||||||
case DialogOpenFile:
|
case DialogOpenFile:
|
||||||
var options OpenFileDialogOptions
|
var options OpenFileDialogOptions
|
||||||
@ -119,7 +119,7 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.dialogCallback(window, dialogID, string(result), true)
|
m.dialogCallback(window, dialogID, string(result), true)
|
||||||
m.Info("Runtime:", "method", methodName, "result", result)
|
m.Info("Runtime Call:", "method", methodName, "result", result)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file, err := dialog.PromptForSingleSelection()
|
file, err := dialog.PromptForSingleSelection()
|
||||||
@ -128,11 +128,11 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.dialogCallback(window, dialogID, file, false)
|
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.ok(rw)
|
||||||
m.Info("Runtime:", "method", methodName, "options", options)
|
m.Info("Runtime Call:", "method", methodName, "options", options)
|
||||||
|
|
||||||
case DialogSaveFile:
|
case DialogSaveFile:
|
||||||
var options SaveFileDialogOptions
|
var options SaveFileDialogOptions
|
||||||
@ -154,10 +154,10 @@ func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWrite
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.dialogCallback(window, dialogID, file, false)
|
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.ok(rw)
|
||||||
m.Info("Runtime:", "method", methodName, "options", options)
|
m.Info("Runtime Call:", "method", methodName, "options", options)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
m.httpError(rw, "Unknown dialog method: %d", method)
|
m.httpError(rw, "Unknown dialog method: %d", method)
|
||||||
|
@ -35,6 +35,6 @@ func (m *MessageProcessor) processEventsMethod(method int, rw http.ResponseWrite
|
|||||||
return
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,6 @@ func (m *MessageProcessor) processScreensMethod(method int, rw http.ResponseWrit
|
|||||||
m.httpError(rw, "Unknown screens method: %d", method)
|
m.httpError(rw, "Unknown screens method: %d", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Info("Runtime:", "method", "Screens."+screensMethodNames[method])
|
m.Info("Runtime Call:", "method", "Screens."+screensMethodNames[method])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ const (
|
|||||||
|
|
||||||
var systemMethodNames = map[int]string{
|
var systemMethodNames = map[int]string{
|
||||||
SystemIsDarkMode: "IsDarkMode",
|
SystemIsDarkMode: "IsDarkMode",
|
||||||
|
Environment: "Environment",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MessageProcessor) processSystemMethod(method int, rw http.ResponseWriter, r *http.Request, window Window, params QueryParams) {
|
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.httpError(rw, "Unknown system method: %d", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Info("Runtime:", "method", "System."+systemMethodNames[method])
|
m.Info("Runtime Call:", "method", "System."+systemMethodNames[method])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -255,5 +255,5 @@ func (m *MessageProcessor) processWindowMethod(method int, rw http.ResponseWrite
|
|||||||
m.httpError(rw, "Unknown window method id: %d", method)
|
m.httpError(rw, "Unknown window method id: %d", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Info("Runtime:", "method", "Window."+windowMethodNames[method])
|
m.Info("Runtime Call:", "method", "Window."+windowMethodNames[method])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user