Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for newer app version at start #33

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
})
})
}