-
Notifications
You must be signed in to change notification settings - Fork 865
/
index.js
103 lines (90 loc) · 3.02 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
91
92
93
94
95
96
97
98
99
100
101
102
103
// @ts-check
const { registerAppStartTime, getSecondsSinceAppStart } = require('./metrics/appStart')
registerAppStartTime()
require('v8-compile-cache')
const { app, dialog } = require('electron')
if (process.env.NODE_ENV === 'test') {
const path = require('path')
if (process.env.HOME) {
app.setPath('home', process.env.HOME)
app.setPath('userData', path.join(process.env.HOME, 'data'))
}
}
const getCtx = require('./context')
const fixPath = require('fix-path')
const logger = require('./common/logger')
const setupProtocolHandlers = require('./protocol-handlers')
const setupI18n = require('./i18n')
const setupDaemon = require('./daemon')
const setupWebUI = require('./webui')
const setupAutoLaunch = require('./auto-launch')
const setupAutoGc = require('./automatic-gc')
const setupPubsub = require('./enable-pubsub')
const setupNamesysPubsub = require('./enable-namesys-pubsub')
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 setupAnalytics = require('./analytics')
const setupSecondInstance = require('./second-instance')
const { analyticsKeys } = require('./analytics/keys')
const handleError = require('./handleError')
const createSplashScreen = require('./splash/create-splash-screen')
// 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)
}
app.on('will-finish-launching', () => {
setupProtocolHandlers()
})
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 Promise.all([
createSplashScreen(),
setupDaemon(), // ctx.getIpfsd, startIpfs, stopIpfs, restartIpfs
setupAnalytics(), // ctx.countlyDeviceId
setupI18n(),
setupAppMenu(),
setupWebUI(), // ctx.webui, launchWebUI
setupAutoUpdater(), // ctx.manualCheckForUpdates
setupTray(), // ctx.tray
setupArgvFilesHandler(),
setupAutoLaunch(),
setupAutoGc(),
setupPubsub(),
setupNamesysPubsub(),
setupSecondInstance(),
// Setup global shortcuts
setupTakeScreenshot()
])
const submitAppReady = () => {
logger.addAnalyticsEvent({ withAnalytics: analyticsKeys.APP_READY, dur: getSecondsSinceAppStart() })
}
const webui = await getCtx().getProp('webui')
if (webui.webContents.isLoading()) {
webui.webContents.once('dom-ready', submitAppReady)
} else {
submitAppReady()
}
} catch (e) {
const splash = await getCtx().getProp('splashScreen')
if (splash && !splash.isDestroyed()) splash.hide()
handleError(e)
}
}
run()