当我在我的 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)
})
希望大家帮帮我
最佳答案
经过一番努力,我弄明白了。 原来我使用的 zeit.co 服务器没有发送 latest.yml。所以我们可以完全删除
const server = "https://hazel.scarvite.now.sh/"
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)
我开始使用 github。我们还必须将自动更新程序从 electron 更改为 electron-builder 的自动更新程序,因为它已被弃用。我们这样导入它: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"
]
},
我调用 autoUpdater.checkForUpdatesAndNotify();
在我的 app.on('ready') 中设置一个时间间隔,因此它每 10 分钟检查一次
然后在 autoupdater 事件 update-downloaded 上,我发送了一个对话框,询问用户是否要现在或以后重新启动并更新应用程序。如果响应是现在我调用autoUpdater.quitAndInstall()
它重新启动了。 Autoupdater 会在您下次自动关闭应用程序时更新
关于javascript - 如何让我的 Electron 自动更新程序工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59922073/