forked from ipfs/ipfs-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-ipfs-binary.js
93 lines (78 loc) · 2.12 KB
/
custom-ipfs-binary.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const i18n = require('i18next')
const { app, dialog } = require('electron')
const { showDialog } = require('./dialogs')
const logger = require('./common/logger')
const store = require('./common/store')
const dock = require('./utils/dock')
const SETTINGS_KEY = 'binaryPath'
async function setCustomBinary (ctx) {
await dock.run(async () => {
logger.info('[custom binary] request to change')
let opt = showDialog({
showDock: false,
title: i18n.t('setCustomIpfsBinaryConfirmation.title'),
message: i18n.t('setCustomIpfsBinaryConfirmation.message'),
type: 'warning',
buttons: [
i18n.t('yes'),
i18n.t('no')
]
})
if (opt !== 0) {
logger.info('[custom binary] user canceled')
return
}
const { canceled, filePaths } = await dialog.showOpenDialog({
title: i18n.t('pickCustomIpfsBinary'),
defaultPath: app.getPath('home'),
properties: ['openFile']
})
if (canceled || filePaths.length === 0) {
logger.info('[custom binary] user canceled')
return
}
store.set(SETTINGS_KEY, filePaths[0])
opt = showDialog({
showDock: false,
title: i18n.t('setCustomIpfsBinarySuccess.title'),
message: i18n.t('setCustomIpfsBinarySuccess.message', { path: filePaths[0] }),
buttons: [
i18n.t('restart'),
i18n.t('close')
]
})
logger.info(`[custom binary] updated to ${filePaths[0]}`)
if (opt === 0) {
ctx.restartIpfs()
}
})
}
function clearCustomBinary (ctx) {
store.delete(SETTINGS_KEY)
logger.info('[custom binary] cleared')
const opt = showDialog({
title: i18n.t('clearCustomIpfsBinarySuccess.title'),
message: i18n.t('clearCustomIpfsBinarySuccess.message'),
buttons: [
i18n.t('restart'),
i18n.t('close')
]
})
if (opt === 0) {
ctx.restartIpfs()
}
}
function hasCustomBinary () {
return typeof store.get(SETTINGS_KEY) === 'string'
}
function getCustomBinary () {
if (hasCustomBinary()) {
return store.get(SETTINGS_KEY)
}
}
module.exports = {
setCustomBinary,
clearCustomBinary,
hasCustomBinary,
getCustomBinary
}