NiceLeeのBlog 用爱发电 bilibili~

备忘录 关于tauri的二三事

2023-01-03
nIceLee

阅读:


官方文档已经整理得挺好的,这里额外补充一些注意事项

常见错误

This version of %1 is not compatible with the version of Windows currently running. Check in your computer's system information, then contact the software publisher.

该版本的 %1 与你运行的 Windows 版本不兼容。请查看计算机的系统信息,然后联系软件发布者。
  • 先检查前置条件是否满足
  • Webview2版本对此可能会有影响,卸载它然后重装
打包的时候: 
info: Verifying wix package
info: Downloading https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip
  • 将文件wix311-binaries.zip下载,然后解压文件到C:\Users[用户名]\AppData\Local\tauri\WixTools文件夹中

开发常用命令

# 生成初始工程
cargo create-tauri-app

# 这里是以npm为包管理
vite                            # 只专注于前端界面开发
npm run tauri dev               # 开发
npm run tauri build             # 打包编译
npm run tauri build --debug     # 打包编译debug版本
npm run tauri icon ./icon.png   # 根据icon生成程序需要的一系列图标(必须是正方形)

# 二进制 src-tauri/target/release/[app name]
# 安装包 src-tauri/target/release/bundle/

自升级

原理

  • 生成私钥和公钥
  • 在程序里配置公钥和升级地址(这个地址返回的格式为json, 内容包括版本、各平台的升级包下载地址和私钥生成的签名等)
  • 生成各平台所需的安装包、升级包、升级包的签名
  • 发布release、更新升级地址的内容

  • 这里的话,我们以利用Github Actions进行编译和分发举例,有如下解决方案:
    • 编译并发布release,可以参考tauri-action
    • 关于升级地址,我们可以自建一个release(比如updater),专门指定一个附件(比如update.json)来指示更新内容。那么升级地址就是附件的下载地址:
      原始地址:        https://github.com/{owner}/{repo}/releases/download/updater/update.json
      fastgit代理:     https://hub.fgit.ml/{owner}/{repo}/releases/download/updater/update.json
      ghproxy代理:     https://ghproxy.com/https://github.com/{owner}/{repo}/releases/download/updater/update.json
      
    • 关于升级内容,我们可以等待新版本的release构建并发布完毕,写个脚本,查询最新版本的升级包地址和签名,可以参考update.mjs
      它会根据最新版本生成json,并推送到updaterrelease的update.json附件。
      需要设置环境变量GITHUB_TOKEN

实现

  • 生成私钥和公钥
    tauri signer generate -w  ./tauri.key
    
  • 配置tauri.conf.json
    "updater": {
      "active": true,
      "endpoints": [
          "https://github.com/{owner}/{repo}/releases/download/updater/update.json",
          "https://hub.fgit.ml/{owner}/{repo}/releases/download/updater/update.json",
          "https://ghproxy.com/https://github.com/{owner}/{repo}/releases/download/updater/update.json"
      ],
      "dialog": false,
      "pubkey": "{PUBLIC_KEY}"
    }
    
  • 在Github对应项目新建Release,名称为updater

  • 构建并发布release
    参考tauri-actionMasterLee
    注意需要设置TAURI_PRIVATE_KEYTAURI_KEY_PASSWORD(如果私钥设置了密码的话)

  • 生成update.json
    参考update.mjs
    # 设置好环境变量GITHUB_TOKEN
    node ./.github/scripts/update.mjs
    

相似文章

内容
隐藏