Fix: 修复拖动/点击桌宠时,主程序发生移动的问题

This commit is contained in:
2025-09-03 15:53:05 +08:00
parent a1183a35d3
commit 57b268008d
3 changed files with 44 additions and 20 deletions

View File

@ -87,7 +87,17 @@ function createWindow() {
// 当渲染进程传来这个事件时,就移动窗口
ipcMain.on('move-window', (event, { x, y }) => {
mainWindow.setPosition(x, y, true); // true 表示动画平滑移动
// 使用 Math.round 避免非整数坐标可能带来的问题
mainWindow.setPosition(Math.round(x), Math.round(y), false);
});
// 添加一个 handle用于响应前端获取窗口位置的请求
ipcMain.handle('get-window-position', () => {
if (mainWindow) {
const [x, y] = mainWindow.getPosition();
return { x, y };
}
return { x: 0, y: 0 };
});
if (process.env.NODE_ENV === "development") {