Last active
December 16, 2018 06:34
-
-
Save rllola/62133a92476db5af867f4e4e2fbe0341 to your computer and use it in GitHub Desktop.
Electron updater code basic example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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