|
|
@ -1,5 +1,6 @@ |
|
|
|
// Modules to control application life and create native browser window
|
|
|
|
const { app, BrowserWindow } = require('electron') |
|
|
|
const { exec } = require('child_process'); |
|
|
|
const path = require('node:path') |
|
|
|
|
|
|
|
function createWindow () { |
|
|
@ -45,5 +46,30 @@ app.on('window-all-closed', function () { |
|
|
|
if (process.platform !== 'darwin') app.quit() |
|
|
|
}) |
|
|
|
|
|
|
|
app.on('before-quit', () => { |
|
|
|
getJavaProcessIdByPort(30523); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getJavaProcessIdByPort(port) { |
|
|
|
let pid = null; |
|
|
|
exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => { |
|
|
|
// 查找stdout中匹配端口的行,并提取PID
|
|
|
|
if (stdout) { |
|
|
|
const lines = stdout.trim().split('\r\n'); |
|
|
|
for (const line of lines) { |
|
|
|
const pidMatch = line.match(/LISTENING\s+(\d+)/);; |
|
|
|
if (pidMatch) { |
|
|
|
pid = pidMatch[1]; |
|
|
|
require('child_process').execSync(`taskkill /PID ${pid} -t -f`); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// In this file you can include the rest of your app's specific main process
|
|
|
|
// code. You can also put them in separate files and require them here.
|