@@ -120,6 +120,7 @@ let serverProcess;
120
120
let serverPort = 7788 ;
121
121
let extensionRegistry = "ghcr.io" ;
122
122
let downloadTimeout = "1m" ;
123
+ let mainProcessLocation = "built-in" ;
123
124
124
125
// This method will be called when Electron has finished
125
126
// initialization and is ready to create browser windows.
@@ -156,6 +157,12 @@ app.whenReady().then(() => {
156
157
} )
157
158
ipcMain . handle ( 'getHomePage' , server . getHomePage )
158
159
ipcMain . handle ( 'getHealthzUrl' , server . getHealthzUrl )
160
+ ipcMain . handle ( 'getMainProcessLocation' , ( ) => {
161
+ return mainProcessLocation
162
+ } )
163
+ ipcMain . handle ( 'setMainProcessLocation' , ( e , location ) => {
164
+ mainProcessLocation = location
165
+ } )
159
166
160
167
startServer ( )
161
168
createWindow ( )
@@ -178,28 +185,21 @@ const startServer = () => {
178
185
recursive : true
179
186
} )
180
187
181
- // try to find the atest file first
182
- const serverFile = process . platform === "win32" ? "atest.exe" : "atest"
183
- const atestFromHome = path . join ( homeBin , serverFile )
184
- const atestFromPkg = path . join ( __dirname , serverFile )
185
-
186
- const data = fs . readFileSync ( atestFromPkg )
187
- log . info ( 'start to write file with length' , data . length )
188
-
189
- try {
190
- if ( process . platform === "win32" ) {
191
- const file = fs . openSync ( atestFromHome , 'w' ) ;
192
- fs . writeSync ( file , data , 0 , data . length , 0 ) ;
193
- fs . closeSync ( file ) ;
194
- } else {
195
- fs . writeFileSync ( atestFromHome , data ) ;
188
+ let atestBinPath
189
+ switch ( mainProcessLocation ) {
190
+ case "built-in" :
191
+ atestBinPath = locateBinPath ( )
192
+ break ;
193
+ case "system-path" :
194
+ const which = require ( 'which' ) ;
195
+ atestBinPath = process . platform === "win32" ? which . sync ( 'atest.exe' ) : which . sync ( 'atest' )
196
+ break ;
197
+ case "home-path" :
198
+ atestBinPath = locateBinPath ( false )
199
+ break ;
196
200
}
197
- } catch ( e ) {
198
- log . error ( 'Error Code:' , e . code ) ;
199
- }
200
- fs . chmodSync ( atestFromHome , 0o755 ) ;
201
201
202
- serverProcess = spawn ( atestFromHome , [
202
+ serverProcess = spawn ( atestBinPath , [
203
203
"server" ,
204
204
`--http-port=${ serverPort } ` ,
205
205
"--port=0" ,
@@ -223,6 +223,33 @@ const startServer = () => {
223
223
log . info ( serverProcess . spawnargs )
224
224
}
225
225
226
+ const locateBinPath = ( overwrite = true ) => {
227
+ // try to find the atest file first
228
+ const serverFile = process . platform === "win32" ? "atest.exe" : "atest"
229
+ const atestFromHome = path . join ( homeBin , serverFile )
230
+ if ( ! overwrite ) {
231
+ return atestFromHome
232
+ }
233
+
234
+ const atestFromPkg = path . join ( __dirname , serverFile )
235
+ const data = fs . readFileSync ( atestFromPkg )
236
+ log . info ( 'start to write file with length' , data . length )
237
+
238
+ try {
239
+ if ( process . platform === "win32" ) {
240
+ const file = fs . openSync ( atestFromHome , 'w' ) ;
241
+ fs . writeSync ( file , data , 0 , data . length , 0 ) ;
242
+ fs . closeSync ( file ) ;
243
+ } else {
244
+ fs . writeFileSync ( atestFromHome , data ) ;
245
+ }
246
+ } catch ( e ) {
247
+ log . error ( 'Error Code:' , e . code ) ;
248
+ }
249
+ fs . chmodSync ( atestFromHome , 0o755 ) ;
250
+ return atestFromHome
251
+ }
252
+
226
253
const stopServer = ( ) => {
227
254
if ( serverProcess ) {
228
255
serverProcess . kill ( )
0 commit comments