mirror of
https://github.com/wavetermdev/wails.git
synced 2026-04-22 15:26:15 -07:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f89fdea4b | |||
| 2c29e1ca76 | |||
| 5a57ee99ac | |||
| 735b6b6c87 | |||
| 7ea0601fc6 | |||
| 99537f2816 | |||
| b384bb885b | |||
| 2255af1c45 | |||
| f55b781d86 | |||
| 38d9a9551f | |||
| c38cee0a4a | |||
| 0f9c7b1bbf | |||
| 32ddbd8e05 | |||
| 67c493f1a8 | |||
| 69c513e33d | |||
| 82b910dd6d | |||
| 5d0a58cc6a | |||
| 368ca13314 | |||
| 2cee1edcb5 | |||
| 1b288a0a1a | |||
| 81aba310d0 | |||
| b050a07362 | |||
| 021efab84d | |||
| 0a42a050bd | |||
| 9ca1b30da1 | |||
| 220d5535f7 | |||
| 0895e6a508 | |||
| ed5532a535 | |||
| 6f41dbf954 | |||
| c7ed7e72d4 | |||
| a7208f5262 | |||
| 09f6680aa9 | |||
| 9261130fed | |||
| fec22e0052 | |||
| 7c921d6a81 | |||
| 16a029754f | |||
| 3c9fd67fd0 | |||
| 724ca386e7 | |||
| 6f75b00463 | |||
| 105d9f0d3a | |||
| 38f6b1297d | |||
| cf130a6e25 | |||
| e91c30fad0 | |||
| 3e3f7b9273 | |||
| 88ff84f5a5 | |||
| eee373f15a | |||
| c839c053cb |
@@ -71,14 +71,28 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Run tests (mac)
|
||||
if: matrix.os == 'macos-latest'
|
||||
- name: Run tests (mac) | v2
|
||||
if: ${{ matrix.os == 'macos-latest' && github.event.pull_request.base.ref == 'master' }}
|
||||
env:
|
||||
CGO_LDFLAGS: -framework UniformTypeIdentifiers -mmacosx-version-min=10.13
|
||||
CGO_CFLAGS: -mmacosx-version-min=10.13
|
||||
working-directory: ./v2
|
||||
run: go test -v ./...
|
||||
|
||||
- name: Run tests (!mac)
|
||||
if: matrix.os != 'macos-latest'
|
||||
working-directory: ./v2
|
||||
- name: Run tests (!mac) | v2
|
||||
if: ${{ matrix.os != 'macos-latest' && github.event.pull_request.base.ref == 'master' }}
|
||||
working-directory: ./v2
|
||||
run: go test -v ./...
|
||||
|
||||
- name: Run tests (mac) | v3
|
||||
if: ${{ matrix.os == 'macos-latest' && github.event.pull_request.base.ref == 'v3-alpha' }}
|
||||
env:
|
||||
CGO_LDFLAGS: -framework UniformTypeIdentifiers -mmacosx-version-min=10.13
|
||||
CGO_CFLAGS: -mmacosx-version-min=10.13
|
||||
working-directory: ./v3
|
||||
run: go test -v ./...
|
||||
|
||||
- name: Run tests (!mac) | v3
|
||||
if: ${{ matrix.os != 'macos-latest' && github.event.pull_request.base.ref == 'v3-alpha' }}
|
||||
working-directory: ./v3
|
||||
run: go test -v ./...
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
on:
|
||||
push:
|
||||
branches: ['v3-alpha']
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "20"
|
||||
- run: npm ci
|
||||
working-directory: v3/internal/runtime/desktop/@wailsio/runtime
|
||||
|
||||
- uses: JS-DevTools/npm-publish@v3
|
||||
with:
|
||||
package: v3/internal/runtime/desktop/@wailsio/runtime
|
||||
access: public
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM squidfunk/mkdocs-material
|
||||
RUN pip install mkdocs-macros-plugin
|
||||
RUN pip install mkdocs-glightbox
|
||||
RUN pip install mkdocs-table-reader-plugin
|
||||
RUN pip install mkdocs-static-i18n
|
||||
+26
-23
@@ -5,36 +5,39 @@ This is the documentation for Wails v3. It is currently a work in progress.
|
||||
If you do not wish to build it locally, it is available online at
|
||||
[https://wailsapp.github.io/wails/](https://wailsapp.github.io/wails/).
|
||||
|
||||
## Setup Steps
|
||||
## Recommended Setup Steps
|
||||
|
||||
1. Install the wails3 CLI if you haven't already:
|
||||
Install the wails3 CLI if you haven't already:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/wailsapp/wails.git
|
||||
cd wails
|
||||
git checkout v3-alpha
|
||||
cd v3/cmd/wails3
|
||||
go install
|
||||
```
|
||||
2. Install [docker](https://www.docker.com)
|
||||
3. Run the following command to build the docker container:
|
||||
```shell
|
||||
go install github.com/wailsapp/wails/v3/cmd/wails3@latest
|
||||
```
|
||||
|
||||
```shell
|
||||
wails3 task docs:setup
|
||||
```
|
||||
4. Serve the documentation locally:
|
||||
The documentation uses mkdocs, so you will need to install
|
||||
[Python](https://www.python.org/). Once installed, you can setup the
|
||||
documentation by running the following command:
|
||||
|
||||
```shell
|
||||
wails3 task docs:serve
|
||||
```
|
||||
```bash
|
||||
wails3 task docs:setup
|
||||
```
|
||||
|
||||
5. Open your browser to [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
This will install the required dependencies for you.
|
||||
|
||||
6. For a complete build, run:
|
||||
If you have installed the wails3 CLI, you can run the following command to build
|
||||
the documentation and serve it locally:
|
||||
|
||||
```shell
|
||||
wails3 task docs:build
|
||||
```
|
||||
```bash
|
||||
wails3 task docs:serve
|
||||
```
|
||||
|
||||
### Manual Setup
|
||||
|
||||
To install manually, you will need to do the following:
|
||||
|
||||
- Install [Python](https://www.python.org/)
|
||||
- Run `pip install -r requirements.txt` to install the required dependencies
|
||||
- Run `mkdocs serve` to serve the documentation locally
|
||||
- Run `mkdocs build` to build the documentation
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ tasks:
|
||||
setup:
|
||||
summary: Setup the project
|
||||
preconditions:
|
||||
- sh: docker version
|
||||
msg: "Looks like docker isn't installed. Visit https://www.docker.com to download and install."
|
||||
- sh: python{{exeExt}} --version
|
||||
msg: "Looks like Python isn't installed. Python is required to build the documentation: https://www.python.org/downloads/"
|
||||
cmds:
|
||||
- docker build -t squidfunk/mkdocs-material .
|
||||
- python -m pip install -r requirements.txt --user
|
||||
|
||||
setup:insiders:
|
||||
summary: Setup the project (insiders)
|
||||
@@ -31,54 +31,18 @@ tasks:
|
||||
build:
|
||||
summary: Builds the documentation
|
||||
preconditions:
|
||||
- sh: docker version
|
||||
msg: "Looks like docker isn't installed. Visit https://www.docker.com to download and install."
|
||||
- sh: mkdocs --version
|
||||
msg: "Looks like mkdocs isn't installed. Run `wails3 task setup` or `task setup` in the documentation directory to install it."
|
||||
cmds:
|
||||
- build:windows
|
||||
- build:unix
|
||||
|
||||
build:windows:
|
||||
summary: Builds the documentation (Windows)
|
||||
internal: true
|
||||
platforms:
|
||||
- windows
|
||||
cmds:
|
||||
- docker run --rm -v "%cd%":/docs squidfunk/mkdocs-material build
|
||||
|
||||
build:unix:
|
||||
summary: Builds the documentation (Unix)
|
||||
internal: true
|
||||
platforms:
|
||||
- darwin
|
||||
- linux
|
||||
cmds:
|
||||
- docker run --rm -v "$(pwd)":/docs squidfunk/mkdocs-material build
|
||||
- mkdocs build
|
||||
|
||||
serve:
|
||||
summary: Builds the documentation and serves it locally
|
||||
preconditions:
|
||||
- sh: docker version
|
||||
msg: "Looks like docker isn't installed. Visit https://www.docker.com to download and install."
|
||||
- sh: mkdocs --version
|
||||
msg: "Looks like mkdocs isn't installed. Run `wails3 task setup` or `task setup` in the documentation directory to install it."
|
||||
cmds:
|
||||
- task: serve:windows
|
||||
- task: serve:unix
|
||||
|
||||
serve:windows:
|
||||
summary: Builds the documentation and serves it locally (Windows)
|
||||
internal: true
|
||||
platforms:
|
||||
- windows
|
||||
cmds:
|
||||
- docker run --rm -it -p 8000:8000 -v "%cd%":/docs squidfunk/mkdocs-material
|
||||
|
||||
serve:unix:
|
||||
summary: Builds the documentation and serves it locally (Unix)
|
||||
internal: true
|
||||
platforms:
|
||||
- darwin
|
||||
- linux
|
||||
cmds:
|
||||
- docker run --rm -it -p 8000:8000 -v "$(pwd)":/docs squidfunk/mkdocs-material
|
||||
- mkdocs serve
|
||||
|
||||
serve:insiders:
|
||||
summary: Builds the documentation and serves it locally
|
||||
|
||||
@@ -31,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Support multiple space-separated trigger events in the WML system by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295)
|
||||
- Add ESM exports from the bundled JS runtime script by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295)
|
||||
- Add binding generator flag for using the bundled JS runtime script instead of the npm package by [@fbbdev](https://github.com/fbbdev) in [#3334](https://github.com/wailsapp/wails/pull/3334)
|
||||
- Implement `setIcon` on linux by [@abichinger](https://github.com/abichinger) in [#3354](https://github.com/wailsapp/wails/pull/3354)
|
||||
- Add flag `-port` to dev command and support environment variable `WAILS_VITE_PORT` by [@abichinger](https://github.com/abichinger) in [#3429](https://github.com/wailsapp/wails/pull/3429)
|
||||
- Add tests for bound method calls by [@abichinger](https://github.com/abichinger) in [#3431](https://github.com/wailsapp/wails/pull/3431)
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -56,6 +59,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Fix custom context menu closing immediately on linux by [@abichinger](https://github.com/abichinger) in [#3330](https://github.com/wailsapp/wails/pull/3330)
|
||||
- Fix the output path and extension of model files produced by the binding generator by [@fbbdev](https://github.com/fbbdev) in [#3334](https://github.com/wailsapp/wails/pull/3334)
|
||||
- Fix the import paths of model files in JS code produced by the binding generator by [@fbbdev](https://github.com/fbbdev) in [#3334](https://github.com/wailsapp/wails/pull/3334)
|
||||
- Fix drag-n-drop on some linux distros by [@abichinger](https://github.com/abichinger) in [#3346](https://github.com/wailsapp/wails/pull/3346)
|
||||
- Fix missing task for macOS when using `wails3 task dev` by [@hfoxy](https://github.com/hfoxy) in [#3417](https://github.com/wailsapp/wails/pull/3417)
|
||||
- Fix registering events causing a nil map assignment by [@hfoxy](https://github.com/hfoxy) in [#3426](https://github.com/wailsapp/wails/pull/3426)
|
||||
- Fix unmarshaling of bound method parameters by [@fbbdev](https://github.com/fbbdev) in [#3431](https://github.com/wailsapp/wails/pull/3431)
|
||||
- Fix handling of multiple return values from bound methods by [@fbbdev](https://github.com/fbbdev) in [#3431](https://github.com/wailsapp/wails/pull/3431)
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ posts before creating new ones. Here are the different ways to provide feedback:
|
||||
|
||||
=== "Bugs"
|
||||
|
||||
If you find a bug, please let us know by posting into the [v3 Alpha Feedback](https://discord.gg/3mgVyGua) channel on Discord.
|
||||
If you find a bug, please let us know by posting into the [v3 Alpha Feedback](https://discord.gg/Vgff2p8gsy) channel on Discord.
|
||||
|
||||
- The post should clearly state what the bug is and have a simple reproducible example. If the docs are unclear what *should* happen, please include that in the post.
|
||||
- The post should be given the `Bug` tag.
|
||||
@@ -24,17 +24,17 @@ posts before creating new ones. Here are the different ways to provide feedback:
|
||||
If you have a fix for a bug or an update for documentation, please do the following:
|
||||
|
||||
- Open a pull request on the [Wails repository](https://github.com/wailsapp/wails). The title of the PR should start with `[v3 alpha]`.
|
||||
- Create a post in the [v3 Alpha Feedback](https://discord.gg/3mgVyGua) channel.
|
||||
- Create a post in the [v3 Alpha Feedback](https://discord.gg/Vgff2p8gsy) channel.
|
||||
- The post should be given the `PR` tag.
|
||||
- Please include a link to the PR in your post.
|
||||
|
||||
=== "Suggestions"
|
||||
|
||||
If you have a suggestion, please let us know by posting into the [v3 Alpha Feedback](https://discord.gg/3mgVyGua) channel on Discord:
|
||||
If you have a suggestion, please let us know by posting into the [v3 Alpha Feedback](https://discord.gg/Vgff2p8gsy) channel on Discord:
|
||||
|
||||
- The post should be given the `Suggestion` tag.
|
||||
|
||||
Please feel free to reach out to us on [Discord](https://discord.gg/3mgVyGua) if you have any questions.
|
||||
Please feel free to reach out to us on [Discord](https://discord.gg/Vgff2p8gsy) if you have any questions.
|
||||
|
||||
=== "Upvoting"
|
||||
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
# Enums
|
||||
|
||||
In Go, an enum (enumeration) is a user-defined type that consists of a set of named constants called enumerators. Enums
|
||||
are useful for representing a fixed set of values that a variable can take.
|
||||
|
||||
To define an enum in Go, you can use a type declaration with a list of constant values. Here's an example:
|
||||
|
||||
```go
|
||||
type Title string
|
||||
|
||||
const (
|
||||
Mr Title = "Mr"
|
||||
Mrs Title = "Mrs"
|
||||
Ms Title = "Ms"
|
||||
)
|
||||
```
|
||||
|
||||
In this example, we define an enum type called `Title` using the `type` keyword. We then declare a set of constants
|
||||
(`Mr`, `Mrs`, `Ms`) of type `Title` using the `const` keyword.
|
||||
|
||||
## Using Enums in Bound Structs
|
||||
|
||||
Let's extend our previous example to use the `Title` enum in the `Person` struct:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"log"
|
||||
)
|
||||
|
||||
// Title is a title
|
||||
type Title string
|
||||
|
||||
const (
|
||||
Mr Title = "Mr"
|
||||
Mrs Title = "Mrs"
|
||||
Ms Title = "Ms"
|
||||
)
|
||||
|
||||
// Person is a person
|
||||
type Person struct {
|
||||
// Name of the person
|
||||
Name string
|
||||
// Title of the person
|
||||
Title Title
|
||||
}
|
||||
|
||||
type GreetService struct{}
|
||||
|
||||
func (g *GreetService) Greet(person Person) string {
|
||||
return "Hello " + string(person.Title) + " " + person.Name
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Bind: []any{
|
||||
&GreetService{},
|
||||
},
|
||||
})
|
||||
// ....
|
||||
app.NewWebviewWindow()
|
||||
err := app.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this updated example, we add a `Title` field of type `Title` to the `Person` struct. The `Greet` method now includes the `Title` in the greeting message.
|
||||
|
||||
When we run the bindings generator, it will process the enum and generate the corresponding JavaScript or TypeScript code.
|
||||
|
||||
## Generating Bindings with Enums
|
||||
|
||||
After adding the `Title` enum to our example, let's generate the bindings using the following command:
|
||||
|
||||
```bash
|
||||
% wails3 generate bindings
|
||||
```
|
||||
|
||||
The output should display information about the processed package, struct, method, enum, and model:
|
||||
|
||||
```bash
|
||||
INFO Processed: 1 Package, 1 Struct, 1 Method, 1 Enum, 1 Model in 1.044166ms.
|
||||
INFO Output directory: /Users/lea/GolandProjects/tempdocs/binding/frontend/bindings
|
||||
```
|
||||
|
||||
If we look in the `frontend/bindings` directory, we should see a generated `models.js` file that includes the enum definition:
|
||||
|
||||
```javascript
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Ă‚ MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
export const Title = {
|
||||
Mr: "Mr",
|
||||
Mrs: "Mrs",
|
||||
Ms: "Ms",
|
||||
};
|
||||
|
||||
/**
|
||||
* Person defines a person
|
||||
*/
|
||||
export class Person {
|
||||
/**
|
||||
* Creates a new Person instance.
|
||||
* @param {Partial<Person>} [source = {}] - The source object to create the Person.
|
||||
*/
|
||||
constructor(source = {}) {
|
||||
if (!("Name" in source)) {
|
||||
/**
|
||||
* Name of the person
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["Name"] = "";
|
||||
}
|
||||
if (!("Title" in source)) {
|
||||
/**
|
||||
* Title of the person
|
||||
* @member
|
||||
* @type {Title}
|
||||
*/
|
||||
this["Title"] = null;
|
||||
}
|
||||
Object.assign(this, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The generated `models.js` file includes the `Title` enum definition, which is exported as a read-only object with the enum values as properties. The `Person` class also includes a `Title` property of type `Title`.
|
||||
|
||||
You can now use the generated enum and class in your frontend code when interacting with the bound `GreetService` struct.
|
||||
@@ -1,14 +0,0 @@
|
||||
# Bindings Generator Guide
|
||||
|
||||
Welcome to the Wails v3 Bindings Generator Guide!
|
||||
|
||||
One of the key features of Wails is the ability to seamlessly integrate backend Go code with the frontend, enabling
|
||||
efficient communication between the two layers. This can be done manually by sending messages between the frontend and
|
||||
backend, but this can be cumbersome and error-prone, especially when dealing with complex data types.
|
||||
|
||||
The bindings generator in Wails v3 simplifies this process by automatically generating JavaScript or TypeScript
|
||||
functions and models that reflect the methods and data structures defined in your Go code. This means you can write
|
||||
your backend logic in Go and easily expose it to the frontend without the need for manual binding or complex integration.
|
||||
|
||||
This guide is designed to help you understand and utilise this powerful binding tool.
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
# Binding Models
|
||||
|
||||
In addition to binding methods, you can also use structs as input or output parameters in your bound methods. When structs are used as parameters, Wails generates corresponding JavaScript versions of those types.
|
||||
|
||||
Let's extend the previous example to use a `Person` type that has a `Name` field:
|
||||
|
||||
```go title="main.go"
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"log"
|
||||
)
|
||||
|
||||
// Person defines a person
|
||||
type Person struct {
|
||||
// Name of the person
|
||||
Name string
|
||||
}
|
||||
|
||||
type GreetService struct{}
|
||||
|
||||
func (g *GreetService) Greet(person Person) string {
|
||||
return "Hello " + person.Name
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Bind: []any{
|
||||
&GreetService{},
|
||||
},
|
||||
})
|
||||
// ....
|
||||
app.NewWebviewWindow()
|
||||
err := app.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
In this updated example, we define a `Person` struct with a `Name` field. The `Greet` method in the `GreetService` struct
|
||||
now takes a `Person` as an input parameter.
|
||||
|
||||
When you run the bindings generator, Wails will generate a corresponding JavaScript `Person` type that mirrors the Go
|
||||
struct. This allows you to create instances of the `Person` type in your frontend code and pass them to the bound
|
||||
`Greet` method.
|
||||
|
||||
If we run the bindings generator again, we should see the following output:
|
||||
|
||||
```bash
|
||||
% wails3 generate bindings
|
||||
INFO Processed: 1 Package, 1 Struct, 1 Method, 0 Enums, 1 Models in 4.075625ms.
|
||||
INFO Output directory: /Users/me/myproject/frontend/bindings
|
||||
```
|
||||
|
||||
In the `frontend/bindings/main` directory, you should see a new `models.js` file containing the following code:
|
||||
|
||||
```javascript title="models.js"
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Ă‚ MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* Person defines a person
|
||||
*/
|
||||
export class Person {
|
||||
/**
|
||||
* Creates a new Person instance.
|
||||
* @param {Partial<Person>} [source = {}] - The source object to create the Person.
|
||||
*/
|
||||
constructor(source = {}) {
|
||||
if (!("Name" in source)) {
|
||||
/**
|
||||
* Name of the person
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["Name"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
The `Person` class is generated with a constructor that takes an optional `source` parameter, which allows you to
|
||||
create a new `Person` instance from an object. It also has a static `createFrom` method that can create a `Person`
|
||||
instance from a string or object.
|
||||
|
||||
You may also notice that comments in the Go struct are kept in the generated JavaScript code! This can be helpful for
|
||||
understanding the purpose of the fields and methods in the generated models and should be picked up by your IDE.
|
||||
|
||||
## Using Bound Models
|
||||
|
||||
Here's an example of how you can use the generated JavaScript `Person` type in your frontend code:
|
||||
|
||||
```javascript title="main.js"
|
||||
import {Greet} from "./bindings/main/GreetService.js";
|
||||
import {Person} from "./bindings/main/models.js";
|
||||
|
||||
const resultElement = document.getElementById('result');
|
||||
|
||||
async function doGreet() {
|
||||
let person = new Person({Name: document.getElementById('name').value});
|
||||
if (!person.Name) {
|
||||
person.Name = 'anonymous';
|
||||
}
|
||||
resultElement.innerText = await Greet(person);
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we import the generated `Person` type from the `models` module. We create a new instance of `Person`,
|
||||
set its `Name` property, and pass it to the `Greet` method.
|
||||
|
||||
Using bound models allows you to work with complex data structures and seamlessly pass them between the frontend and
|
||||
backend of your Wails application.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user