https://github.com/electron-in-action/firesale/tree/chapter-5
添加参数, targetWindow 表示当前窗口
main.js
const openFile = exports.openFile = (targetWindow, file) => {
const content = fs.readFileSync(file).toString();
targetWindow.webContents.send(‘file-opened‘, file, content);
};
renderer.js
在渲染进程中,使用 remote.getCurrentWindow();
获取当前窗口
const { remote, ipcRenderer } = require(‘electron‘);
const mainProcess = remote.require(‘./main.js‘);
const currentWindow = remote.getCurrentWindow();
mainProcess.openFile(currentWindow );
const currentWindow = BrowserWindow.getFocusedWindow();
currentWindow.getPosition()
const { app, BrowserWindow, dialog } = require(‘electron‘);
...
const currentWindow = BrowserWindow.getFocusedWindow();
if (currentWindow) {
const [currentWindowX, currentWindowY] = currentWindow.getPosition();
x = currentWindowX + 10;
y = currentWindowY + 10;
}
04.《Electron 跨平台开发实战》- chapter05-创建多窗口应用
原文:https://www.cnblogs.com/easy5weikai/p/13098676.html