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

feat(ux): improve gc #1420

Merged
merged 7 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 10 additions & 5 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"ipfsIsRunning": "IPFS is running",
"ipfsIsStopping": "IPFS is stopping",
"ipfsIsStarting": "IPFS is starting",
"ipfsIsNotRunning": "IPFS is not running",
"ipfsHasErrored": "IPFS has errored",
"ipfsIsRunning": "IPFS is Running",
"ipfsIsStopping": "IPFS is Stopping",
"ipfsIsStarting": "IPFS is Starting",
"ipfsIsNotRunning": "IPFS is Not Running",
"ipfsHasErrored": "IPFS has Errored",
"runningWithGC": "Running (Garbage Collecting)",
hacdias marked this conversation as resolved.
Show resolved Hide resolved
"start": "Start",
"stop": "Stop",
"restart": "Restart",
Expand Down Expand Up @@ -149,5 +150,9 @@
"cantAddIpfsToPath": {
"title": "IPFS on PATH",
"message": "Could not add IPFS to the PATH."
},
"runGarbageCollectorErrored": {
"title": "Garbage collector",
"message": "The garbage collector ran could not be completed successfully."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
}
}
15 changes: 12 additions & 3 deletions src/run-gc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const i18n = require('i18next')
const { ipcMain } = require('electron')
const logger = require('./common/logger')
const { showDialog, recoverableErrorDialog } = require('./dialogs')
const dock = require('./dock')
Expand Down Expand Up @@ -29,8 +30,10 @@ module.exports = function runGarbageCollector ({ getIpfsd }) {
return
}

ipcMain.emit('gcRunning')

try {
ipfsd.api.repo.gc()
await ipfsd.api.repo.gc()
showDialog({
title: i18n.t('runGarbageCollectorDone.title'),
message: i18n.t('runGarbageCollectorDone.message'),
Expand All @@ -40,9 +43,15 @@ module.exports = function runGarbageCollector ({ getIpfsd }) {
],
showDock: false
})
logger.info('[run gc] success')
} catch (err) {
logger.error(`[run gc] ${err.toString()}`)
return recoverableErrorDialog(err)
logger.error(`[run gc] ${err.stack}`)
recoverableErrorDialog(err, {
title: i18n.t('runGarbageCollectorErrored.title'),
message: i18n.t('runGarbageCollectorErrored.message')
})
}

ipcMain.emit('gcEnded')
})
}
69 changes: 49 additions & 20 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function buildMenu (ctx) {
['ipfsIsRunning', 'green'],
['ipfsIsStopping', 'yellow'],
['ipfsIsNotRunning', 'gray'],
['ipfsHasErrored', 'red']
['ipfsHasErrored', 'red'],
['runningWithGC', 'yellow']
].map(([status, color]) => ({
id: status,
label: i18n.t(status),
Expand Down Expand Up @@ -94,6 +95,7 @@ function buildMenu (ctx) {
click: () => { shell.openItem(store.path) }
},
{
id: 'moveRepositoryLocation',
label: i18n.t('moveRepositoryLocation'),
click: () => { moveRepositoryLocation(ctx) }
},
Expand Down Expand Up @@ -156,7 +158,11 @@ module.exports = function (ctx) {
logger.info('[tray] starting')
const tray = new Tray(icon(off))
let menu = null
let status = {}

const state = {
status: null,
gcRunning: false
}

// macOS tray drop files
tray.on('drop-files', async (_, files) => {
Expand All @@ -175,32 +181,40 @@ module.exports = function (ctx) {

const setupMenu = () => {
menu = buildMenu(ctx)

tray.setContextMenu(menu)
tray.setToolTip('IPFS Desktop')

menu.on('menu-will-show', () => { ipcMain.emit('menubar-will-open') })
menu.on('menu-will-close', () => { ipcMain.emit('menubar-will-close') })

updateStatus(status)
updateMenu()
}

const updateStatus = data => {
status = data
const updateMenu = () => {
const { status, gcRunning } = state
const errored = status === STATUS.STARTING_FAILED || status === STATUS.STOPPING_FAILED

menu.getMenuItemById('ipfsIsStarting').visible = status === STATUS.STARTING_STARTED && !gcRunning
menu.getMenuItemById('ipfsIsRunning').visible = status === STATUS.STARTING_FINISHED && !gcRunning
menu.getMenuItemById('ipfsIsStopping').visible = status === STATUS.STOPPING_STARTED && !gcRunning
menu.getMenuItemById('ipfsIsNotRunning').visible = status === STATUS.STOPPING_FINISHED && !gcRunning
menu.getMenuItemById('ipfsHasErrored').visible = errored && !gcRunning
menu.getMenuItemById('runningWithGC').visible = gcRunning

menu.getMenuItemById('ipfsIsStarting').visible = status === STATUS.STARTING_STARTED
menu.getMenuItemById('ipfsIsRunning').visible = status === STATUS.STARTING_FINISHED
menu.getMenuItemById('ipfsIsStopping').visible = status === STATUS.STOPPING_STARTED
menu.getMenuItemById('ipfsIsNotRunning').visible = status === STATUS.STOPPING_FINISHED
menu.getMenuItemById('ipfsHasErrored').visible = status === STATUS.STARTING_FAILED ||
status === STATUS.STOPPING_FAILED
menu.getMenuItemById('restartIpfs').visible = status === STATUS.STARTING_FINISHED ||
menu.getMenuItemById('ipfsHasErrored').visible
menu.getMenuItemById('startIpfs').visible = menu.getMenuItemById('ipfsIsNotRunning').visible
menu.getMenuItemById('stopIpfs').visible = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('startIpfs').visible = status === STATUS.STOPPING_FINISHED
menu.getMenuItemById('stopIpfs').visible = status === STATUS.STARTING_FINISHED
menu.getMenuItemById('restartIpfs').visible = (status === STATUS.STARTING_FINISHED || errored)

menu.getMenuItemById('takeScreenshot').enabled = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('downloadHash').enabled = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('runGarbageCollector').enabled = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('startIpfs').enabled = !gcRunning
menu.getMenuItemById('stopIpfs').enabled = !gcRunning
menu.getMenuItemById('restartIpfs').enabled = !gcRunning

menu.getMenuItemById('takeScreenshot').enabled = status === STATUS.STARTING_FINISHED
menu.getMenuItemById('downloadHash').enabled = status === STATUS.STARTING_FINISHED

menu.getMenuItemById('moveRepositoryLocation').enabled = !gcRunning && status !== STATUS.STOPPING_STARTED
menu.getMenuItemById('runGarbageCollector').enabled = menu.getMenuItemById('ipfsIsRunning').visible && !gcRunning

if (status === STATUS.STARTING_FINISHED) {
tray.setImage(icon(on))
Expand All @@ -215,8 +229,23 @@ module.exports = function (ctx) {
}
}

ipcMain.on('ipfsd', (status) => { updateStatus(status) })
ipcMain.on('languageUpdated', () => { setupMenu(status) })
ipcMain.on('ipfsd', status => {
state.status = status
updateMenu()
})

ipcMain.on('gcRunning', () => {
state.gcRunning = true
updateMenu()
})

ipcMain.on('gcEnded', () => {
state.gcRunning = false
updateMenu()
})

ipcMain.on('languageUpdated', () => { setupMenu() })

setupMenu()

ctx.tray = tray
Expand Down