Files

101 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

2021-09-27 19:35:30 +10:00
---
sidebar_position: 1
---
# Introduction
2022-11-28 17:13:22 +08:00
The runtime is a library that provides utility methods for your application. There is both a Go and JavaScript runtime
2021-09-27 19:35:30 +10:00
and the aim is to try and keep them at parity where possible.
2022-08-27 11:17:03 +10:00
It has utility methods for:
- [Window](window.mdx)
- [Menu](menu.mdx)
- [Dialog](dialog.mdx)
- [Events](events.mdx)
- [Browser](browser.mdx)
- [Log](log.mdx)
2023-01-05 06:41:07 +01:00
- [Clipboard](clipboard.mdx)
2022-08-27 11:17:03 +10:00
2021-09-27 19:35:30 +10:00
The Go Runtime is available through importing `github.com/wailsapp/wails/v2/pkg/runtime`. All methods in this package
2022-03-30 23:21:33 +11:00
take a context as the first parameter. This context should be obtained from the [OnStartup](../options.mdx#onstartup)
or [OnDomReady](../options.mdx#ondomready) hooks.
:::info Note
Whilst the context will be provided to the
2022-03-30 23:21:33 +11:00
[OnStartup](../options.mdx#onstartup) method, there's no guarantee the runtime will work in this method as
the window is initialising in a different thread. If
2022-03-30 23:21:33 +11:00
you wish to call runtime methods at startup, use [OnDomReady](../options.mdx#ondomready).
:::
2021-09-27 19:35:30 +10:00
2022-11-28 17:13:22 +08:00
The JavaScript library is available to the frontend via the `window.runtime` map. There is a runtime package generated when using `dev`
mode that provides TypeScript declarations for the runtime. This should be located in the `wailsjs` directory in your
2021-09-27 19:35:30 +10:00
frontend directory.
### Hide
2022-08-27 11:17:03 +10:00
Go: `Hide(ctx context.Context)`<br/>
JS: `Hide()`
Hides the application.
:::info Note
On Mac, this will hide the application in the same way as the `Hide` menu item in standard Mac applications.
This is different to hiding the window, but the application still being in the foreground.
For Windows and Linux, this is currently the same as `WindowHide`.
:::
### Show
Shows the application.
:::info Note
On Mac, this will bring the application back into the foreground.
For Windows and Linux, this is currently the same as `WindowShow`.
:::
2022-08-27 11:17:03 +10:00
Go: `Show(ctx context.Context)`<br/>
JS: `Show()`
2022-02-04 07:52:45 +11:00
2022-08-27 11:17:03 +10:00
### Quit
2022-02-04 07:52:45 +11:00
Quits the application.
2022-08-27 11:17:03 +10:00
Go: `Quit(ctx context.Context)`<br/>
JS: `Quit()`
2022-02-04 07:52:45 +11:00
2022-08-27 11:17:03 +10:00
### Environment
2022-02-04 07:52:45 +11:00
Returns details of the current environment.
2022-08-27 11:17:03 +10:00
Go: `Environment(ctx context.Context) EnvironmentInfo`<br/>
JS: `Environment(): Promise<EnvironmentInfo>`
2022-02-04 07:52:45 +11:00
#### EnvironmentInfo
2022-08-27 11:17:03 +10:00
Go:
2022-02-04 07:52:45 +11:00
```go
type EnvironmentInfo struct {
2022-08-27 11:17:03 +10:00
BuildType string
Platform string
Arch string
}
```
2022-08-27 11:17:03 +10:00
JS:
2022-08-27 11:17:03 +10:00
```ts
interface EnvironmentInfo {
buildType: string;
platform: string;
arch: string;
2022-02-04 07:52:45 +11:00
}
```