-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
64 lines (49 loc) · 1.64 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
// Karma Edge Launcher
// =================
// Dependencies
// ------------
var path = require('path')
var spawn = require('child_process').spawn
var escapeRegex = /\\/g
var escapement = '\\\\'
var startScriptPath = path.join(__dirname, 'scripts/start_edge.ps1').replace(escapeRegex, escapement)
var stopScriptPath = path.join(__dirname, 'scripts/stop_edge.ps1').replace(escapeRegex, escapement)
// Constructor
function EdgeBrowser (baseBrowserDecorator) {
baseBrowserDecorator(this)
var self = this
// Use start_edge script path as powershell argument, and url as script argument
this._getOptions = function (url) {
return [ startScriptPath, url ]
}
// Override onProcessExit to manage edge shutdown
var baseOnProcessExit = this._onProcessExit
this._onProcessExit = function (code, errorOutput) {
// In case of error return immediatly
if (code > 0 || errorOutput.length > 0) {
baseOnProcessExit(code, errorOutput)
} else {
// Start stop process to close edge gracefully
var stopProcess = spawn(self.DEFAULT_CMD.win32, [ stopScriptPath ])
stopProcess.stdout.on('data', self._onStdout)
stopProcess.stderr.on('data', self._onStderr)
stopProcess.on('error', self._onStderr)
stopProcess.on('exit', function (code) {
baseOnProcessExit(code, errorOutput)
})
}
}
}
EdgeBrowser.prototype = {
name: 'Edge',
DEFAULT_CMD: {
win32: 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
},
ENV_CMD: 'EDGE_BIN'
}
EdgeBrowser.$inject = ['baseBrowserDecorator']
// Publish di module
// -----------------
module.exports = {
'launcher:Edge': ['type', EdgeBrowser]
}