You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Tauri(Vite)应用.exe移出release文件夹后无法发送Windows通知?

问题

我使用Tauri 2.0搭配前端Vite/Vue开发仅针对Windows平台的应用,已完成官方通知插件的集成。

在dev环境、build环境下,以及直接运行release文件夹内的.exe时,所有功能(包括通知)均正常工作。但将该.exe移出release文件夹后,应用可正常运行,唯独通知功能完全失效,且控制台无任何报错信息。即使是仅添加通知功能的全新项目也存在同样问题。

配置代码

tauri.conf.json

{
  "$schema": "https://schema.tauri.app/config/2",
  "productName": "myapp",
  "version": "0.1.0",
  "identifier": "com.myapp.app",
  "build": {
    "beforeDevCommand": "npm run dev",
    "devUrl": "http://localhost:5173",
    "beforeBuildCommand": "npm run build",
    "frontendDist": "../dist"
  },
  "app": {
    "windows": [
      {
        "title": "myapp",
        "width": 400,
        "height": 320,
        "minWidth": 320,
        "minHeight": 80
      }
    ],
    "security": {
      "csp": null
    }
  },
  "bundle": {
    "active": true,
    "targets": [ "app" ],
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/128x128@2x.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ]
  }
}

lib.rs

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_notification::init())
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

发送通知的JavaScript代码(已确认可正常工作)

async request() {
  let permissionGranted = await isPermissionGranted();
  if (!permissionGranted) {
    const permission = await requestPermission();
    permissionGranted = permission === 'granted';
  }
  return permissionGranted;
}

async send(options) {
  const hasPermission = await this.request();
  if(hasPermission) {
    sendNotification(options);
  }
}

原因分析

Tauri 2.0的通知插件依赖同目录下的tauri-plugin-notification.dll文件,该文件会随.exe一起生成在release文件夹中。单独移动.exe时未携带这个依赖库,导致通知功能无法加载执行。

解决办法

  • 生成安装包:修改tauri.conf.json中bundle.targets为["msi"],执行npm run tauri build生成Windows安装程序。安装后系统会自动处理依赖,无需手动管理文件。
  • 绿色版部署:将release文件夹中的tauri-plugin-notification.dll与.exe放在同一目录下,通知功能即可正常使用。

内容的提问来源于stack exchange,提问作者Dan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 04:47:24