Skip to content

Commit

Permalink
Merge pull request #186 from jcfun/dev
Browse files Browse the repository at this point in the history
- 修复linux下无法记录窗口大小和位置的问题
- 修复主进程端口占用时无法自动切换端口的问题
- 统一程序关闭按钮的效果
  • Loading branch information
imsyy authored Jun 21, 2024
2 parents 7d3d769 + 54fb8e7 commit 9423d2b
Show file tree
Hide file tree
Showing 4 changed files with 4,485 additions and 5,568 deletions.
1 change: 1 addition & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ linux:
icon: public/imgs/icons/favicon-512x512.png
# 构建类型
target:
- pacman
- AppImage
- deb
- rpm
Expand Down
18 changes: 8 additions & 10 deletions electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class MainProcess {
}
// 生产模式
else {
this.mainWindow.loadURL(`http://127.0.0.1:${import.meta.env.MAIN_VITE_MAIN_PORT ?? 7899}`);
console.log("生产模式渲染端口: " + process.env.MAIN_VITE_MAIN_PORT ?? 7899);
this.mainWindow.loadURL(`http://127.0.0.1:${process.env.MAIN_VITE_MAIN_PORT ?? 7899}`);
}

// 配置网络代理
Expand Down Expand Up @@ -232,24 +233,21 @@ class MainProcess {
this.mainWindow.webContents.send("windowState", false);
});

this.mainWindow.on("resized", () => {
this.mainWindow.on("resize", () => {
this.store.set("windowSize", this.mainWindow.getBounds());
});

this.mainWindow.on("moved", () => {
this.mainWindow.on("move", () => {
this.store.set("windowSize", this.mainWindow.getBounds());
});

// 窗口关闭
this.mainWindow.on("close", (event) => {
if (platform.isLinux) {
app.quit();
event.preventDefault();
if (!app.isQuiting) {
this.mainWindow.hide();
} else {
if (!app.isQuiting) {
event.preventDefault();
this.mainWindow.hide();
}
return false;
app.exit();
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion electron/main/startMainServer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { join } from "path";
import express from "express";
import expressProxy from "express-http-proxy";
import checkPort from "./utils/checkPort";

/**
* 启动主服务器
* @returns {import('http').Server} HTTP 服务器实例
*/
export const startMainServer = async () => {
const { MAIN_VITE_MAIN_PORT, MAIN_VITE_SERVER_HOST, MAIN_VITE_SERVER_PORT } = import.meta.env;
const port = MAIN_VITE_MAIN_PORT ?? 7899;
const port = await checkPort(MAIN_VITE_MAIN_PORT ?? 7899);
process.env.MAIN_VITE_MAIN_PORT = port;
const apiHost = `http://${MAIN_VITE_SERVER_HOST}:${MAIN_VITE_SERVER_PORT}`;
const expressApp = express();
// 代理
expressApp.use("/", express.static(join(__dirname, "../renderer/")));
expressApp.use("/api", expressProxy(apiHost));
console.log("生产模式主进程端口: ", port);
// 启动 Express 应用服务器,并监听指定端口
return expressApp.listen(port, "127.0.0.1");
};
Loading

0 comments on commit 9423d2b

Please sign in to comment.