Skip to content

Commit

Permalink
fix(windows): autoInstallOnAppQuit
Browse files Browse the repository at this point in the history
autoInstallOnAppQuit works fine on windows, but we had a bunch of code
responsible for doing it manually due to macOS not being supported
natively by autoInstallOnAppQuit.

Due to this fix from
#1679 was not applied
correctly, and macOS-specific handling broke updates on windows.

This change ensures that macOS keeps using the old upgrade paths, but
Windows and AppImage leverage upstream code for applying upgrades.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Oct 8, 2020
1 parent b526407 commit 0544aff
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
28 changes: 18 additions & 10 deletions src/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ const i18n = require('i18next')
const logger = require('../common/logger')
const { notify } = require('../common/notify')
const { showDialog } = require('../dialogs')
const quitAndInstall = require('./quit-and-install')
const macQuitAndInstall = require('./macos-quit-and-install')
const macOS = process.platform === 'darwin'

let feedback = false

function setup (ctx) {
// we download manually in 'update-available'
autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = true

// mac requires manual upgrade, other platforms work out of the box
autoUpdater.autoInstallOnAppQuit = !macOS

autoUpdater.on('error', err => {
logger.error(`[updater] ${err.toString()}`)
Expand All @@ -31,7 +35,7 @@ function setup (ctx) {
})

autoUpdater.on('update-available', async ({ version, releaseNotes }) => {
logger.info('[updater] update available, download will start')
logger.info(`[updater] update to ${version} available, download will start`)

try {
await autoUpdater.downloadUpdate()
Expand Down Expand Up @@ -80,11 +84,15 @@ function setup (ctx) {
})

autoUpdater.on('update-downloaded', ({ version }) => {
logger.info('[updater] update downloaded')
logger.info(`[updater] update to ${version} downloaded`)

const { autoInstallOnAppQuit } = autoUpdater
const doIt = () => {
// Do nothing if install is handled by upstream logic
if (autoInstallOnAppQuit) return
// Else, do custom install handling
setImmediate(() => {
quitAndInstall(ctx)
if (macOS) macQuitAndInstall(ctx)
})
}

Expand All @@ -102,7 +110,7 @@ function setup (ctx) {
message: i18n.t('updateDownloadedDialog.message', { version }),
type: 'info',
buttons: [
i18n.t('updateDownloadedDialog.action')
(autoInstallOnAppQuit ? i18n.t('ok') : i18n.t('updateDownloadedDialog.action'))
]
})

Expand All @@ -120,23 +128,23 @@ async function checkForUpdates () {

module.exports = async function (ctx) {
if (process.env.NODE_ENV === 'development') {
ctx.checkForUpdates = () => {
ctx.manualCheckForUpdates = () => {
showDialog({
title: 'Not available in development',
message: 'Yes, you called this function successfully.',
buttons: [i18n.t('close')]
})
}

return
}

setup(ctx)

await checkForUpdates()
checkForUpdates() // background check

setInterval(checkForUpdates, 43200000) // every 12 hours

ctx.checkForUpdates = () => {
ctx.manualCheckForUpdates = () => {
feedback = true
checkForUpdates()
}
Expand Down
File renamed without changes.
8 changes: 2 additions & 6 deletions src/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,8 @@ module.exports = async function (ctx) {

ipcMain.on('ipfsConfigChanged', restartIpfs)

app.on('before-quit', async e => {
if (ipfsd) {
e.preventDefault()
await stopIpfs()
app.quit()
}
app.on('before-quit', async () => {
if (ipfsd) await stopIpfs()
})

await startIpfs()
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function run () {
await setupWebUI(ctx) // ctx.webui, launchWebUI
await setupTray(ctx) // ctx.tray
await setupDaemon(ctx) // ctx.getIpfsd, startIpfs, stopIpfs, restartIpfs
await setupAutoUpdater(ctx) // ctx.checkForUpdates
await setupAutoUpdater(ctx) // ctx.manualCheckForUpdates

await Promise.all([
setupArgvFilesHandler(ctx),
Expand Down
2 changes: 1 addition & 1 deletion src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function buildMenu (ctx) {
{ type: 'separator' },
{
label: i18n.t('checkForUpdates'),
click: () => { ctx.checkForUpdates() }
click: () => { ctx.manualCheckForUpdates() }
},
{ type: 'separator' },
{
Expand Down

0 comments on commit 0544aff

Please sign in to comment.