From d57fb8df7fec2b85ba0f36b3058efb23626a2ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?= <10714957+xiao-zhu245@user.noreply.gitee.com> Date: Fri, 11 Jul 2025 21:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9F=B3=E9=A2=91=E5=92=8Cpy?= =?UTF-8?q?thon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 28 ---------------------------- client/src/App.tsx | 15 +++++++++++++-- server/src/routes/instances.ts | 34 ++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index acedb60..6f7a19c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,34 +61,6 @@ jobs: with: node-version: '22.16.0' cache: 'npm' - - name: Download Windows Node.js - shell: pwsh - run: | - $nodeVersion = "22.16.0" - $nodeUrl = "https://nodejs.org/dist/v$nodeVersion/node-v$nodeVersion-win-x64.zip" - Write-Host "Downloading Node.js for Windows..." - Invoke-WebRequest -Uri $nodeUrl -OutFile "node-windows.zip" - - # 解压到临时目录 - Write-Host "Extracting Node.js..." - Expand-Archive -Path "node-windows.zip" -DestinationPath "temp-node" -Force - - # 移动到server目录 - if (Test-Path "temp-node/node-v$nodeVersion-win-x64") { - if (Test-Path "server/node") { - Remove-Item "server/node" -Recurse -Force - } - Move-Item "temp-node/node-v$nodeVersion-win-x64" "server/node" - Remove-Item "temp-node" -Recurse -Force - } - - # 验证文件结构 - if (Test-Path "server/node/node.exe") { - Write-Host "Node.js for Windows downloaded and placed in server directory successfully" - } else { - Write-Error "Failed to place Node.js in server directory" - exit 1 - } - name: Install dependencies run: | npm install diff --git a/client/src/App.tsx b/client/src/App.tsx index d42a891..ea245f6 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -18,6 +18,17 @@ import LoadingSpinner from '@/components/LoadingSpinner' import NotificationContainer from '@/components/NotificationContainer' import GlobalMusicPlayer from '@/components/GlobalMusicPlayer' +// GlobalMusicPlayer包装器组件 - 只在已登录时显示 +const GlobalMusicPlayerWrapper: React.FC = () => { + const { isAuthenticated } = useAuthStore() + + if (!isAuthenticated) { + return null + } + + return +} + // 受保护的路由组件 const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => { const { isAuthenticated, loading } = useAuthStore() @@ -137,8 +148,8 @@ function App() { {/* 全局通知容器 */} - {/* 全局音乐播放器 */} - + {/* 全局音乐播放器 - 只在已登录时显示 */} + diff --git a/server/src/routes/instances.ts b/server/src/routes/instances.ts index 82e268f..a6dff08 100644 --- a/server/src/routes/instances.ts +++ b/server/src/routes/instances.ts @@ -487,10 +487,29 @@ const __dirname = path.dirname(__filename) // Python脚本路径 const PYTHON_SCRIPT_PATH = path.join(__dirname, '..', 'Python', 'game_config_manager.py') -// Python依赖安装状态 +// Python依赖是否已安装的标志 let pythonDepsInstalled = false -// 安装Python依赖 +// 获取正确的Python命令 +function getPythonCommand(): string { + const platform = os.platform() + if (platform === 'win32') { + return 'python' + } else { + return 'python3' + } +} + +// 获取正确的pip命令 +function getPipCommand(): string { + const platform = os.platform() + if (platform === 'win32') { + return 'pip' + } else { + return 'pip3' + } +} + function installPythonDependencies(): Promise { return new Promise((resolve, reject) => { if (pythonDepsInstalled) { @@ -531,7 +550,7 @@ function installPythonDependencies(): Promise { const mirror = mirrors[currentMirrorIndex] logger.info(`尝试使用${mirror.name}安装Python依赖`) - const installProcess = spawn('pip', [ + const installProcess = spawn(getPipCommand(), [ 'install', '-r', requirementsPath, @@ -581,7 +600,7 @@ function callPythonScript(method: string, args: any[] = []): Promise { await installPythonDependencies() const pythonArgs = [PYTHON_SCRIPT_PATH, method, ...args.map(arg => JSON.stringify(arg))] - const pythonProcess = spawn('python', pythonArgs, { + const pythonProcess = spawn(getPythonCommand(), pythonArgs, { stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, @@ -808,12 +827,7 @@ router.post('/:instanceId/configs/:configId', authenticateToken, async (req: Req router.get('/python/check', authenticateToken, async (req: Request, res: Response) => { try { const platform = os.platform() - let pythonCommand = 'python' - - // Linux和macOS系统优先使用python3 - if (platform === 'linux' || platform === 'darwin') { - pythonCommand = 'python3' - } + const pythonCommand = getPythonCommand() logger.info(`检测Python环境,平台: ${platform},使用命令: ${pythonCommand}`)