[v3] Add CallByID method to runtime.

This commit is contained in:
Lea Anthony
2023-08-27 16:59:18 +10:00
parent cdf48e0589
commit 21790dc3ee
20 changed files with 423 additions and 533 deletions
+8 -10
View File
@@ -7,6 +7,10 @@ import (
"strconv"
)
const (
CallBinding = 0
)
func (m *MessageProcessor) callErrorCallback(window *WebviewWindow, message string, callID *string, err error) {
errorMsg := fmt.Sprintf(message, err)
m.Error(errorMsg)
@@ -19,7 +23,7 @@ func (m *MessageProcessor) callCallback(window *WebviewWindow, callID *string, r
window.ExecJS(msg)
}
func (m *MessageProcessor) processCallMethod(method string, rw http.ResponseWriter, r *http.Request, window *WebviewWindow, params QueryParams) {
func (m *MessageProcessor) processCallMethod(method int, rw http.ResponseWriter, r *http.Request, window *WebviewWindow, params QueryParams) {
args, err := params.Args()
if err != nil {
m.httpError(rw, "Unable to parse arguments: %s", err)
@@ -31,7 +35,7 @@ func (m *MessageProcessor) processCallMethod(method string, rw http.ResponseWrit
return
}
switch method {
case "Call":
case CallBinding:
var options CallOptions
err := params.ToStruct(&options)
if err != nil {
@@ -39,20 +43,14 @@ func (m *MessageProcessor) processCallMethod(method string, rw http.ResponseWrit
return
}
var boundMethod *BoundMethod
methodID := r.Header.Get("x-wails-method-id")
if methodID == "" {
if options.PackageName != "" {
boundMethod = globalApplication.bindings.Get(&options)
if boundMethod == nil {
m.callErrorCallback(window, "Error getting binding for method: %s", callID, fmt.Errorf("method '%s' not found", options.Name()))
return
}
} else {
id, err := strconv.ParseUint(methodID, 10, 32)
if err != nil {
m.callErrorCallback(window, "Error parsing method id for call: %s", callID, err)
return
}
boundMethod = globalApplication.bindings.GetByID(uint32(id))
boundMethod = globalApplication.bindings.GetByID(options.MethodID)
}
if boundMethod == nil {
m.callErrorCallback(window, "Error getting binding for method: %s", callID, fmt.Errorf("method ID '%s' not found", options.Name()))