关于tauri自动通知更新

自动通知应用升级

疑问:是如何来通知用户应用升级

官方文档了解情况

tauri 分发打包官网

步骤1

首先生成私钥和秘钥

我是windows系统

步骤2

在tauri.config.json中新增updater配置

重要的两个字段

endpoints:从地址中获取更新的内容,判断是否需要更新

pubkey:步骤一生成的公钥,带pub后缀的那个

tips:

endpoints中通常用静态的json文件来配置,例如

url:更新包的url地址

signature:.sig文件的内容,每次构建时可能都会改变

步骤3

在github中设置环境变量

TAURI_PRIVATE_KEY:步骤一生成的私钥

TAURI_KEY_PASSWORD:步骤一输入了两次的密码

tips:

在本地打包时,需要配置环境变量

步骤4

从tauri-action文档学习到了一个github打包的例子,如下

yaml 复制代码
name: 'publish'
​
on: pull_request
​
jobs:
  create-release:
    permissions:
      contents: write
    runs-on: ubuntu-20.04
    outputs:
      release_id: ${{ steps.create-release.outputs.result }}
​
    steps:
      - uses: actions/checkout@v4
      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: get version
        run: echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
      - name: create release
        id: create-release
        uses: actions/github-script@v6
        with:
          script: |
            const { data } = await github.rest.repos.createRelease({
              owner: context.repo.owner,
              repo: context.repo.repo,
              tag_name: `v${process.env.PACKAGE_VERSION}`,
              name: `Desktop App v${process.env.PACKAGE_VERSION}`,
              body: 'Take a look at the assets to download and install this app.',
              draft: true,
              prerelease: false
            })
            return data.id
​
  build-tauri:
    needs: create-release
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        platform: [macos-latest, ubuntu-20.04, windows-latest]
​
    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4
      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: install Rust stable
        uses: dtolnay/rust-toolchain@stable
      - name: install dependencies (ubuntu only)
        if: matrix.platform == 'ubuntu-20.04'
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
      - name: install frontend dependencies
        run: pnpm install # change this to npm or pnpm depending on which one you use
      - uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          releaseId: ${{ needs.create-release.outputs.release_id }}
​
  publish-release:
    permissions:
      contents: write
    runs-on: ubuntu-20.04
    needs: [create-release, build-tauri]
​
    steps:
      - name: publish release
        id: publish-release
        uses: actions/github-script@v6
        env:
          release_id: ${{ needs.create-release.outputs.release_id }}
        with:
          script: |
            github.rest.repos.updateRelease({
              owner: context.repo.owner,
              repo: context.repo.repo,
              release_id: process.env.release_id,
              draft: false,
              prerelease: false
            })

拿到这个模板,github构建就成功了一半,然后呢,我们需要在构建完之后,来生成一个install.json文件来提示更新,这个install.json的地址就是上方的endpoints的地址,具体怎么做的,可以去下方仓库查看

github页面构建

流水线会在这个分支生成一个install.json文件,从而可以通过这个文件来判断是否更新,如果可以通过例如https://liboq.github.io/tauri-example/install.json来访问到,则表示github页面构建成功(需要把我的仓库和用户名替换哦)

最后

经过多次测试,最后终于成功了!自动提示更新成功

源码地址

tauri-example欢迎star!

References

https://mp.weixin.qq.com/s?__biz=MzIzNjE2NTI3NQ==&mid=2247485470&idx=1&sn=1bc6105add6614312db2b37784b8a3c4&chksm=e8dd49eadfaac0fc38610916c3430f43764eb6fd5e04771365ee277d329a647800561616a90d&scene=178&cur_album_id=2593843659863752704&poc_token=HD4jrmWjMnJHedUvWGODAD_UBWZ8d_Wah68hOd-M

https://github.com/tauri-apps/tauri-action/tree/v0.3/

相关推荐
小弥儿几秒前
GitHub今日热榜 | 2026-10-22:智能体工具退潮,基础层集中上新
学习·开源·github
沙蒿同学1 分钟前
Wails v3 实战:一个桌面提醒客户端,从 v2 升到 v3 的全过程
前端·后端·github
inquisiter20 分钟前
KernelGpt的部分尝试
java·前端·apache
the局外人42 分钟前
用 TRAE 把 Markdown文档 搬到微信公众号
前端
Autumn_ing43 分钟前
AI原型设计工具怎么选?可编辑原型与可运行前端适合什么场景
前端·小程序·产品经理·代码·codex·墨刀ai客户端·ai原型
夕阳_醉了1 小时前
前端通用组件开发全指南|从 0 到 1 打造稳定可复用的业务组件
前端
Amos_Web1 小时前
Rspack 源码解析(三十):SourceMapDevToolPlugin 如何生成并关联 source map
前端
console.log('npc')1 小时前
从0到1实现任务评价统计功能:React + TypeScript 实战指南(小白注释版)
前端·react.js·typescript
IT_陈寒2 小时前
为什么你应该学习React?
前端·人工智能·后端
ZoeLandia2 小时前
React04:事件处理与受控表单
开发语言·前端·react.js·typescript