Skip to content
Tauri 中文网

自动启动

在系统启动时自动启动你的应用。

¥Automatically launch your application at system startup.

支持的平台

¥Supported Platforms

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

设置

¥Setup

安装自动启动插件以开始使用。

¥Install the autostart plugin to get started.

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

¥Use your project’s package manager to add the dependency:

npm run tauri add autostart

使用

¥Usage

自动启动插件在 JavaScript 和 Rust 中都可用。

¥The autostart plugin is available in both JavaScript and Rust.

import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';
// when using `"withGlobalTauri": true`, you may use
// const { enable, isEnabled, disable } = window.__TAURI__.autostart;
// Enable autostart
await enable();
// Check enable state
console.log(`registered for autostart? ${await isEnabled()}`);
// Disable autostart
disable();

权限

¥Permissions

默认情况下,所有潜在危险的插件命令和范围都会被阻止,无法访问。你必须修改 capabilities 配置中的权限才能启用这些权限。

¥By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities configuration to enable these.

有关更详细的说明,请参阅 功能概述

¥See the Capabilities Overview for more information and the step by step guide to use plugin permissions.

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.

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


Tauri 中文网 - 粤ICP备13048890号