11import CrossProcessExports from "electron" ;
22import { app , session , powerMonitor } from "electron" ;
3+ import { ChildProcessWithoutNullStreams } from "child_process" ;
34import { initialize } from "@electron/remote/main/index.js" ;
45import state from "./server/state.js" ;
56import { electronApp , optimizer } from "@electron-toolkit/utils" ;
67import {
78 retrieveNativePHPConfig ,
89 retrievePhpIniSettings ,
910 runScheduler ,
11+ killScheduler ,
1012 startAPI ,
1113 startPhpApp ,
1214} from "./server/index.js" ;
@@ -21,9 +23,9 @@ import electronUpdater from 'electron-updater';
2123const { autoUpdater } = electronUpdater ;
2224
2325class NativePHP {
24- processes = [ ] ;
25- schedulerInterval = undefined ;
26+ processes : ChildProcessWithoutNullStreams [ ] = [ ] ;
2627 mainWindow = null ;
28+ schedulerInterval = undefined ;
2729
2830 public bootstrap (
2931 app : CrossProcessExports . App ,
@@ -244,12 +246,13 @@ class NativePHP {
244246 }
245247
246248
247- private stopScheduler ( ) {
248- if ( this . schedulerInterval ) {
249- clearInterval ( this . schedulerInterval ) ;
250- this . schedulerInterval = null ;
251- }
252- }
249+ private stopScheduler ( ) {
250+ if ( this . schedulerInterval ) {
251+ clearInterval ( this . schedulerInterval ) ;
252+ this . schedulerInterval = null ;
253+ }
254+ killScheduler ( ) ;
255+ }
253256
254257 private startScheduler ( ) {
255258 const now = new Date ( ) ;
@@ -270,16 +273,23 @@ class NativePHP {
270273 }
271274
272275 private killChildProcesses ( ) {
276+ this . stopScheduler ( ) ;
277+
273278 this . processes
274279 . filter ( ( p ) => p !== undefined )
275280 . forEach ( ( process ) => {
281+ if ( ! process || ! process . pid ) return ;
282+ if ( process . killed && process . exitCode !== null ) return ;
283+
276284 try {
277285 // @ts -ignore
278286 killSync ( process . pid , 'SIGTERM' , true ) ; // Kill tree
279287 ps . kill ( process . pid ) ; // Sometimes does not kill the subprocess of php server
288+
280289 } catch ( err ) {
281290 console . error ( err ) ;
282291 }
292+
283293 } ) ;
284294 }
285295}
0 commit comments