forked from ipfs/ipfs-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-gc.js
69 lines (58 loc) · 1.68 KB
/
run-gc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const i18n = require('i18next')
const { ipcMain } = require('electron')
const logger = require('./common/logger')
const { showDialog, recoverableErrorDialog } = require('./dialogs')
const dock = require('./utils/dock')
const ipcMainEvents = require('./utils/ipcMainEvents')
module.exports = function runGarbageCollector ({ getIpfsd }) {
dock.run(async () => {
logger.info('[run gc] alerting user for effects')
const opt = showDialog({
title: i18n.t('runGarbageCollectorWarning.title'),
message: i18n.t('runGarbageCollectorWarning.message'),
type: 'warning',
buttons: [
i18n.t('runGarbageCollectorWarning.action'),
i18n.t('cancel')
],
showDock: false
})
if (opt !== 0) {
logger.info('[run gc] user canceled')
return
}
const ipfsd = await getIpfsd()
if (!ipfsd) {
return
}
ipcMain.emit(ipcMainEvents.GC_RUNNING)
try {
const errors = []
for await (const res of ipfsd.api.repo.gc()) {
if (res instanceof Error) {
errors.push(res)
}
}
if (errors.length) {
throw errors
}
showDialog({
title: i18n.t('runGarbageCollectorDone.title'),
message: i18n.t('runGarbageCollectorDone.message'),
type: 'info',
buttons: [
i18n.t('ok')
],
showDock: false
})
logger.info('[run gc] success')
} catch (err) {
logger.error(`[run gc] ${err.stack}`)
recoverableErrorDialog(err, {
title: i18n.t('runGarbageCollectorErrored.title'),
message: i18n.t('runGarbageCollectorErrored.message')
})
}
ipcMain.emit(ipcMainEvents.GC_ENDED)
})
}