問題描述
當我在我的 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.
我正在使用electron-builder"打包我的應用程序.這是我的 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 electron-updater
強>
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 &&electron-builder -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 intervall, so it checks every 10 minutes
然后在 autoupdater 事件 update-downloaded 中,我發送了一個對話框,詢問用戶是否要立即或稍后重新啟動和更新應用程序.如果響應是現在我調用 autoUpdater.quitAndInstall()
并重新啟動.Autoupdater 會在您下次關閉應用時自動更新
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
這篇關于如何讓 My Electron Auto 更新程序工作?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!