5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-16 17:09:28 +08:00
wails/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/intro.mdx
github-actions[bot] 4cd873fecb
docs: sync documents (#2443)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-03-11 17:57:56 +11:00

86 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebar_position: 1
---
# 简介
运行时是一个为应用程序提供实用方法的库。 有 Go 和 JavaScript 运行时,目的是在可能的情况下尝试使它们保持一致。
它具有以下实用方法:
- [窗口](window.mdx)
- [菜单](menu.mdx)
- [对话框](dialog.mdx)
- [事件](events.mdx)
- [浏览器](browser.mdx)
- [日志](log.mdx)
- [剪切板](clipboard.mdx)
Go 运行时可通过导入 `github.com/wailsapp/wails/v2/pkg/runtime` 获取。 此包中的所有方法都将 context 作为第一个参数。 此 context 应该从 [应用启动回调](../options.mdx#onstartup) 或 [前端 Dom 加载完成回调](../options.mdx#ondomready) 回调方法中获取。
:::info 注意
虽然上下文将提供给 [应用启动回调](../../reference/options#应用启动回调) 方法,但不能保证运行时将在此方法中工作,因为窗口正在不同的线程中初始化。 如果您希望在启动时调用运行时方法,请使用 [前端 Dom 加载完成回调](../../reference/options#前端-dom-加载完成回调) 方法。
:::
JavaScript 库可通过 `window.runtime` 提供给前端。 使用 `开发` 模式时会生成一个运行时包,该包为运行时提供 TypeScript 声明。 这应该位于您的前端目录的`wailsjs`目录中。
### 隐藏
Go: `Hide(ctx context.Context)`<br/> JS: `Hide()`
隐藏应用程序。
:::info 注意
`Hide` 在 Mac 上,这将以与标准 Mac 应用程序中的菜单项相同的方式隐藏应用程序。 这与隐藏窗口不同,但应用程序仍处于前台。 对于 Windows 和 Linux这与 `WindowHide` 相同。
:::
### 显示
显示应用程序。
:::info 注意
在 Mac 上,这会将应用程序带回前台。 对于 Windows 和 Linux这目前与 `WindowShow` 相同。
:::
Go: `Show(ctx context.Context)`<br/> JS: `Show()`
### 退出
退出应用程序。
Go: `Quit(ctx context.Context)`<br/> JS: `Quit()`
### 环境
返回当前环境的详细信息。
Go: `Environment(ctx context.Context) EnvironmentInfo`<br/> JS: `Environment(): Promise<EnvironmentInfo>`
#### 环境信息
Go:
```go
type EnvironmentInfo struct {
BuildType string
Platform string
Arch string
}
```
JS:
```ts
interface EnvironmentInfo {
buildType: string;
platform: string;
arch: string;
}
```