Skip to content
Merged
Changes from all 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
135 changes: 130 additions & 5 deletions src/content/docs/features/autostart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,137 @@ title: Autostart
description: Automatically launch your app at system startup.
---

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="autostart" />

<Stub>
Based on
https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/autostart
</Stub>
Automatically launch your application at system startup.

## Supported Platforms

- Windows
- Mac (via AppleScript or Launch Agent)
- Linux

## Setup

Install the autostart plugin to get started.

<Tabs>
<TabItem label="Automatic">

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

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

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

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

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

```rust title="lib.rs" ins={1, 6}
use tauri_plugin_autostart::MacosLauncher;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]) /* arbitrary number of args to pass to your app */))
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

3. You can install the JavaScript Guest bindings using your preferred JavaScript package manager:

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

## Usage

The autostart plugin is available in both JavaScript and Rust.

<Tabs>
<TabItem label="JavaScript">

```js
import { enable, isEnabled, disable } from "@tauri-apps/plugin-autostart";

// Enable autostart
await enable();
// Check enable state
console.log(`registered for autostart? ${await isEnabled()}`);
// Disable autostart
disable();
```

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

```rust
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
Some(vec!["--flag1", "--flag2"]),
))
.setup(|app| {
// Get the autostart manager
let autostart_manager = app.autolaunch();
// Enable autostart
let _ = autostart_manager.enable();
// Check enable state
println!("registered for autostart? {}", autostart_manager.is_enabled().unwrap());
// Disable autostart
let _ = autostart_manager.disable();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

</TabItem>
</Tabs>

## Permissions

By default all plugin commands are blocked and cannot be accessed.
You must define a list of permissions in your `capabilities` configuration.

See [Access Control List](/references/v2/acl) for more information.

```json title="src-tauri/capabilities/main.json"
{
"permissions": [
...,
"autostart:allow-enable",
"autostart:allow-disable",
"autostart:allow-is-enabled"
]
}
```

| Permission | Description |
| --- | --- |
| `autostart:allow-disable` | Enables the disable command without any pre-configured scope. |
| `autostart:deny-disable` | Denies the disable command without any pre-configured scope. |
| `autostart:allow-enable` | Enables the enable command without any pre-configured scope. |
| `autostart:deny-enable` | Denies the enable command without any pre-configured scope. |
| `autostart:allow-is-enabled` | Enables the is_enabled command without any pre-configured scope. |
| `autostart:deny-is-enabled` | Denies the is_enabled command without any pre-configured scope. |