Fix: 修复背景不透明的 bug
This commit is contained in:
32
main/main.js
32
main/main.js
@ -58,45 +58,21 @@ function createWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 300,
|
||||
height: 300,
|
||||
transparent: true,
|
||||
frame: false,
|
||||
resizable: false, // 固定大小
|
||||
transparent: true, // 开启透明窗口
|
||||
frame: false, // 无边框窗口
|
||||
resizable: false, // 禁止调整大小
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
contextIsolation: true,
|
||||
webSecurity: false, // 信任应用,并允许加载本地资源
|
||||
webSecurity: false,
|
||||
},
|
||||
});
|
||||
|
||||
// 开发模式加载Vite服务器
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
mainWindow.loadURL("http://localhost:5173");
|
||||
} else {
|
||||
mainWindow.loadFile(path.join(__dirname, "../renderer/dist/index.html"));
|
||||
}
|
||||
|
||||
// 窗口拖拽功能
|
||||
let isDragging = false;
|
||||
mainWindow.webContents.on("before-input-event", (_, input) => {
|
||||
if (input.type === "mouseDown") {
|
||||
isDragging = true;
|
||||
mainWindow.webContents.executeJavaScript(`
|
||||
window.dragOffset = { x: ${input.x}, y: ${input.y} }
|
||||
`);
|
||||
} else if (input.type === "mouseUp") {
|
||||
isDragging = false;
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.on("moved", () => {
|
||||
if (isDragging) {
|
||||
mainWindow.webContents.executeJavaScript(`
|
||||
window.electronAPI.updatePosition()
|
||||
`);
|
||||
}
|
||||
const [x, y] = mainWindow.getPosition();
|
||||
mainWindow.webContents.send("update-position", { x, y });
|
||||
});
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow);
|
||||
|
Reference in New Issue
Block a user