Skip to content

Instantly share code, notes, and snippets.

@ngudbhav
Last active May 5, 2019 19:50
Show Gist options
  • Save ngudbhav/7e9d429229fc78644c44d58f78dc5bda to your computer and use it in GitHub Desktop.
Save ngudbhav/7e9d429229fc78644c44d58f78dc5bda to your computer and use it in GitHub Desktop.
Electron app version check
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');
});
}
}
});
@ngudbhav
Copy link
Author

ngudbhav commented May 5, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment