Skip to content

Commit 36ff4e4

Browse files
author
Stuart Nelson
authored
feat: improve updating ux (#1758)
1 parent 0ff806a commit 36ff4e4

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

assets/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"ipfsIsNotRunning": "IPFS is Not Running",
66
"ipfsHasErrored": "IPFS has Errored",
77
"runningWithGC": "Running (GC in progress)",
8+
"runningWhileCheckingForUpdate": "Running (Checking for Updates)",
89
"start": "Start",
910
"stop": "Stop",
1011
"restart": "Restart",
@@ -28,6 +29,7 @@
2829
"clickToOpenLogs": "Click here to open the logs.",
2930
"ipfsNotRunning": "IPFS is not running",
3031
"checkForUpdates": "Check for Updates…",
32+
"checkingForUpdates": "Checking for Updates",
3133
"yes": "Yes",
3234
"no": "No",
3335
"close": "Close",

src/auto-updater/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { shell } = require('electron')
22
const { autoUpdater } = require('electron-updater')
33
const i18n = require('i18next')
4+
const { ipcMain } = require('electron')
45
const logger = require('../common/logger')
56
const { notify } = require('../common/notify')
67
const { showDialog } = require('../dialogs')
@@ -125,11 +126,13 @@ function setup (ctx) {
125126
}
126127

127128
async function checkForUpdates () {
129+
ipcMain.emit('updating')
128130
try {
129131
await autoUpdater.checkForUpdates()
130132
} catch (_) {
131133
// Ignore. The errors are already handled on 'error' event.
132134
}
135+
ipcMain.emit('updatingEnded')
133136
}
134137

135138
module.exports = async function (ctx) {

src/tray.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function buildMenu (ctx) {
5454
['ipfsIsStopping', 'yellow'],
5555
['ipfsIsNotRunning', 'gray'],
5656
['ipfsHasErrored', 'red'],
57-
['runningWithGC', 'yellow']
57+
['runningWithGC', 'yellow'],
58+
['runningWhileCheckingForUpdate', 'yellow']
5859
].map(([status, color]) => ({
5960
id: status,
6061
label: i18n.t(status),
@@ -203,9 +204,15 @@ function buildMenu (ctx) {
203204
},
204205
{ type: 'separator' },
205206
{
207+
id: 'checkForUpdates',
206208
label: i18n.t('checkForUpdates'),
207209
click: () => { ctx.manualCheckForUpdates() }
208210
},
211+
{
212+
id: 'checkingForUpdates',
213+
label: i18n.t('checkingForUpdates'),
214+
enabled: false
215+
},
209216
{ type: 'separator' },
210217
{
211218
label: i18n.t('viewOnGitHub'),
@@ -245,7 +252,8 @@ module.exports = function (ctx) {
245252

246253
const state = {
247254
status: null,
248-
gcRunning: false
255+
gcRunning: false,
256+
isUpdating: false
249257
}
250258

251259
// macOS tray drop files
@@ -276,15 +284,16 @@ module.exports = function (ctx) {
276284
}
277285

278286
const updateMenu = () => {
279-
const { status, gcRunning } = state
287+
const { status, gcRunning, isUpdating } = state
280288
const errored = status === STATUS.STARTING_FAILED || status === STATUS.STOPPING_FAILED
281289

282-
menu.getMenuItemById('ipfsIsStarting').visible = status === STATUS.STARTING_STARTED && !gcRunning
283-
menu.getMenuItemById('ipfsIsRunning').visible = status === STATUS.STARTING_FINISHED && !gcRunning
284-
menu.getMenuItemById('ipfsIsStopping').visible = status === STATUS.STOPPING_STARTED && !gcRunning
285-
menu.getMenuItemById('ipfsIsNotRunning').visible = status === STATUS.STOPPING_FINISHED && !gcRunning
286-
menu.getMenuItemById('ipfsHasErrored').visible = errored && !gcRunning
290+
menu.getMenuItemById('ipfsIsStarting').visible = status === STATUS.STARTING_STARTED && !gcRunning && !isUpdating
291+
menu.getMenuItemById('ipfsIsRunning').visible = status === STATUS.STARTING_FINISHED && !gcRunning && !isUpdating
292+
menu.getMenuItemById('ipfsIsStopping').visible = status === STATUS.STOPPING_STARTED && !gcRunning && !isUpdating
293+
menu.getMenuItemById('ipfsIsNotRunning').visible = status === STATUS.STOPPING_FINISHED && !gcRunning && !isUpdating
294+
menu.getMenuItemById('ipfsHasErrored').visible = errored && !gcRunning && !isUpdating
287295
menu.getMenuItemById('runningWithGC').visible = gcRunning
296+
menu.getMenuItemById('runningWhileCheckingForUpdate').visible = isUpdating
288297

289298
menu.getMenuItemById('startIpfs').visible = status === STATUS.STOPPING_FINISHED
290299
menu.getMenuItemById('stopIpfs').visible = status === STATUS.STARTING_FINISHED
@@ -309,6 +318,10 @@ module.exports = function (ctx) {
309318
menu.getMenuItemById('setCustomBinary').visible = !hasCustomBinary()
310319
menu.getMenuItemById('clearCustomBinary').visible = hasCustomBinary()
311320

321+
menu.getMenuItemById('checkForUpdates').enabled = !isUpdating
322+
menu.getMenuItemById('checkForUpdates').visible = !isUpdating
323+
menu.getMenuItemById('checkingForUpdates').visible = isUpdating
324+
312325
if (status === STATUS.STARTING_FINISHED) {
313326
tray.setImage(icon(on))
314327
} else {
@@ -342,6 +355,16 @@ module.exports = function (ctx) {
342355
updateMenu()
343356
})
344357

358+
ipcMain.on('updating', () => {
359+
state.isUpdating = true
360+
updateMenu()
361+
})
362+
363+
ipcMain.on('updatingEnded', () => {
364+
state.isUpdating = false
365+
updateMenu()
366+
})
367+
345368
ipcMain.on('configUpdated', () => { updateMenu() })
346369
ipcMain.on('languageUpdated', () => { setupMenu() })
347370

0 commit comments

Comments
 (0)