mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Support window as second parameter
This commit is contained in:
@@ -19,3 +19,8 @@ func (*GreetService) GreetWithCtx(ctx context.Context, name string) string {
|
||||
win := ctx.Value("window").(application.Window)
|
||||
return "[ctx] Hello " + name + " on " + win.Name()
|
||||
}
|
||||
|
||||
// GreetWithCtx greets a person
|
||||
func (*GreetService) GreetWithBoth(_ context.Context, win application.Window, name string) string {
|
||||
return "[ctx+win] Hello " + name + " on " + win.Name()
|
||||
}
|
||||
|
||||
@@ -26,3 +26,13 @@ export async function Greet(name) {
|
||||
export async function GreetWithCtx(name) {
|
||||
return Call.ByName("main.GreetService.GreetWithCtx", ...Array.prototype.slice.call(arguments, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* GreetPerson greets a person
|
||||
* @function GreetWithBoth
|
||||
* @param name {string}
|
||||
* @returns {Promise<string>}
|
||||
**/
|
||||
export async function GreetWithBoth(name) {
|
||||
return Call.ByName("main.GreetService.GreetWithBoth", ...Array.prototype.slice.call(arguments, 0));
|
||||
}
|
||||
|
||||
@@ -83,17 +83,19 @@
|
||||
<script type="module">
|
||||
import * as GreetService from "./bindings/main/GreetService.js";
|
||||
|
||||
let useCtx = false;
|
||||
let state = 0;
|
||||
async function greet() {
|
||||
if( useCtx ) {
|
||||
document.getElementById("result").innerHTML =
|
||||
await GreetService.GreetWithCtx(document.getElementById("name").value);
|
||||
useCtx = false;
|
||||
} else {
|
||||
if(state % 3 === 0) {
|
||||
document.getElementById("result").innerHTML =
|
||||
await GreetService.Greet(document.getElementById("name").value);
|
||||
useCtx = true;
|
||||
} else if(state % 3 === 1) {
|
||||
document.getElementById("result").innerHTML =
|
||||
await GreetService.GreetWithCtx(document.getElementById("name").value);
|
||||
} else {
|
||||
document.getElementById("result").innerHTML =
|
||||
await GreetService.GreetWithBoth(document.getElementById("name").value);
|
||||
}
|
||||
state++;
|
||||
}
|
||||
|
||||
document.getElementById("greet-btn").onclick = greet;
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -105,12 +106,11 @@ func (m *MessageProcessor) processCallMethod(method int, rw http.ResponseWriter,
|
||||
m.l.Unlock()
|
||||
}()
|
||||
|
||||
// Check if the first bound method parameter is a Window interface
|
||||
if len(boundMethod.Inputs) > 0 {
|
||||
if boundMethod.Inputs[0].ReflectType.String() == "application.Window" {
|
||||
// Prepend the options.Args with the current window
|
||||
options.Args = append([]interface{}{window}, options.Args...)
|
||||
}
|
||||
// Check if the first or second bound method parameter is a Window interface
|
||||
if len(boundMethod.Inputs) > 1 && (boundMethod.Inputs[0].ReflectType == reflect.TypeFor[Window]() ||
|
||||
boundMethod.Inputs[1].ReflectType == reflect.TypeFor[Window]()) {
|
||||
// Prepend the options.Args with the current window
|
||||
options.Args = append([]interface{}{window}, options.Args...)
|
||||
}
|
||||
result, err := boundMethod.Call(ctx, options.Args)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user