2

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

ScarVite
  • 327
  • 1
  • 5
  • 19
  • I can relate, I've spent days getting my auto updater working. Can you include your `package.json` and the way you package your app e.g. `electron-builder` or `electron-packager`. – Joshua Jan 26 '20 at 23:19
  • My `package.json` syntax is different to yours. Try removing the `.git` at the end of `repository.url`. Also try changing `build.win.publish` to an object like: `"publish": {"provider": "github"}`. Also it doesn't seem like you're using `electron-builder` to publish your releases, so how do you publish a release on Github? – Joshua Jan 27 '20 at 23:20
  • Were packing our app with the npm run build -w, which executes "node [.electron-vue/build.js](https://gist.github.com/ScarVite/7b193a94ac8c169ac875e1671874183c) && electron-builder". and it packs it to an exe which we then release it on the repro i linked. if you mean that – ScarVite Jan 28 '20 at 00:09
  • Okay, if my `package.json` syntax suggestions don't work, try releasing the binary on Github with `electron-builder`'s `-p` option. That'll automatically publish the new release on the Github repo. [See docs](https://www.electron.build/configuration/publish#how-to-publish) – Joshua Jan 28 '20 at 00:12
  • do you mean like that : "npm run build -w -p". Updated my [package.json](https://gist.github.com/ScarVite/ba1cbd2e9e9ee5b9d5652d9f8ab33ade) btw – ScarVite Jan 28 '20 at 00:18
  • i just noticed another problem: the url "https://hazel.scarvite.now.sh/" doesnt event get pinged by the package app, only by the unpackaged one – ScarVite Jan 28 '20 at 00:19
  • What I mean by the `-p` option is to add ` -p always` to the end of your `electron-builder` script in your `package.json`. So it'd be something like: `"releaseWin": "electron-builder --ia32 -p always"`. [See publishing options](https://www.electron.build/configuration/publish#how-to-publish). – Joshua Jan 28 '20 at 00:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206755/discussion-between-joshua-and-scarvite). – Joshua Jan 28 '20 at 01:14
  • hi @ScarVite, can you share your package.json (at least the properties required for this question it would be very helpful for me to get hazel to working. When clicking on the link it says 404 – Meir Sep 14 '21 at 16:14
  • 1
    hi @Meilech, i did not get it to work with hazel, idk if it was a misconfiguration problem, but i just simply did not work. I switched over to github releases for updating and described how i got it to work below – ScarVite Sep 16 '21 at 12:50

3 Answers3

3

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

ScarVite
  • 327
  • 1
  • 5
  • 19
  • Hi, I'm able to update my electron app using the above approach but when I go back and open up the electron app, the auto-update pop-up notifies me again... Any suggestions? – santosh kumar Jul 20 '22 at 05:24
2

Use electron-updater module

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();
});
aniyd
  • 31
  • 1
  • 4
  • still doesn't work. i Uploaded the entire [index.js](https://gist.github.com/ScarVite/54a46d4b145ceb7bc5752ed79efa3917). hope this helps – ScarVite Jan 29 '20 at 13:48
  • I am using in script object of package.json `"dist": "build --win" //for local build "ship": "build --win -p always" //to ship the build for auto update` did you check the console log for auto-update? i am not able to see the electron-updater module in dependencies object of package.json `Dev-dependecies electron-builder v20.31.0 Dependencies electron-updater v3.1.2` – aniyd Jan 30 '20 at 08:03
  • i have `"electron-updater": "^4.2.0"`in my local package.json and im using `node .electron-vue/build.js && electron-builder -p always -w` to build. – ScarVite Jan 30 '20 at 14:00
1

It looks like the feed url is wrong

const server = "https://hazel.scarvite.now.sh/"
const feed = `${server}/update/${process.platform}/${app.getVersion()}` 

output:

https://hazel.scarvite.now.sh//update/${process.platform}/${app.getVersion()}

Make sure you remove the last slash from the feed url.

Zakthedev
  • 347
  • 4
  • 7
  • already tried it, it not working with my hazel link had to do with me not upload latest.yml and the blockmap and there is an issue with zeit.co's service i figured the answer out yesterday – ScarVite Feb 26 '20 at 19:49