@@ -13,7 +13,6 @@ import { app, BrowserWindow, dialog, ipcMain } from 'electron';
13
13
import installExtension , { REDUX_DEVTOOLS } from 'electron-devtools-installer' ;
14
14
import * as grpc from '@grpc/grpc-js' ;
15
15
import * as Sentry from '@sentry/electron' ;
16
- import * as child_process from 'child_process' ;
17
16
import log from 'electron-log' ;
18
17
import { autoUpdater } from 'electron-updater' ;
19
18
import { menubar } from 'menubar' ;
@@ -47,18 +46,16 @@ import {
47
46
} from './shared/constants' ;
48
47
import Helper from './trayMenu/helper' ;
49
48
import {
50
- ConfigClient ,
51
49
ConnectionStatusUpdate ,
52
50
ExportRequest ,
53
51
GetTagsRequest ,
54
52
ImportRequest ,
55
- ListenerClient ,
56
53
ListenerUpdateRequest ,
57
54
Record as ListenerRecord ,
58
55
Selector ,
59
56
StatusUpdatesRequest ,
60
57
} from './shared/pb/api' ;
61
- import { pomeriumCli } from './main/binaries ' ;
58
+ import { start } from './cli ' ;
62
59
63
60
const SentryDSN =
64
61
'https://[email protected] /6146413' ;
@@ -70,24 +67,6 @@ Sentry.init({
70
67
let mainWindow : BrowserWindow | null ;
71
68
let updateStream : grpc . ClientReadableStream < ConnectionStatusUpdate > | undefined ;
72
69
73
- const cliProcess = child_process
74
- . spawn ( pomeriumCli , [ 'api' , '--sentry-dsn' , SentryDSN ] )
75
- . on ( 'error' , ( error ) => {
76
- Sentry . captureEvent ( {
77
- message : 'API process failed to start' ,
78
- extra : { error } ,
79
- } ) ;
80
- } )
81
- . on ( 'close' , ( code , signal ) => {
82
- if ( signal != null ) return ;
83
- Sentry . captureEvent ( {
84
- message : 'API process unexpectedly quit' ,
85
- extra : { code } ,
86
- } ) ;
87
- } ) ;
88
-
89
- cliProcess . stderr . on ( 'data' , ( data ) => console . error ( data . toString ( ) ) ) ;
90
- cliProcess . stdout . on ( 'data' , ( data ) => console . info ( data . toString ( ) ) ) ;
91
70
class AppUpdater {
92
71
constructor ( ) {
93
72
log . transports . file . level = 'info' ;
@@ -105,16 +84,6 @@ if (isDev || prodDebug) {
105
84
require ( 'electron-debug' ) ( ) ;
106
85
}
107
86
108
- const configClient = new ConfigClient (
109
- '127.0.0.1:8800' ,
110
- grpc . ChannelCredentials . createInsecure ( )
111
- ) ;
112
-
113
- const listenerClient = new ListenerClient (
114
- '127.0.0.1:8800' ,
115
- grpc . ChannelCredentials . createInsecure ( )
116
- ) ;
117
-
118
87
const onUncaughtException = ( ( ) => {
119
88
let shuttingDown = false ;
120
89
return async ( err : Error ) => {
@@ -153,7 +122,14 @@ app.on('activate', async () => {
153
122
if ( mainWindow === null ) mainWindow = createWindow ( ) ;
154
123
} ) ;
155
124
156
- app . on ( 'ready' , async ( ) => {
125
+ async function init ( ) : Promise < void > {
126
+ const [ cli ] = await Promise . all ( [
127
+ start ( SentryDSN ) ,
128
+ new Promise ( ( resolve ) => app . on ( 'ready' , resolve ) ) ,
129
+ ] ) ;
130
+ const cliProcess = cli . process ;
131
+ const { configClient, listenerClient } = cli ;
132
+
157
133
// Remove this if your app does not use auto updates
158
134
// eslint-disable-next-line
159
135
new AppUpdater ( ) ;
@@ -368,4 +344,6 @@ app.on('ready', async () => {
368
344
mainWindow ?. close ( ) ;
369
345
} ) ;
370
346
} ) ;
371
- } ) ;
347
+ }
348
+
349
+ init ( ) ;
0 commit comments