You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
10 years ago
1 year ago
  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow } = require('electron')
  3. const { exec } = require('child_process');
  4. const path = require('node:path')
  5. function createWindow () {
  6. // Create the browser window.
  7. const mainWindow = new BrowserWindow({
  8. width: 1600,
  9. height: 1000,
  10. icon: path.join(__dirname, 'icon.ico'),
  11. webPreferences: {
  12. preload: path.join(__dirname, 'preload.js'),
  13. webSecurity: false, // 允许跨域
  14. }
  15. })
  16. //隐藏菜单
  17. mainWindow.setMenu(null);
  18. // and load the index.html of the app.
  19. //mainWindow.loadFile('index.html')
  20. mainWindow.loadFile('./dist/index.html')
  21. // Open the DevTools.
  22. mainWindow.webContents.openDevTools()
  23. }
  24. // This method will be called when Electron has finished
  25. // initialization and is ready to create browser windows.
  26. // Some APIs can only be used after this event occurs.
  27. app.whenReady().then(() => {
  28. createWindow()
  29. app.on('activate', function () {
  30. // On macOS it's common to re-create a window in the app when the
  31. // dock icon is clicked and there are no other windows open.
  32. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  33. })
  34. })
  35. // Quit when all windows are closed, except on macOS. There, it's common
  36. // for applications and their menu bar to stay active until the user quits
  37. // explicitly with Cmd + Q.
  38. app.on('window-all-closed', function () {
  39. if (process.platform !== 'darwin') app.quit()
  40. })
  41. app.on('before-quit', () => {
  42. getJavaProcessIdByPort(30523);
  43. });
  44. function getJavaProcessIdByPort(port) {
  45. let pid = null;
  46. exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => {
  47. // 查找stdout中匹配端口的行,并提取PID
  48. if (stdout) {
  49. const lines = stdout.trim().split('\r\n');
  50. for (const line of lines) {
  51. const pidMatch = line.match(/LISTENING\s+(\d+)/);;
  52. if (pidMatch) {
  53. pid = pidMatch[1];
  54. require('child_process').execSync(`taskkill /PID ${pid} -t -f`);
  55. return;
  56. }
  57. }
  58. }
  59. });
  60. }
  61. // In this file you can include the rest of your app's specific main process
  62. // code. You can also put them in separate files and require them here.