Autostart
Lancez automatiquement votre application au démarrage du système.
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | |
| ios | |
Installez le plugin autostart pour commencer.
Utilisez le gestionnaire de paquets de votre projet pour ajouter la dépendance :
npm run tauri add autostartyarn run tauri add autostartpnpm tauri add autostartdeno task tauri add autostartbun tauri add autostartcargo tauri add autostart-
Exécutez la commande suivante dans le dossier
src-tauripour ajouter le plugin aux dépendances du projet dansCargo.toml:cargo add tauri-plugin-autostart --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))' -
Modifiez
lib.rspour initialiser le plugin :src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().setup(|app| {#[cfg(desktop)]app.handle().plugin(tauri_plugin_autostart::init(tauri_plugin_autostart::MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]) /* nombre arbitraire d'arguments à passer à votre application */));Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");} -
Vous pouvez installer les liaisons JavaScript Guest en utilisant votre gestionnaire de paquets JavaScript préféré :
npm install @tauri-apps/plugin-autostartyarn add @tauri-apps/plugin-autostartpnpm add @tauri-apps/plugin-autostartdeno add npm:@tauri-apps/plugin-autostartbun add @tauri-apps/plugin-autostart
Le plugin autostart est disponible en JavaScript et en Rust.
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';// lors de l'utilisation de `"withGlobalTauri": true`, vous pouvez utiliser// const { enable, isEnabled, disable } = window.__TAURI__.autostart;
// Activer le démarrage automatiqueawait enable();// Vérifier l'état d'activationconsole.log(`registered for autostart? ${await isEnabled()}`);// Désactiver le démarrage automatiquedisable();#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .setup(|app| { #[cfg(desktop)] { use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::ManagerExt;
app.handle().plugin(tauri_plugin_autostart::init( MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]), ));
// Obtenir le gestionnaire de démarrage automatique let autostart_manager = app.autolaunch(); // Activer le démarrage automatique let _ = autostart_manager.enable(); // Vérifier l'état d'activation println!("registered for autostart? {}", autostart_manager.is_enabled().unwrap()); // Désactiver le démarrage automatique let _ = autostart_manager.disable(); } Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}Par défaut, toutes les commandes et portées de plugin potentiellement dangereuses sont bloquées et inaccessibles. Vous devez modifier les permissions dans votre configuration capabilities pour les activer.
Consultez la Vue d’ensemble des capacités pour plus d’informations et le guide étape par étape pour utiliser les permissions de plugin.
{ "permissions": [ ..., "autostart:allow-enable", "autostart:allow-disable", "autostart:allow-is-enabled" ]}Default Permission
This permission set configures if your application can enable or disable auto starting the application on boot.
Granted Permissions
It allows all to check, enable and disable the automatic start on boot.
This default permission set includes the following:
allow-enableallow-disableallow-is-enabled
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the disable command without any pre-configured scope. |
|
|
Denies the disable command without any pre-configured scope. |
|
|
Enables the enable command without any pre-configured scope. |
|
|
Denies the enable command without any pre-configured scope. |
|
|
Enables the is_enabled command without any pre-configured scope. |
|
|
Denies the is_enabled command without any pre-configured scope. |
© 2025 Tauri Contributors. CC-BY / MIT