From 5ab71e4b5ef0c8e082b9f4649d450d57628e0fd3 Mon Sep 17 00:00:00 2001 From: "583641232@qq.com" <583641232@qq.com> Date: Sat, 6 Jul 2024 13:18:52 +0800 Subject: [PATCH] :sparkles: go --- main.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index ed0908c..ecb0247 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,7 @@ function createWindow () { // Open the DevTools. - mainWindow.webContents.openDevTools() + //mainWindow.webContents.openDevTools() } // This method will be called when Electron has finished @@ -47,13 +47,7 @@ app.on('window-all-closed', function () { }) app.on('before-quit', () => { - getJavaProcessIdByPort(30523); -}); - - - -function getJavaProcessIdByPort(port) { - let pid = null; + let port = 30523; exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => { // 查找stdout中匹配端口的行,并提取PID if (stdout) { @@ -61,14 +55,16 @@ function getJavaProcessIdByPort(port) { for (const line of lines) { const pidMatch = line.match(/LISTENING\s+(\d+)/);; if (pidMatch) { - pid = pidMatch[1]; + let 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