如何让 My Electron Auto 更新程序工作?

How to get My Electron Auto updater to work?(如何让 My Electron Auto 更新程序工作?)

本文介绍了如何让 My 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.

我正在使用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 更新程序工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何让 My Electron Auto 更新程序工作?

基础教程推荐