tauri-plugin-app-exit-api
Version:
A plugin for tauri@v2 to exit app.
71 lines (52 loc) • 1.75 kB
Markdown
# Tauri Plugin app-exit
A plugin for [tauri@v2](https://v2.tauri.app/zh-cn/) to exit app.
## Platform Supported
| Platform | Supported |
| -------- | :-------: |
| Linux | ✅ |
| Windows | ✅ |
| macOS | ✅ |
| Android | ✅ |
| iOS | ✅ |
This plugin is similar to [tauri-plugin-process](https://v2.tauri.app/plugin/process/), with the addition of support for `Android` and `iOS` platforms.
## Setup
Install the app-exit plugin to get started.
1. Run the following command in the `src-tauri` folder to add the plugin to the project’s dependencies in `Cargo.toml`:
```shell
cargo add tauri-plugin-app-exit@0.1
```
1. Modify `lib.rs` to initialize the plugin:
```diff
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
+ .plugin(tauri_plugin_app_exit::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
1. Install the JavaScript Guest bindings using your preferred JavaScript package manager:
```shell
pnpm add tauri-plugin-app-exit-api@0.1
```
1. Modify `src-tauri/capabilities/default.json` to Allow the frontend to execute the exit_app command.
```diff
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
+ "app-exit:default"
]
}
```
## Usage
```js
import { exitApp } from tauri-plugin-app-exit-api";
exitApp().catch(err => {
console.error(err)
})
```
## [Permission description](./permissions/autogenerated/reference.md)