首页 > 其他 > 详细

04.《Electron 跨平台开发实战》- chapter05-创建多窗口应用

时间:2020-06-12 12:32:00      阅读:53      评论:0      收藏:0      [点我收藏+]

项目代码

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 );

window的坐标

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;
    }

与macOS集成

04.《Electron 跨平台开发实战》- chapter05-创建多窗口应用

原文:https://www.cnblogs.com/easy5weikai/p/13098676.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!