-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from flbraun/check-for-updates
Check for newer app version at start
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { app, dialog, shell } = require('electron') | ||
const semver = require('semver') | ||
const https = require('https') | ||
|
||
exports.checkForUpdates = () => { | ||
const currentVersion = app.getVersion() | ||
|
||
const reqOptions = { | ||
protocol: 'https:', | ||
host: 'api.github.com', | ||
path: '/repos/flbraun/poe-palette/releases/latest', | ||
headers: { | ||
'User-Agent': 'flbraun/poe-palette', | ||
}, | ||
} | ||
|
||
https.get(reqOptions, (resp) => { | ||
let data = '' | ||
|
||
resp.on('data', (chunk) => { | ||
data += chunk | ||
}) | ||
|
||
resp.on('end', () => { | ||
const respData = JSON.parse(data) | ||
const latestVersion = respData.tag_name | ||
const releasePage = respData.html_url | ||
|
||
if (semver.lt(semver.coerce(currentVersion), semver.coerce(latestVersion))) { | ||
let buttonClicked = dialog.showMessageBoxSync(null, { | ||
type: 'info', | ||
title: 'Update available!', | ||
message: 'A new version of PoE Palette is available!', | ||
detail: `${latestVersion} is available, you're running ${currentVersion}.\nOpen download page?`, | ||
buttons: ['Yes', 'No'], | ||
}) | ||
|
||
if (buttonClicked === 0) { // 0 is index of 'Yes' button | ||
shell.openExternal(releasePage) | ||
app.quit() | ||
} | ||
} | ||
}) | ||
}) | ||
} |