1
1
const DEV_MODE = process . env . HTK_DEV === 'true' ;
2
2
3
- import * as Sentry from '@sentry/electron' ;
4
- import { RewriteFrames } from '@sentry/integrations' ;
5
-
6
- if ( ! DEV_MODE ) {
7
- Sentry . init ( {
8
- dsn : 'https://1194b128453942ed9470d49a74c35992@o202389.ingest.sentry.io/1367048' ,
9
- integrations : [
10
- new RewriteFrames ( {
11
- // Make all paths relative to this root, because otherwise it can make
12
- // errors unnecessarily distinct, especially on Windows.
13
- root : process . platform === 'win32'
14
- // Root must always be POSIX format, so we transform it on Windows:
15
- ? __dirname
16
- . replace ( / ^ [ A - Z ] : / , '' ) // remove Windows-style prefix
17
- . replace ( / \\ / g, '/' ) // replace all `\\` instances with `/`
18
- : __dirname
19
- } )
20
- ]
21
- } ) ;
22
- }
23
-
24
- function reportError ( error : Error | string ) {
25
- console . log ( error ) ;
3
+ // Set up error handling before everything else:
4
+ import { reportError , addBreadcrumb } from './errors' ;
26
5
27
- if ( typeof error === 'string' ) {
28
- Sentry . captureMessage ( error ) ;
29
- } else {
30
- Sentry . captureException ( error ) ;
31
- }
32
- }
33
-
34
- import { spawn , exec , ChildProcess } from 'child_process' ;
6
+ import { spawn , ChildProcess } from 'child_process' ;
35
7
import * as os from 'os' ;
36
8
import { promises as fs } from 'fs'
37
9
import * as net from 'net' ;
@@ -44,6 +16,7 @@ import * as uuid from 'uuid/v4';
44
16
import * as yargs from 'yargs' ;
45
17
import * as semver from 'semver' ;
46
18
import * as rimraf from 'rimraf' ;
19
+ const rmRF = promisify ( rimraf ) ;
47
20
import * as windowStateKeeper from 'electron-window-state' ;
48
21
import { getSystemProxy } from 'os-proxy-config' ;
49
22
@@ -55,8 +28,7 @@ registerContextMenu({
55
28
import { reportStartupEvents } from './report-install-event' ;
56
29
import { getMenu , shouldAutoHideMenu } from './menu' ;
57
30
import { getDeferred , delay } from './util' ;
58
-
59
- const rmRF = promisify ( rimraf ) ;
31
+ import { stopServer } from './stop-server' ;
60
32
61
33
const packageJson = require ( '../package.json' ) ;
62
34
@@ -166,34 +138,21 @@ if (!amMainInstance) {
166
138
}
167
139
168
140
let serverKilled = false ;
169
- app . on ( 'will-quit' , ( event ) => {
141
+ app . on ( 'will-quit' , async ( event ) => {
170
142
if ( server && ! serverKilled ) {
143
+ // Don't shutdown until we've tried to kill the server
144
+ event . preventDefault ( ) ;
145
+
171
146
serverKilled = true ;
147
+
172
148
try {
173
- if ( isWindows ) {
174
- // Don't shutdown until we've tried to kill the server
175
- event . preventDefault ( ) ;
176
-
177
- // Forcefully kill the pid (the cmd) and child processes
178
- exec ( `taskkill /pid ${ server . pid } /T /F` , ( error , stdout , stderr ) => {
179
- if ( error ) {
180
- console . log ( stdout ) ;
181
- console . log ( stderr ) ;
182
- reportError ( error ) ;
183
- }
184
-
185
- // We've done our best - now shut down for real. Disable errors, otherwise
186
- // we can receive reports for invisible errors during/just after exit.
187
- app . quit ( ) ;
188
- } ) ;
189
- } else {
190
- // Make sure we clean up the whole group (shell + node).
191
- // https://azimi.me/2014/12/31/kill-child_process-node-js.html
192
- process . kill ( - server . pid ! ) ;
193
- }
149
+ await stopServer ( server , AUTH_TOKEN ) ;
150
+ // We've done our best - now shut down for real.
151
+ app . quit ( ) ;
194
152
} catch ( error ) {
195
153
console . log ( 'Failed to kill server' , error ) ;
196
154
reportError ( error ) ;
155
+ app . quit ( ) ;
197
156
}
198
157
}
199
158
} ) ;
@@ -398,13 +357,13 @@ if (!amMainInstance) {
398
357
stderr . pipe ( process . stderr ) ;
399
358
400
359
server . stdout ! . on ( 'data' , ( data ) => {
401
- Sentry . addBreadcrumb ( { category : 'server-stdout' , message : data . toString ( 'utf8' ) , level : < any > 'info' } ) ;
360
+ addBreadcrumb ( { category : 'server-stdout' , message : data . toString ( 'utf8' ) , level : < any > 'info' } ) ;
402
361
} ) ;
403
362
404
363
let lastError : string | undefined = undefined ;
405
364
stderr . on ( 'data' , ( data ) => {
406
365
const errorOutput = data . toString ( 'utf8' ) ;
407
- Sentry . addBreadcrumb ( { category : 'server-stderr' , message : errorOutput , level : < any > 'warning' } ) ;
366
+ addBreadcrumb ( { category : 'server-stderr' , message : errorOutput , level : < any > 'warning' } ) ;
408
367
409
368
// Remember the last '*Error:' line we saw.
410
369
lastError = errorOutput
@@ -434,7 +393,7 @@ if (!amMainInstance) {
434
393
error = new Error ( `Server shutdown unexpectedly with code ${ errorOrCode } ` ) ;
435
394
}
436
395
437
- Sentry . addBreadcrumb ( { category : 'server-exit' , message : error . message , level : < any > 'error' , data : { serverRunTime } } ) ;
396
+ addBreadcrumb ( { category : 'server-exit' , message : error . message , level : < any > 'error' , data : { serverRunTime } } ) ;
438
397
reportError ( error ) ;
439
398
440
399
showErrorAlert (
@@ -480,7 +439,8 @@ if (!amMainInstance) {
480
439
} ) ;
481
440
482
441
// Check we're happy using the default proxy settings
483
- getSystemProxy ( ) . then ( ( proxyConfig ) => {
442
+ getSystemProxy ( )
443
+ . then ( ( proxyConfig ) => {
484
444
let shouldDisableProxy = false ;
485
445
486
446
if ( proxyConfig ) {
0 commit comments