【问题标题】:How to get My Electron Auto updater to work?如何让 My Electron Auto 更新程序工作?
【发布时间】:2021-06-08 19:47:15
【问题描述】:

当我在我的 Github Repro 中发布新更新时,我正在尝试让我的 Electron Vue.js 应用程序自行更新。

我正在使用“electron-builder”打包我的应用程序,这是我的package.json

我关注了this guide,但没有成功。

这是位于 src/main/index.js 顶部的更新程序部分的代码。

const { app, autoUpdater, dialog } = require('electron')
const server = "https://hazel.scarvite.now.sh/"
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)

setInterval(() => {
    autoUpdater.checkForUpdates()
}, 60000)

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
    const dialogOpts = {
        type: 'info',
        buttons: ['Restart', 'Not Now. On next Restart'],
        title: 'Update',
        message: process.platform === 'win32' ? releaseNotes : releaseName,
        detail: 'A New Version has been Downloaded. Restart Now to Complete the Update.'
    }

    dialog.showMessageBox(dialogOpts).then((returnValue) => {
        if (returnValue.response === 0) autoUpdater.quitAndInstall()
    })
})

autoUpdater.on('error', message => {
    console.error('There was a problem updating the application')
    console.error(message)
})

希望大家能帮帮我

【问题讨论】:

  • 我可以理解,我花了几天时间让我的自动更新程序正常工作。您能否包括您的package.json 以及您打包应用程序的方式,例如electron-builderelectron-packager.
  • 我的 package.json 语法与您的不同。尝试删除repository.url 末尾的.git。还可以尝试将build.win.publish 更改为类似:"publish": {"provider": "github"} 的对象。此外,您似乎没有使用 electron-builder 发布您的版本,那么您如何在 Github 上发布版本?
  • 正在使用 npm run build -w 打包我们的应用程序,它执行“node .electron-vue/build.js && electron-builder”。并将其打包到一个 exe 中,然后我们将其发布到我链接的 repro 上。如果你是这个意思
  • 好的,如果我的package.json 语法建议不起作用,请尝试使用electron-builder-p 选项在Github 上发布二进制文件。这将自动在 Github 存储库上发布新版本。 See docs
  • 嗨@Meilech,我没有让它与榛树一起工作,如果这是一个错误配置问题,我只是没有工作。我切换到 github 版本进行更新,并在下面描述了我是如何让它工作的

标签: javascript windows vue.js electron electron-updater


【解决方案1】:

经过一番挣扎,我想通了。 原来我使用的 zeit.co 服务器没有发送 latest.yml。所以我们可以完全删除

const server = "https://hazel.scarvite.now.sh/"
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)

我开始使用 github。我们还必须将自动更新程序从电子(已弃用)更改为电子生成器的自动更新程序。我们是这样导入的:const { autoUpdater } = require("electron-updater"); 别忘了npm i electron-updater

在我的 Package.json 中,我更改了我的构建脚本,因此它可以作为草稿直接发布到 github。node .electron-vue/build.js && electron-builder -p always

我也必须添加

"repository": {
    "type": "git",
    "url": "https://github.com/ScarVite/Example-Repro/"
},
    "publish": {
    "provider": "github",
    "releaseType": "release"
},
"build": {
    "productName": "Your App Name",
    "appId": "com.example.yourapp",
    "directories": {
        "output": "build"
    },
    "files": [
        "dist/electron/**/*"
    ],
    "win": {
        "icon": "build/icons/icon.ico",
    "publish": [
            "github"
        ]
    },

我在 app.on('ready') 中调用了 autoUpdater.checkForUpdatesAndNotify(); 并设置了一个间隔,因此它每 10 分钟检查一次

然后在 autoupdater 事件 update-downloaded 中,我发送了一个对话框,询问用户是否要立即或稍后重新启动和更新应用程序。如果现在响应是我打电话给autoUpdater.quitAndInstall() 并重新启动。 Autoupdater 会在您下次关闭应用时自动更新

【讨论】:

    【解决方案2】:

    使用 electron-updater 模块

    const { autoUpdater } = require("electron-updater");
    
    /*checking for updates*/
    autoUpdater.on("checking-for-update", () => {
      //your code
    });
    
    /*No updates available*/
    autoUpdater.on("update-not-available", info => {
      //your code
    });
    
    /*New Update Available*/
    autoUpdater.on("update-available", info => {
      //your code
    });
    
    /*Download Status Report*/
    autoUpdater.on("download-progress", progressObj => {
     //your code
    });
    
    /*Download Completion Message*/
    autoUpdater.on("update-downloaded", info => {
     //your code
    });
    
    /*Checking updates just after app launch and also notify for the same*/
    app.on("ready", function() {
     autoUpdater.checkForUpdatesAndNotify();
    });
    

    【讨论】:

    • 还是不行。我上传了整个index.js。希望这会有所帮助
    • 我在 package.json "dist": "build --win" //for local build "ship": "build --win -p always" //to ship the build for auto update 的脚本对象中使用您是否检查了控制台日志以进行自动更新?我无法在 package.json Dev-dependecies electron-builder v20.31.0 Dependencies electron-updater v3.1.2 的依赖项对象中看到电子更新模块
    • 我在本地 package.json 中有 "electron-updater": "^4.2.0",我使用 node .electron-vue/build.js && electron-builder -p always -w 构建。
    【解决方案3】:

    Feed 网址好像有误

    const server = "https://hazel.scarvite.now.sh/"
    const feed = `${server}/update/${process.platform}/${app.getVersion()}` 
    

    输出:

    https://hazel.scarvite.now.sh//update/${process.platform}/${app.getVersion()}
    

    确保从提要网址中删除最后一个斜杠。

    【讨论】:

    • 已经尝试过了,它不能与我的 hazel 链接一起使用与我没有上传 latest.yml 和块图有关,并且 zeit.co 的服务存在问题,我昨天想出了答案跨度>
    猜你喜欢
    • 2018-08-27
    • 2023-03-20
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多