forked from ipfs/ipfs-desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
90 lines (76 loc) · 2.39 KB
/
index.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
require('v8-compile-cache')
const { app, dialog } = require('electron')
const fixPath = require('fix-path')
const { criticalErrorDialog } = require('./dialogs')
const logger = require('./common/logger')
const setupProtocolHandlers = require('./protocol-handlers')
const setupI18n = require('./i18n')
const setupNpmOnIpfs = require('./npm-on-ipfs')
const setupDaemon = require('./daemon')
const setupWebUI = require('./webui')
const setupAutoLaunch = require('./auto-launch')
const setupDownloadCid = require('./download-cid')
const setupTakeScreenshot = require('./take-screenshot')
const setupAppMenu = require('./app-menu')
const setupArgvFilesHandler = require('./argv-files-handler')
const setupAutoUpdater = require('./auto-updater')
const setupTray = require('./tray')
const setupIpfsOnPath = require('./ipfs-on-path')
const setupAnalytics = require('./analytics')
const setupSecondInstance = require('./second-instance')
// Hide Dock
if (app.dock) app.dock.hide()
// Sets User Model Id so notifications work on Windows 10
app.setAppUserModelId('io.ipfs.desktop')
// Fixes $PATH on macOS
fixPath()
// Only one instance can run at a time
if (!app.requestSingleInstanceLock()) {
process.exit(0)
}
const ctx = {}
app.on('will-finish-launching', () => {
setupProtocolHandlers(ctx)
})
function handleError (err) {
// Ignore network errors that might happen during the
// execution.
if (err.stack.includes('net::')) {
return
}
logger.error(err)
criticalErrorDialog(err)
}
process.on('uncaughtException', handleError)
process.on('unhandledRejection', handleError)
async function run () {
try {
await app.whenReady()
} catch (e) {
dialog.showErrorBox('Electron could not start', e.stack)
app.exit(1)
}
try {
await setupAnalytics(ctx) // ctx.countlyDeviceId
await setupI18n(ctx)
await setupAppMenu(ctx)
await setupWebUI(ctx) // ctx.webui, launchWebUI
await setupTray(ctx) // ctx.tray
await setupDaemon(ctx) // ctx.getIpfsd, startIpfs, stopIpfs, restartIpfs
await setupAutoUpdater(ctx) // ctx.checkForUpdates
await Promise.all([
setupArgvFilesHandler(ctx),
setupAutoLaunch(ctx),
setupSecondInstance(ctx),
// Setup global shortcuts
setupDownloadCid(ctx),
setupTakeScreenshot(ctx),
// Setup PATH-related features
setupNpmOnIpfs(ctx),
setupIpfsOnPath(ctx)
])
} catch (e) {
handleError(e)
}
}
run()