diff --git a/v3/examples/binding/GreetService.go b/v3/examples/binding/GreetService.go index 5913c3e5..121004b6 100644 --- a/v3/examples/binding/GreetService.go +++ b/v3/examples/binding/GreetService.go @@ -1,17 +1,26 @@ package main -import "github.com/wailsapp/wails/v3/examples/binding/data" +import ( + "context" + "github.com/wailsapp/wails/v3/pkg/application" +) // GreetService is a service that greets people type GreetService struct { } // Greet greets a person -func (*GreetService) Greet(name string) string { - return "Hello " + name +func (*GreetService) Greet(win application.Window, name string) string { + return "Hello " + name + " on " + win.Name() } -// GreetPerson greets a person -func (*GreetService) GreetPerson(person data.Person) string { - return "Hello " + person.Name +// GreetWithCtx greets a person +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() } diff --git a/v3/examples/binding/assets/bindings/data/models.js b/v3/examples/binding/assets/bindings/data/models.js deleted file mode 100644 index 0820a394..00000000 --- a/v3/examples/binding/assets/bindings/data/models.js +++ /dev/null @@ -1,28 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// Person holds someone's most important attributes -export const Person = class { - /** - * Creates a new Person instance. - * @constructor - * @param {Object} source - The source object to create the Person. - * @param {string} source.Name - */ - constructor(source = {}) { - const { name = "" } = source; - this.name = name; - } - - /** - * Creates a new Person instance from a string or object. - * @param {string|object} source - The source data to create a Person instance from. - * @returns {Person} A new Person instance. - */ - static createFrom(source) { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource); - } -}; - diff --git a/v3/examples/binding/assets/bindings/main/GreetService.js b/v3/examples/binding/assets/bindings/main/GreetService.js index 468aca7c..80f826c7 100644 --- a/v3/examples/binding/assets/bindings/main/GreetService.js +++ b/v3/examples/binding/assets/bindings/main/GreetService.js @@ -19,10 +19,20 @@ export async function Greet(name) { /** * GreetPerson greets a person - * @function GreetPerson - * @param person {dataPerson} + * @function GreetWithCtx + * @param name {string} * @returns {Promise} **/ -export async function GreetPerson(person) { - return Call.ByName("main.GreetService.GreetPerson", ...Array.prototype.slice.call(arguments, 0)); +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} + **/ +export async function GreetWithBoth(name) { + return Call.ByName("main.GreetService.GreetWithBoth", ...Array.prototype.slice.call(arguments, 0)); } diff --git a/v3/examples/binding/assets/index.html b/v3/examples/binding/assets/index.html index 53699e37..34eacc36 100644 --- a/v3/examples/binding/assets/index.html +++ b/v3/examples/binding/assets/index.html @@ -83,9 +83,19 @@