From b1d515465a1fec42cea47c6371ce447be5ab0520 Mon Sep 17 00:00:00 2001 From: alger Date: Wed, 30 Apr 2025 00:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E6=8E=A7=E5=88=B6=E9=A1=B5=E9=9D=A2=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/modules/remoteControl.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/modules/remoteControl.ts b/src/main/modules/remoteControl.ts index 6a3d3b3..f69eb8c 100644 --- a/src/main/modules/remoteControl.ts +++ b/src/main/modules/remoteControl.ts @@ -1,4 +1,4 @@ -import { ipcMain } from 'electron'; +import { ipcMain, app as electronApp } from 'electron'; import express from 'express'; import cors from 'cors'; import os from 'os'; @@ -212,12 +212,22 @@ function setupRoutes(app: express.Application) { // 提供远程控制界面HTML app.get('/', (_, res) => { try { - const htmlPath = path.join(process.cwd(), 'resources', 'html', 'remote-control.html'); - if (fs.existsSync(htmlPath)) { - res.sendFile(htmlPath); + // 使用electronApp.getAppPath()获取应用根目录 + const appPath = electronApp.getAppPath(); + + // 在开发环境下可能需要不同的路径 + const isPacked = electronApp.isPackaged; + const finalPath = isPacked + ? path.join(path.dirname(appPath), 'resources', 'html', 'remote-control.html') + : path.join(appPath, 'resources', 'html', 'remote-control.html'); + + console.log('远程控制HTML路径:', finalPath); + + if (fs.existsSync(finalPath)) { + res.sendFile(finalPath); } else { res.status(404).send('远程控制界面文件未找到'); - console.error('远程控制界面文件不存在:', htmlPath); + console.error('远程控制界面文件不存在:', finalPath); } } catch (error) { console.error('加载远程控制界面失败:', error);