【问题标题】:How to set the devTools window position in electron如何在电子中设置 devTools 窗口位置
【发布时间】:2022-02-11 20:06:26
【问题描述】:

我从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'})
})

它打开两个窗口,打开的是开发工具。但它正好在主窗口的下方。

有没有办法让它们并排(屏幕足够大)?

【问题讨论】:

    标签: electron


    【解决方案1】:

    一旦你调用了setDevToolsWebContents,你就可以通过调用devtools.setPosition(x, y)来移动开发工具窗口。

    这是一个将 devtools 移动到窗口旁边的示例,方法是在移动时设置它的位置:

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

    【讨论】:

      猜你喜欢
      • 2017-09-24
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 2021-11-19
      相关资源
      最近更新 更多