Skip to content

Commit c3051d8

Browse files
authored
fix(windows): autoInstallOnAppQuit (#1682)
1 parent 2d5794b commit c3051d8

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/auto-updater/index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ const i18n = require('i18next')
44
const logger = require('../common/logger')
55
const { notify } = require('../common/notify')
66
const { showDialog } = require('../dialogs')
7-
const quitAndInstall = require('./quit-and-install')
7+
const macQuitAndInstall = require('./macos-quit-and-install')
8+
const { IS_MAC } = require('../common/consts')
89

910
let feedback = false
1011

1112
function setup (ctx) {
13+
// we download manually in 'update-available'
1214
autoUpdater.autoDownload = false
13-
autoUpdater.autoInstallOnAppQuit = true
15+
16+
// mac requires manual upgrade, other platforms work out of the box
17+
autoUpdater.autoInstallOnAppQuit = !IS_MAC
1418

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

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

3640
try {
3741
await autoUpdater.downloadUpdate()
@@ -80,11 +84,15 @@ function setup (ctx) {
8084
})
8185

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

89+
const { autoInstallOnAppQuit } = autoUpdater
8590
const doIt = () => {
91+
// Do nothing if install is handled by upstream logic
92+
if (autoInstallOnAppQuit) return
93+
// Else, do custom install handling
8694
setImmediate(() => {
87-
quitAndInstall(ctx)
95+
if (IS_MAC) macQuitAndInstall(ctx)
8896
})
8997
}
9098

@@ -102,7 +110,7 @@ function setup (ctx) {
102110
message: i18n.t('updateDownloadedDialog.message', { version }),
103111
type: 'info',
104112
buttons: [
105-
i18n.t('updateDownloadedDialog.action')
113+
(autoInstallOnAppQuit ? i18n.t('ok') : i18n.t('updateDownloadedDialog.action'))
106114
]
107115
})
108116

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

121129
module.exports = async function (ctx) {
122130
if (process.env.NODE_ENV === 'development') {
123-
ctx.checkForUpdates = () => {
131+
ctx.manualCheckForUpdates = () => {
124132
showDialog({
125133
title: 'Not available in development',
126134
message: 'Yes, you called this function successfully.',
127135
buttons: [i18n.t('close')]
128136
})
129137
}
130-
131138
return
132139
}
133140

134141
setup(ctx)
135142

136-
await checkForUpdates()
143+
checkForUpdates() // background check
144+
137145
setInterval(checkForUpdates, 43200000) // every 12 hours
138146

139-
ctx.checkForUpdates = () => {
147+
ctx.manualCheckForUpdates = () => {
140148
feedback = true
141149
checkForUpdates()
142150
}

src/daemon/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,8 @@ module.exports = async function (ctx) {
109109

110110
ipcMain.on('ipfsConfigChanged', restartIpfs)
111111

112-
app.on('before-quit', async e => {
113-
if (ipfsd) {
114-
e.preventDefault()
115-
await stopIpfs()
116-
app.quit()
117-
}
112+
app.on('before-quit', async () => {
113+
if (ipfsd) await stopIpfs()
118114
})
119115

120116
await startIpfs()

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function run () {
6969
await setupWebUI(ctx) // ctx.webui, launchWebUI
7070
await setupTray(ctx) // ctx.tray
7171
await setupDaemon(ctx) // ctx.getIpfsd, startIpfs, stopIpfs, restartIpfs
72-
await setupAutoUpdater(ctx) // ctx.checkForUpdates
72+
await setupAutoUpdater(ctx) // ctx.manualCheckForUpdates
7373

7474
await Promise.all([
7575
setupArgvFilesHandler(ctx),

src/tray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function buildMenu (ctx) {
195195
{ type: 'separator' },
196196
{
197197
label: i18n.t('checkForUpdates'),
198-
click: () => { ctx.checkForUpdates() }
198+
click: () => { ctx.manualCheckForUpdates() }
199199
},
200200
{ type: 'separator' },
201201
{

0 commit comments

Comments
 (0)