开机启动
安装包
- 在src-tauri/Cargo.toml中添加如下配置,安装tauri插件
[dependencies]
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
- 使用npm安装
npm add https://github.com/tauri-apps/tauri-plugin-autostart#v1
使用
- 在tauri中注册插件
use tauri_plugin_autostart::MacosLauncher;
fn main() {
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");
}
- 在前端页面中引入API
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api";
await enable();
console.log(`registered for autostart? ${await isEnabled()}`);
disable();