How to set the devTools window position in electron

孤街浪徒 提交于 2019-12-11 01:59:57

问题


I got this from the docs

app.on('ready', function(){
    devtools = new BrowserWindow()
    window = new BrowserWindow({width:800, height:600})
    window.loadURL(path.join('file://', __dirname, 'static/index.html'))
    window.webContents.setDevToolsWebContents(devtools.webContents)
    window.webContents.openDevTools({mode: 'detach'})
})

It opens two windows, on is the dev tools. But it's exactly underneath the main window.

Is there a way to get them side by side (the screen is big enough)?


回答1:


Once you've called setDevToolsWebContents then you can move the devtools window around just by calling devtools.setPosition(x, y).

Here is a example of moving the devtools next to the window by setting it's position whenever it's moved:

app.on('ready', function () {
    var devtools = new BrowserWindow();
    var window   = new BrowserWindow({width: 800, height: 600});
    window.loadURL('https://stackoverflow.com/questions/52178592/how-to-set-the-devtools-window-position-in-electron');

    window.webContents.setDevToolsWebContents(devtools.webContents);
    window.webContents.openDevTools({mode: 'detach'});

    // Set the devtools position when the parent window has finished loading.
    window.webContents.once('did-finish-load', function () {
        var windowBounds = window.getBounds();
        devtools.setPosition(windowBounds.x + windowBounds.width, windowBounds.y);
    });

    // Set the devtools position when the parent window is moved.
    window.on('move', function () {
        var windowBounds = window.getBounds();
        devtools.setPosition(windowBounds.x + windowBounds.width, windowBounds.y);
    });
});


来源:https://stackoverflow.com/questions/52178592/how-to-set-the-devtools-window-position-in-electron

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!