Detect the actual operating system CPU architecture. This is different than `process.arch` which returns the architecture the binary was compiled for. This is just good info to have in the telemetry, but we're also sending it in the update check so that eventually we can upgrade Windows 32-bit apps to 64-bit, like Slack does. Context: https://github.com/feross/webtorrent-desktop/issues/873#issuecomment-247 722023
78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
module.exports = {
|
|
init
|
|
}
|
|
|
|
const electron = require('electron')
|
|
const get = require('simple-get')
|
|
|
|
const config = require('../config')
|
|
const log = require('./log')
|
|
const windows = require('./windows')
|
|
|
|
const AUTO_UPDATE_URL = config.AUTO_UPDATE_URL +
|
|
'?version=' + config.APP_VERSION +
|
|
'&platform=' + process.platform +
|
|
'&sysarch=' + config.OS_SYSARCH
|
|
|
|
function init () {
|
|
if (process.platform === 'linux') {
|
|
initLinux()
|
|
} else {
|
|
initDarwinWin32()
|
|
}
|
|
}
|
|
|
|
// The Electron auto-updater does not support Linux yet, so manually check for
|
|
// updates and show the user a modal notification.
|
|
function initLinux () {
|
|
get.concat(AUTO_UPDATE_URL, onResponse)
|
|
}
|
|
|
|
function onResponse (err, res, data) {
|
|
if (err) return log(`Update error: ${err.message}`)
|
|
if (res.statusCode === 200) {
|
|
// Update available
|
|
try {
|
|
data = JSON.parse(data)
|
|
} catch (err) {
|
|
return log(`Update error: Invalid JSON response: ${err.message}`)
|
|
}
|
|
windows.main.dispatch('updateAvailable', data.version)
|
|
} else if (res.statusCode === 204) {
|
|
// No update available
|
|
} else {
|
|
// Unexpected status code
|
|
log(`Update error: Unexpected status code: ${res.statusCode}`)
|
|
}
|
|
}
|
|
|
|
function initDarwinWin32 () {
|
|
electron.autoUpdater.on(
|
|
'error',
|
|
(err) => log.error(`Update error: ${err.message}`)
|
|
)
|
|
|
|
electron.autoUpdater.on(
|
|
'checking-for-update',
|
|
() => log('Checking for update')
|
|
)
|
|
|
|
electron.autoUpdater.on(
|
|
'update-available',
|
|
() => log('Update available')
|
|
)
|
|
|
|
electron.autoUpdater.on(
|
|
'update-not-available',
|
|
() => log('No update available')
|
|
)
|
|
|
|
electron.autoUpdater.on(
|
|
'update-downloaded',
|
|
(e, notes, name, date, url) => log(`Update downloaded: ${name}: ${url}`)
|
|
)
|
|
|
|
electron.autoUpdater.setFeedURL(AUTO_UPDATE_URL)
|
|
electron.autoUpdater.checkForUpdates()
|
|
}
|