如何让我的电子自动更新程序工作?
How to get My Electron Auto updater to work?
当我在 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)
})
我希望你们能帮助我
使用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();
});
似乎提要 url 有误
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()}
确保从 Feed 中删除最后一个斜杠 url。
经过一番努力,我弄明白了。
原来我使用的 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"
]
},
我在 app.on('ready') 中调用了 autoUpdater.checkForUpdatesAndNotify();
并设置了一个时间间隔,因此它每 10 分钟检查一次
然后在 autoupdater 事件 update-downloaded 上,我发送了一个对话框,询问用户是否要立即或稍后重新启动并更新应用程序。如果现在响应是我调用 autoUpdater.quitAndInstall()
并重新启动。 Autoupdater 会在您下次关闭应用程序时自动更新
当我在 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)
})
我希望你们能帮助我
使用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();
});
似乎提要 url 有误
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()}
确保从 Feed 中删除最后一个斜杠 url。
经过一番努力,我弄明白了。 原来我使用的 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"
]
},
我在 app.on('ready') 中调用了 autoUpdater.checkForUpdatesAndNotify();
并设置了一个时间间隔,因此它每 10 分钟检查一次
然后在 autoupdater 事件 update-downloaded 上,我发送了一个对话框,询问用户是否要立即或稍后重新启动并更新应用程序。如果现在响应是我调用 autoUpdater.quitAndInstall()
并重新启动。 Autoupdater 会在您下次关闭应用程序时自动更新