Conversation
laoshuikaixue
commented
Apr 5, 2026
- 将 localhost 替换为 127.0.0.1 以解决网络连接问题
- 统一所有窗口 URL 配置中的地址引用
- 在 Vite 配置中设置服务器主机地址为 127.0.0.1
- 创建专门的 devRendererUrl 变量处理开发环境渲染器地址
- 确保歌词窗口和加载窗口使用正确的本地地址
- 修复了 ELECTRON_RENDERER_URL 环境变量的地址替换逻辑
- 将 localhost 替换为 127.0.0.1 以解决网络连接问题 - 统一所有窗口 URL 配置中的地址引用 - 在 Vite 配置中设置服务器主机地址为 127.0.0.1 - 创建专门的 devRendererUrl 变量处理开发环境渲染器地址 - 确保歌词窗口和加载窗口使用正确的本地地址 - 修复了 ELECTRON_RENDERER_URL 环境变量的地址替换逻辑
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request updates the development and preview server configurations to use 127.0.0.1 instead of localhost and adjusts the URL generation logic in the Electron main process. Review feedback suggests refining the fallback logic for the renderer URL by incorporating a dedicated web port and refactoring the URL constants to eliminate redundancy.
| const devRendererUrl = process.env["ELECTRON_RENDERER_URL"]?.replace( | ||
| "://localhost", | ||
| "://127.0.0.1", | ||
| ); |
There was a problem hiding this comment.
建议同时引入渲染进程的开发端口 VITE_WEB_PORT,以便在 ELECTRON_RENDERER_URL 环境变量缺失时,能为开发环境提供更准确的回退地址。在进行字符串替换时,遵循项目惯例使用简单的 string.replace 方式。
export const webPort = Number(import.meta.env["VITE_WEB_PORT"] || 14558);
const devRendererUrl = process.env["ELECTRON_RENDERER_URL"]?.replace(
"://localhost",
"://127.0.0.1",
);References
- When modifying existing code, retain simple and clear implementations (like string.replace) over more complex, robust alternatives (like regex) if the original implementation is sufficient.
| export const mainWinUrl = | ||
| isDev && process.env["ELECTRON_RENDERER_URL"] | ||
| ? process.env["ELECTRON_RENDERER_URL"] | ||
| : `http://localhost:${port}`; | ||
| isDev && devRendererUrl ? devRendererUrl : `http://127.0.0.1:${port}`; | ||
|
|
||
| /** | ||
| * 歌词窗口加载地址 | ||
| * @returns string | ||
| */ | ||
| export const lyricWinUrl = | ||
| isDev && process.env["ELECTRON_RENDERER_URL"] | ||
| ? `${process.env["ELECTRON_RENDERER_URL"]}/#/desktop-lyric` | ||
| : `http://localhost:${port}/#/desktop-lyric`; | ||
| isDev && devRendererUrl | ||
| ? `${devRendererUrl}/#/desktop-lyric` | ||
| : `http://127.0.0.1:${port}/#/desktop-lyric`; | ||
|
|
||
| /** | ||
| * 加载窗口地址 | ||
| * @returns string | ||
| */ | ||
| export const loadWinUrl = | ||
| isDev && process.env["ELECTRON_RENDERER_URL"] | ||
| ? `${process.env["ELECTRON_RENDERER_URL"]}/web/loading/index.html` | ||
| : `http://localhost:${port}/web/loading/index.html`; | ||
| isDev && devRendererUrl | ||
| ? `${devRendererUrl}/web/loading/index.html` | ||
| : `http://127.0.0.1:${port}/web/loading/index.html`; |
There was a problem hiding this comment.
建议利用 mainWinUrl 作为基础路径来简化 lyricWinUrl 和 loadWinUrl 的定义,减少重复代码。此外,在开发环境下(isDev 为 true)如果 devRendererUrl 缺失,应回退到渲染进程端口(webPort)而非后端服务端口(port)。
export const mainWinUrl =
isDev ? (devRendererUrl || "http://127.0.0.1:" + webPort) : "http://127.0.0.1:" + port;
/**
* 歌词窗口加载地址
* @returns string
*/
export const lyricWinUrl = mainWinUrl + "/#/desktop-lyric";
/**
* 加载窗口地址
* @returns string
*/
export const loadWinUrl = mainWinUrl + "/web/loading/index.html";There was a problem hiding this comment.
Code Review
This pull request updates the application configuration to use the explicit IP address 127.0.0.1 instead of localhost. Specifically, it modifies the Vite server and preview host settings in electron.vite.config.ts and updates the URL generation logic for the main, lyric, and loading windows in electron/main/utils/config.ts. I have no feedback to provide.
?左右脑互搏 怎么又没了 |

