过程
此插件提供用于访问当前进程的 API。要生成子进程,请参阅 shell 插件。
¥This plugin provides APIs to access the current process. To spawn child processes, see the shell plugin.
支持的平台
¥Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | ||
linux | ||
macos | ||
android | | |
ios | |
设置
¥Setup
安装插件进程即可开始使用。
¥Install the plugin-process to get started.
使用项目的包管理器添加依赖:
¥Use your project’s package manager to add the dependency:
npm run tauri add process
yarn run tauri add process
pnpm tauri add process
deno task tauri add process
bun tauri add process
cargo tauri add process
-
Run the following command in the
src-tauri
folder to add the plugin to the project’s dependencies inCargo.toml
:cargo add tauri-plugin-process -
Modify
lib.rs
to initialize the plugin:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_process::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
If you’d like to utilize the plugin in JavaScript then install the npm package as well:
npm install @tauri-apps/plugin-processyarn add @tauri-apps/plugin-processpnpm add @tauri-apps/plugin-processdeno add npm:@tauri-apps/plugin-processbun add @tauri-apps/plugin-process
使用
¥Usage
流程插件在 JavaScript 和 Rust 中均可用。
¥The process plugin is available in both JavaScript and Rust.
import { exit, relaunch } from '@tauri-apps/plugin-process';// when using `"withGlobalTauri": true`, you may use// const { exit, relaunch } = window.__TAURI__.process;
// exits the app with the given status codeawait exit(0);
// restarts the appawait relaunch();
请注意,app
是 AppHandle
的实例。
¥Note that app
is an instance of AppHandle
.
// exits the app with the given status codeapp.exit(0);
// restarts the appapp.restart();
权限
¥Permissions
默认情况下,所有潜在危险的插件命令和范围都会被阻止,无法访问。你必须修改 capabilities
配置中的权限才能启用这些权限。
¥By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities
configuration to enable these.
有关更详细的说明,请参阅 功能概述。
¥See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
{ "permissions": [ ..., "process:default", ]}
Default Permission
This permission set configures which process features are by default exposed.
Granted Permissions
This enables to quit via allow-exit
and restart via allow-restart
the application.
allow-exit
allow-restart
Permission Table
Identifier | Description |
---|---|
|
Enables the exit command without any pre-configured scope. |
|
Denies the exit command without any pre-configured scope. |
|
Enables the restart command without any pre-configured scope. |
|
Denies the restart command without any pre-configured scope. |
Tauri 中文网 - 粤ICP备13048890号