From e71dda3b673ddcd38ad668fcded74de7d54e57a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E6=A3=AE?= Date: Fri, 28 Jun 2024 18:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forge.config.js | 3 ++- run.bat | 3 ++- server/server.js | 53 ++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/forge.config.js b/forge.config.js index 573de68..65fde88 100644 --- a/forge.config.js +++ b/forge.config.js @@ -7,7 +7,8 @@ module.exports = { icon: 'iyuu.png', extraResource: [ 'run/', - 'iyuu/' + 'iyuu/', + "run.bat" ] }, rebuildConfig: {}, diff --git a/run.bat b/run.bat index fed2f65..72c8568 100644 --- a/run.bat +++ b/run.bat @@ -1,3 +1,4 @@ +@echo off CHCP 65001 .\run\php-8.3.8-x64\php.exe .\iyuu\windows.php -pause \ No newline at end of file +pause diff --git a/server/server.js b/server/server.js index 0589d6e..dcacae2 100644 --- a/server/server.js +++ b/server/server.js @@ -1,4 +1,4 @@ -const { spawn, exec } = require('child_process'); +const { spawn, exec, execFile } = require('child_process'); const os = require('os'); const path = require('path'); const log = require('electron-log') @@ -24,25 +24,54 @@ function startServer() { } const cmdPath = getCmdPath(resourcePath); - const args = [path.join(resourcePath, 'iyuu', 'windows.php')]; + const batPath = path.join(resourcePath, 'run.bat'); const workingDirectory = path.resolve(resourcePath); const env = { ...process.env }; const phpDir = path.dirname(cmdPath); - env.PATH = `${phpDir}${path.delimiter}${env.PATH}`; + env.Path = `${phpDir};${env.Path}`; - serverProcess = spawn(cmdPath, args, { + // serverProcess = exec(`C:\\Windows\\System32\\cmd.exe /c ${batPath}`, { + // cwd: workingDirectory, + // env: env, + // windowsHide: true + // }, (error, stdout, stderr) => { + // if (error) { + // log.error(`[IYUU] 服务启动错误: ${error.message}`); + // return; + // } + // if (stderr) { + // log.error(`[IYUU] 服务启动 stderr: ${stderr}`); + // return; + // } + // log.info(`[IYUU] 服务启动成功: ${stdout}`); + // }); + + serverProcess = execFile('cmd.exe', ['/c', batPath], { cwd: workingDirectory, - stdio: ['inherit', 'pipe', 'inherit'], + stdio: 'ignore', env: env, - detached: true, + windowsHide: true }); - serverProcess.stdout.setEncoding('utf8'); + // serverProcess = spawn('cmd.exe', ['/c', batPath], { + // cwd: workingDirectory, + // stdio: 'ignore', + // env: env, + // detached: true, + // windowsHide: true + // }); + + serverProcess.unref(); + + if (serverProcess.stdout) { + serverProcess.stdout.setEncoding('utf8'); + + serverProcess.stdout.on("data", function (data) { + log.info("[IYUU] 服务启动成功"); + }); + } - serverProcess.stdout.on("data", function (data) { - log.info("[IYUU] 服务启动成功"); - }); serverProcess.on("close", function (code) { log.info("[IYUU] 服务退出:" + code); }); @@ -75,7 +104,9 @@ function stopServer() { function restartServer() { stopServer(); - startServer(); + setTimeout(() => { + startServer(); + }, 1000); } module.exports = { startServer, stopServer, restartServer }; \ No newline at end of file