Autostart
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.
Use your project’s package manager to add the dependency:
npm run tauri add autostart
yarn run tauri add autostart
pnpm tauri add autostart
bun tauri add autostart
cargo tauri add autostart
-
Run
cargo add tauri-plugin-autostart
to add the plugin to the project’s dependencies inCargo.toml
. -
Modify
lib.rs
to initialize the plugin:lib.rs 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");} -
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
npm install @tauri-apps/plugin-autostartyarn add @tauri-apps/plugin-autostartpnpm add @tauri-apps/plugin-autostartbun add @tauri-apps/plugin-autostart
Usage
The autostart plugin is available in both JavaScript and Rust.
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';
// Enable autostartawait enable();// Check enable stateconsole.log(`registered for autostart? ${await isEnabled()}`);// Disable autostartdisable();
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");}
Permissions
By default all plugin commands are blocked and cannot be accessed.
You must define a list of permissions in your capabilities
configuration.
See Permissions Overview for more information.
{ "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. |
© 2024 Tauri Contributors. CC-BY / MIT