Showing window after it is fully loaded

后端 未结 3 767
执笔经年
执笔经年 2021-02-07 03:08

When I create basic application and initialize it using electron command, it shows me a blank window and a moment later loads the content.

Which event and w

3条回答
  •  天涯浪人
    2021-02-07 03:19

    OK, I found an answer myself. The proper event is did-finish-load and should be used like this:

    var Window = new BrowserWindow({ width: 600, height: 400, show: false });
    Window.loadUrl('file://somefile.html');
    Window.webContents.on('did-finish-load', function() {
        Window.show();
    });
    

    For people finding this answer - here you can check official electron documentation on this topic:

    While loading the page, the ready-to-show event will be emitted when the renderer process has rendered the page for the first time if the window has not been shown yet. Showing the window after this event will have no visual flash:

    let win = new BrowserWindow({show: false})
    win.once('ready-to-show', () => {
      win.show()
    })
    

提交回复
热议问题