Potential solution for getting the calling window of a bound method.

This commit is contained in:
Lea Anthony
2024-05-05 18:34:46 +10:00
parent d3d54e0620
commit bf9c1f08bc
+3 -6
View File
@@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
)
const (
@@ -80,6 +79,7 @@ func (m *MessageProcessor) processCallMethod(method int, rw http.ResponseWriter,
}
ctx, cancel := context.WithCancel(context.WithoutCancel(r.Context()))
ctx = context.WithValue(ctx, "window", window)
ambiguousID := false
m.l.Lock()
@@ -105,12 +105,9 @@ func (m *MessageProcessor) processCallMethod(method int, rw http.ResponseWriter,
m.l.Unlock()
}()
// Check if the first or second bound method parameter is a Window interface
// Check if the first bound method parameter is a Window interface
if len(boundMethod.Inputs) > 0 {
if boundMethod.Inputs[0].ReflectType == reflect.TypeFor[Window]() {
// Prepend the options.Args with the current window
options.Args = append([]interface{}{window}, options.Args...)
} else if len(boundMethod.Inputs) > 1 && boundMethod.Inputs[1].ReflectType == reflect.TypeFor[Window]() {
if boundMethod.Inputs[0].ReflectType.String() == "application.Window" {
// Prepend the options.Args with the current window
options.Args = append([]interface{}{window}, options.Args...)
}