如何使我的Electron Auto更新器正常工作? [英] How to get My Electron Auto updater to work?

查看:78
本文介绍了如何使我的Electron Auto更新器正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get my Electron Vue.js aplication to update itself when i release a new update in my Github Repro.

我正在使用电子生成器"打包我的应用程序,这是我的 package.json

I'm packing my app using "electron-builder" and here is my package.json

我正在遵循本指南,但是它没有用.

I was following this guide but it didn't work.

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

This is the Code for the updater part which is located at the top of the 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)
})

我希望你们能帮助我

推荐答案

我经过一番挣扎才弄清楚了.原来我使用的zeit.co服务器没有发送Latest.yml.这样我们就可以完全删除

I Figured it out after a bit of an struggle. Turns out the zeit.co server i was using wasn't sending the latest.yml. So We can completely remove

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 electronic-updater strong>

and i started working with github instead. We also had to change the autoupdater from electron, as it is deprecated, to electron-builder's autoupdater instead. We imported it like this: const { autoUpdater } = require("electron-updater"); Don't forget to npm i electron-updater

在我的Package.json中,我更改了构建脚本,因此它将作为草稿直接发布到github. node .electron-vue/build.js&&电子生成器-p始终.

In my Package.json i changed my build script so it would directly publish to github as a draft.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分钟检查一次

I called autoUpdater.checkForUpdatesAndNotify(); in my app.on('ready') and set a Timeout, so it checks every 10 minutes

然后,在下载并更新了autoupdater事件时,我发送了一个对话框,询问用户是否要现在或以后重新启动和更新应用程序.如果现在响应是我叫 autoUpdater.quitAndInstall(),它会重新启动.自动更新程序会在您下次自动关闭应用程序时更新

Then on the autoupdater event update-downloaded i sent a dialog asking the user if they want to restart and update the app now or later. If the response was now i called autoUpdater.quitAndInstall() and it restarted. the Autoupdater updates the next time you close the app automatically

这篇关于如何使我的Electron Auto更新器正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆