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

fix(windows): autoInstallOnAppQuit #1682

Merged
merged 2 commits into from
Oct 12, 2020
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
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 { IS_MAC } = require('../common/consts')

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 = !IS_MAC

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 (IS_MAC) 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
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()
Comment on lines -114 to -116
Copy link
Member Author

@lidel lidel Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what was the purpose of e.preventDefault(), but it seemed to interfere with autoInstallOnAppQuit on Windows

}
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