Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create plugin process guide #1687

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 96 additions & 5 deletions src/content/docs/features/process.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,103 @@ title: Process
description: Access the current process.
---

import Stub from '@components/Stub.astro';
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';

<PluginLinks plugin="process" />

<Stub>
Based on
https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/process
</Stub>
This plugin provides APIs to access the current process. To spawn child processes, see the [shell](/features/shell) plugin.

## Setup

Install the plugin-process to get started.

<Tabs>
<TabItem label="Automatic">

1. Use your project's package manager to add the dependency:

<CommandTabs npm="npm run tauri add process"
yarn="yarn run tauri add process"
pnpm="pnpm tauri add process"
cargo="cargo tauri add process" />

2. Modify `lib.rs` to initialize the plugin:

{/* TODO: Revise once https://github.com/tauri-apps/tauri/issues/7696 is in */}

```rust ins={6}
// lib.rs
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
// Initialize the plugin
.plugin(tauri_plugin_process::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

</TabItem>
<TabItem label="Manual">

1. Run `cargo add tauri-plugin-process` to add the plugin to the project's dependencies in `Cargo.toml`.

2. Modify `lib.rs` to initialize the plugin:

```rust ins={6}
// lib.rs
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
// Initialize the plugin
.plugin(tauri_plugin_process::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

3. If you'd like to utilize the plugin in JavaScript then install the npm package as well:

<CommandTabs
npm="npm install @tauri-apps/plugin-process"
yarn="yarn add @tauri-apps/plugin-process"
pnpm="pnpm add @tauri-apps/plugin-process"
/>
</TabItem>

</Tabs>

## Usage

The process plugin is available in both JavaScript and Rust.

<Tabs>
<TabItem label="JavaScript">

```js
import { exit, relaunch } from '@tauri-apps/plugin-process';

// exits the app with the given status code
await exit(0);

// restarts the app
await relaunch();
```

</TabItem>
<TabItem label="Rust">

Note that `app` is an instance of AppHandle `app: tauri::AppHandle`
lorenzolewis marked this conversation as resolved.
Show resolved Hide resolved

```rust
// exits the app with the given status code
app.exit(0);
lorenzolewis marked this conversation as resolved.
Show resolved Hide resolved

// restarts the app
app.restart();
```

</TabItem>
</Tabs>