Skip to content

Commit 83053ba

Browse files
committed
feat: run gc
License: MIT Signed-off-by: Henrique Dias <[email protected]>
1 parent 5afb16c commit 83053ba

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

assets/locales/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"takeScreenshot": "Take Screenshot",
5050
"downloadHash": "Download Hash",
5151
"moveRepositoryLocation": "Move Repository Location",
52+
"runGarbageCollector": "Run Garbage Collector",
5253
"polkitDialog": {
5354
"title": "Polkit not found",
5455
"message": "IPFS can't be added to /usr/local/bin/ without polkit agent."
@@ -116,5 +117,14 @@
116117
"itemsFailedNotification": {
117118
"title": "Failed to add items",
118119
"message": "Could not add your items to your node."
120+
},
121+
"runGarbageCollectorWarning": {
122+
"title": "Garbage collector",
123+
"message": "Running the garbage collector will remove all the objects that are not pinned or on your MFS from your repository. This action might take a while. Do you want to run the Garbage Collector?",
124+
"action": "Run GC"
125+
},
126+
"runGarbageCollectorDone": {
127+
"title": "Garbage collector",
128+
"message": "Garbage collector run was successful."
119129
}
120130
}

src/run-gc.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import i18n from 'i18next'
2+
import logger from './common/logger'
3+
import { showDialog, recoverableErrorDialog } from './dialogs'
4+
import dock from './dock'
5+
6+
export default function runGarbageCollector ({ getIpfsd }) {
7+
dock.run(async () => {
8+
logger.info('[run gc] alerting user for effects')
9+
10+
const opt = showDialog({
11+
title: i18n.t('runGarbageCollectorWarning.title'),
12+
message: i18n.t('runGarbageCollectorWarning.message'),
13+
type: 'warning',
14+
buttons: [
15+
i18n.t('runGarbageCollectorWarning.action'),
16+
i18n.t('cancel')
17+
],
18+
showDock: false
19+
})
20+
21+
if (opt !== 0) {
22+
logger.info('[run gc] user canceled')
23+
return
24+
}
25+
26+
const ipfsd = await getIpfsd()
27+
28+
if (!ipfsd) {
29+
return
30+
}
31+
32+
try {
33+
ipfsd.api.repo.gc()
34+
showDialog({
35+
title: i18n.t('runGarbageCollectorDone.title'),
36+
message: i18n.t('runGarbageCollectorDone.message'),
37+
type: 'info',
38+
buttons: [
39+
i18n.t('ok')
40+
],
41+
showDock: false
42+
})
43+
} catch (err) {
44+
logger.error(`[run gc] ${err.toString()}`)
45+
return recoverableErrorDialog(err)
46+
}
47+
})
48+
}

src/tray.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import logger from './common/logger'
99
import store from './common/store'
1010
import { IS_MAC, IS_WIN, VERSION, GO_IPFS_VERSION } from './common/consts'
1111
import moveRepositoryLocation from './move-repository-location'
12+
import runGarbageCollector from './run-gc'
1213

1314
// Notes on this: we are only supporting accelerators on macOS for now because
1415
// they natively work as soon as the menu opens. They don't work like that on Windows
@@ -95,6 +96,12 @@ function buildMenu (ctx) {
9596
{
9697
label: i18n.t('moveRepositoryLocation'),
9798
click: () => { moveRepositoryLocation(ctx) }
99+
},
100+
{
101+
id: 'runGarbageCollector',
102+
label: i18n.t('runGarbageCollector'),
103+
click: () => { runGarbageCollector(ctx) },
104+
enabled: false
98105
}
99106
]
100107
},
@@ -193,6 +200,7 @@ export default function (ctx) {
193200

194201
menu.getMenuItemById('takeScreenshot').enabled = menu.getMenuItemById('ipfsIsRunning').visible
195202
menu.getMenuItemById('downloadHash').enabled = menu.getMenuItemById('ipfsIsRunning').visible
203+
menu.getMenuItemById('runGarbageCollector').enabled = menu.getMenuItemById('ipfsIsRunning').visible
196204

197205
if (status === STATUS.STARTING_FINISHED) {
198206
tray.setImage(icon(on))

0 commit comments

Comments
 (0)