mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-30 21:07:24 +08:00
🐞 fix: 修复远程控制页面找不到问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ipcMain } from 'electron';
|
import { ipcMain, app as electronApp } from 'electron';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
@@ -212,12 +212,22 @@ function setupRoutes(app: express.Application) {
|
|||||||
// 提供远程控制界面HTML
|
// 提供远程控制界面HTML
|
||||||
app.get('/', (_, res) => {
|
app.get('/', (_, res) => {
|
||||||
try {
|
try {
|
||||||
const htmlPath = path.join(process.cwd(), 'resources', 'html', 'remote-control.html');
|
// 使用electronApp.getAppPath()获取应用根目录
|
||||||
if (fs.existsSync(htmlPath)) {
|
const appPath = electronApp.getAppPath();
|
||||||
res.sendFile(htmlPath);
|
|
||||||
|
// 在开发环境下可能需要不同的路径
|
||||||
|
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 {
|
} else {
|
||||||
res.status(404).send('远程控制界面文件未找到');
|
res.status(404).send('远程控制界面文件未找到');
|
||||||
console.error('远程控制界面文件不存在:', htmlPath);
|
console.error('远程控制界面文件不存在:', finalPath);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载远程控制界面失败:', error);
|
console.error('加载远程控制界面失败:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user