tauri 的自动启动插件怎么用

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

bun tauri add autostart

autostart 插件因为我只需要在前端使用,所以只复制了javascript的用法,使用了不好使。

复制代码
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';

// 启用 autostart
await enable();
// 检查 enable 状态
console.log(`registered for autostart? ${await isEnabled()}`);
// 禁用 autostart
disable();

报下面文件找不到系统文件

复制代码
import { invoke } from '@tauri-apps/api/core';

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
async function isEnabled() {
    return await invoke('plugin:autostart|is_enabled');
}
async function enable() {
    await invoke('plugin:autostart|enable');
}
async function disable() {
    await invoke('plugin:autostart|disable');
}

export { disable, enable, isEnabled };

用vscode打开这个文件发现,这个文件需要调用rust的'plugin:autostart|enable'这些方法没有,需要在lib.rs中实现,晕还得把rust写法后拷贝进来

复制代码
    tauri::Builder::default()
        .plugin(tauri_plugin_autostart::init(
            MacosLauncher::LaunchAgent,
            Some(vec!["--flag1", "--flag2"]),
        ))
        .setup(|app| {
            // 获取自动启动管理器
            let autostart_manager = app.autolaunch();
            // 启用 autostart
            let _ = autostart_manager.enable();
            // 禁用 autostart
            let _ = autostart_manager.disable();

好使了。

相关推荐
特立独行的猫a17 小时前
用仓颉语言给娃写了个打字练习游戏:cj-tauri 项目实战
游戏·ui·框架·tauri·仓颉·cangjie·cj-tauri
行者-全栈开发2 天前
华为云码道 CodeArts 实测:让 AI 用 Rust 写一个 Git 仓库健康度体检台「仓衡」
git·rust·tauri·桌面应用·ai 编程·华为云码道·codearts 代码智能体
特立独行的猫a5 天前
用仓颉写一个 Tauri:IPC 的每次往返实现原理(web层到仓颉层的触发过程)
前端·ui·harmonyos·tauri·鸿蒙·仓颉
Leaderxin24 天前
还在用 Electron?6 种跨平台桌面方案横评:Rust + Vue 把安装包从 224MB 干到 4.7MB
rust·vue·跨平台·tauri·桌面应用
q平面人1 个月前
【总工笔记】mindoc平板、桌面端笔记软件,发布到mindoc服务端
rust·tauri·华为平板·mindoc·总工笔记
MC皮蛋侠客1 个月前
Tauri 2.x 系列(九):安全模型——Capabilities、Permissions、Scope 与 CSP
rust·tauri
MC皮蛋侠客1 个月前
Tauri 2.x 系列(八):与其他语言结合——Sidecar、服务、FFI 与插件的选择
rust·tauri