Wilson@思源

目 录

修改新窗口大小

see https://github.com/siyuan-note/siyuan/blob/914c7659388e645395e70224f0d831950275eb05/app/src/window/openNewWindow.ts#L21
see https://gitee.com/wish163/mysoft/blob/main/%E6%80%9D%E6%BA%90/%E6%80%9D%E6%BA%90%E5%90%AF%E5%8A%A8%E8%BD%AF%E4%BB%B6%E6%97%B6%E6%9C%80%E5%A4%A7%E5%8C%96%E6%98%BE%E7%A4%BA.js
see https://ld246.com/article/1732239161536
核心代码
js
// 主窗口监听 function OnWindowOpenResizeWindow() { const ipcRenderer = require('electron').ipcRenderer; const originalSend = ipcRenderer.send; // 重写 ipcRenderer.send 方法 ipcRenderer.send = async function (...args) { if(args[0] === 'siyuan-open-window' && !args[1].width && !args[1].height){ const newWinSize = getNewWindowSize(); args[1].width = newWinSize.width; args[1].height = newWinSize.height; originalSend.apply(ipcRenderer, args); } else { originalSend.apply(ipcRenderer, args); } }; } // 或 新窗口监听 function resizeWindow() { // 获取屏幕的宽度和高度 const screenWidth = screen.width; const screenHeight = screen.height; // 计算新窗口的宽度和高度(屏幕的一半) const windowWidth = screenWidth / 2; const windowHeight = screenHeight / 2; // 计算新窗口的位置(居中显示) const windowLeft = (screenWidth - windowWidth) / 2; const windowTop = (screenHeight - windowHeight) / 2; // 调整窗口大小和位置 window.resizeTo(windowWidth, windowHeight); window.moveTo(windowLeft, windowTop); }