diff --git a/src/auto-updater/index.js b/src/auto-updater/index.js index f0a3b6f2e..729de1faf 100644 --- a/src/auto-updater/index.js +++ b/src/auto-updater/index.js @@ -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()}`) @@ -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() @@ -80,11 +84,14 @@ function setup (ctx) { }) autoUpdater.on('update-downloaded', ({ version }) => { - logger.info('[updater] update downloaded') + logger.info(`[updater] update to ${version} downloaded`) const doIt = () => { + // Do nothing if install is handled by upstream logic + if (autoUpdater.autoInstallOnAppQuit) return + // Else, do custom install handling setImmediate(() => { - quitAndInstall(ctx) + if (macOS) macQuitAndInstall(ctx) }) } @@ -102,7 +109,7 @@ function setup (ctx) { message: i18n.t('updateDownloadedDialog.message', { version }), type: 'info', buttons: [ - i18n.t('updateDownloadedDialog.action') + (macOS ? i18n.t('updateDownloadedDialog.action') : i18n.t('ok')) ] }) @@ -120,23 +127,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() } diff --git a/src/auto-updater/quit-and-install.js b/src/auto-updater/macos-quit-and-install.js similarity index 100% rename from src/auto-updater/quit-and-install.js rename to src/auto-updater/macos-quit-and-install.js diff --git a/src/daemon/index.js b/src/daemon/index.js index 649d9b3ee..63ac0899e 100644 --- a/src/daemon/index.js +++ b/src/daemon/index.js @@ -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() diff --git a/src/index.js b/src/index.js index 3e7a998b9..4695501e8 100644 --- a/src/index.js +++ b/src/index.js @@ -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), diff --git a/src/tray.js b/src/tray.js index e6b308247..b0ebb2ebd 100644 --- a/src/tray.js +++ b/src/tray.js @@ -195,7 +195,7 @@ function buildMenu (ctx) { { type: 'separator' }, { label: i18n.t('checkForUpdates'), - click: () => { ctx.checkForUpdates() } + click: () => { ctx.manualCheckForUpdates() } }, { type: 'separator' }, {