Skip to content

Instantly share code, notes, and snippets.

@rllola
Last active December 16, 2018 06:34
Show Gist options
  • Save rllola/62133a92476db5af867f4e4e2fbe0341 to your computer and use it in GitHub Desktop.
Save rllola/62133a92476db5af867f4e4e2fbe0341 to your computer and use it in GitHub Desktop.
Electron updater code basic example
const electron = require('electron')
const APP_VERSION = require('../package.json').version
const AUTO_UPDATE_URL = 'https://api.update.rocks/github.com/rllola/electron-example/update/' + process.platform + '/' + APP_VERSION
function init () {
if (process.platform === 'linux') {
console.log('Auto updates not available on linux')
} else {
initDarwinWin32()
}
}
function initDarwinWin32 () {
electron.autoUpdater.on(
'error',
(err) => console.error(`Update error: ${err.message}`))
electron.autoUpdater.on(
'checking-for-update',
() => console.log('Checking for update'))
electron.autoUpdater.on(
'update-available',
() => console.log('Update available'))
electron.autoUpdater.on(
'update-not-available',
() => console.log('No update available'))
// Ask the user if update is available
electron.autoUpdater.on(
'update-downloaded',
(event, releaseNotes, releaseName) => {
dialog.showMessageBox(window, {
type: 'question',
buttons: ['Update', 'Cancel'],
defaultId: 0,
message: `Version ${releaseName} is available, do you want to install it now?`,
title: 'Update available'
}, response => {
if (response === 0) {
electron.autoUpdater.quitAndInstall()
}
})
}
)
electron.autoUpdater.setFeedURL(AUTO_UPDATE_URL)
electron.autoUpdater.checkForUpdates()
}
module.exports = {
init
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment