Last active
May 5, 2019 19:50
-
-
Save ngudbhav/7e9d429229fc78644c44d58f78dc5bda to your computer and use it in GitHub Desktop.
Electron app version check
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
request('https://api.github.com/repos/ngudbhav/TriCo-electron-app/releases/latest', {headers: {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 '}}, function(error, html, body){ | |
if(!error){ | |
var v = app.getVersion().replace(' ', ''); | |
var latestV = JSON.parse(body).tag_name.replace('v', ''); | |
var changeLog = JSON.parse(body).body.replace('<strong>Changelog</strong>', 'Update available. Here are the changes:\n'); | |
if(latestV!=v){ | |
dialog.showMessageBox( | |
{ | |
type: 'info', | |
buttons:['Open Browser to download link', 'Close'], | |
title: 'Update Available', | |
detail: changeLog, | |
}, function(response){ | |
if(response === 0){ | |
shell.openExternal('https://github.com/ngudbhav/TriCo-electron-app/releases/latest'); | |
} | |
} | |
); | |
notifier.notify( | |
{ | |
title: 'Update Available', | |
message: 'A new version is available. Click to open browser and download.', | |
icon: 'images/logo.png', | |
sound: true, | |
wait:true | |
}); | |
notifier.on('click', function(notifierObject, options) { | |
shell.openExternal('https://github.com/ngudbhav/TriCo-electron-app/releases/latest'); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If one wants to check if a new release is available without any download, This way can be used. The script uses Github public repository release to get the tag number of the latest release. The tag number obtained is then matched with the current version. The changelog is obtained using the body property. This can be used to create some good outputs.