跳转到内容
Tauri

自动启动

在系统启动时自动启动应用程序。

支持的平台

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

设置

从安装 autostart 插件开始。

使用项目的包管理器来添加依赖。

npm run tauri add autostart

用法

autostart 插件有 JavaScript 和 Rust 两种版本。

import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';
// 启用 autostart
await enable();
// 检查 enable 状态
console.log(`registered for autostart? ${await isEnabled()}`);
// 禁用 autostart
disable();

权限

默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 capabilities 文件夹中的配置来启用它们。

参见能力概览以获取更多信息,以及插件的分步导览来调整插件权限。

src-tauri/capabilities/default.json
{
"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-enable
  • allow-disable
  • allow-is-enabled

Permission Table

Identifier 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.


© 2025 Tauri Contributors. CC-BY / MIT