Skip to content

Commit

Permalink
Merge pull request #33 from flbraun/check-for-updates
Browse files Browse the repository at this point in the history
Check for newer app version at start
  • Loading branch information
flbraun committed Nov 19, 2023
2 parents deca059 + 3f92e28 commit 90d18dc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"stylelint-config-standard": "^34.0.0"
},
"dependencies": {
"electron-store": "^8.1.0"
"electron-store": "^8.1.0",
"semver": "^7.5.4"
}
}
6 changes: 6 additions & 0 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ const { app, BrowserWindow, ipcMain, shell, globalShortcut, dialog } = require('
const path = require('node:path')
const tray = require('./tray')
const { userSettings } = require('./storage')
const { checkForUpdates } = require('./update')

app.commandLine.appendSwitch('wm-window-animations-disabled')

// check for updates in background
if (app.isPackaged) {
checkForUpdates()
}

const createWindow = (width, height) => {
const win = new BrowserWindow({
width: width,
Expand Down
45 changes: 45 additions & 0 deletions src/main/update.js
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()
}
}
})
})
}

0 comments on commit 90d18dc

Please sign in to comment.