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;
|
||||
|
||||
Reference in New Issue
Block a user