javascriptwindowsvue.jselectronelectron-updater

How to get My Electron Auto updater to work?


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

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

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

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)
})

I am Hoping that you guys can help me


Solution

  • 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)
    

    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

    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.

    I also had to add

    "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"
            ]
        },
    

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

    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