Support window as second parameter

This commit is contained in:
Lea Anthony
2024-04-27 14:29:48 +10:00
parent c76b88b7b2
commit 8ea58bef2c
4 changed files with 30 additions and 13 deletions
+5
View File
@@ -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));
}
+9 -7
View File
@@ -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;