-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathelectron-app.js
70 lines (53 loc) · 1.69 KB
/
electron-app.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
const getPort = require('get-port')
const scale = () => {
try {
const { app } = require('electron')
return app.commandLine.appendSwitch('force-device-scale-factor', '1')
} catch (err) {
// Catch errors for when we're running outside of electron in development
return
}
}
const getRemoteDebuggingPort = () => {
try {
const { app } = require('electron')
return app.commandLine.getSwitchValue('remote-debugging-port')
} catch (err) {
// Catch errors for when we're running outside of electron in development
return
}
}
const setRemoteDebuggingPort = async () => {
try {
const { app } = require('electron')
// if port was already set via passing from environment variable ELECTRON_EXTRA_LAUNCH_ARGS,
// then just keep the supplied value
if (app.commandLine.getSwitchValue('remote-debugging-port')) {
return
}
const port = await getPort()
// set up remote debugging port
app.commandLine.appendSwitch('remote-debugging-port', String(port))
} catch (err) {
// Catch errors for when we're running outside of electron in development
return
}
}
const isRunning = () => {
// are we in the electron or the node process?
return Boolean(process.env.ELECTRON_RUN_AS_NODE || process.versions && process.versions.electron)
}
const isRunningAsElectronProcess = ({ debug } = {}) => {
const isElectronProcess = !process.env.ELECTRON_RUN_AS_NODE
if (!isElectronProcess && debug) {
debug('running as a node process without xvfp due to ELECTRON_RUN_AS_NODE env var')
}
return isElectronProcess
}
module.exports = {
scale,
getRemoteDebuggingPort,
setRemoteDebuggingPort,
isRunning,
isRunningAsElectronProcess,
}