Skip to content

Commit

Permalink
Directly link to download url when new updates are found
Browse files Browse the repository at this point in the history
  • Loading branch information
yishn committed May 29, 2018
1 parent 77f6f88 commit 64a265c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ function checkForUpdates(showFailDialogs) {
message: `${app.getName()} v${info.latestVersion} is available now.`,
noLink: true,
cancelId: 1
}, response => response === 0 ? shell.openExternal(info.url) : null)
}, response => {
if (response === 0) {
shell.openExternal(info.downloadUrl || info.url)
}
})
} else if (showFailDialogs) {
dialog.showMessageBox({
type: 'info',
Expand Down
13 changes: 12 additions & 1 deletion src/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@ exports.check = async function(repo) {
})

let data = JSON.parse(response)
if (!('tag_name' in data)) throw new Error('No version information found.')
if (!('tag_name' in data) || !('assets' in data))
throw new Error('No version information found.')

let latestVersion = data.tag_name.slice(1).split('.').map(x => +x)
let currentVersion = app.getVersion().split('.').map(x => +x)
let downloadUrls = data.assets.map(x => x.browser_download_url)

let arch = os.arch()
let platform = ({
linux: 'linux',
win32: 'win',
darwin: 'mac'
})[os.platform()]

return {
url: `https://github.com/${repo}/releases/latest`,
downloadUrl: arch && platform
&& downloadUrls.find(x => x.includes(arch) && x.includes(platform)),
latestVersion: latestVersion.join('.'),
hasUpdates: lexicalCompare(latestVersion, currentVersion) > 0
}
Expand Down

0 comments on commit 64a265c

Please sign in to comment.