完全加载后显示窗口 [英] Showing window after it is fully loaded

查看:93
本文介绍了完全加载后显示窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建基本应用程序并使用 electron 命令对其进行初始化时,它会显示一个空白窗口,稍后会加载内容。

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 which object should be used to show the window after the content is fully loaded?

did-finish在 window.webContent 对象上加载?或者 dom-ready ?或者其他什么?

did-finish-load on a window.webContent object? Or maybe dom-ready? Or maybe something else?

app.js

var app = require('app'),
    Window = require('browser-window'),
    mainWindow = null;

require('crash-reporter').start();

app.on('ready', function() {
   mainWindow = new Window({ width: 600, height: 400, show: false });

   mainWindow.loadUrl('file://' + __dirname + '/index.html');
   mainWindow.show();

   //
   // mainWindow.webContent.on('did-finish-load', function() {
   //     something like that is a proper way?
   // });
   //
});


推荐答案

好的,我自己找到了答案。正确的事件是 did-finish-load ,应该像这样使用:

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






对于找到这个答案的人 - 在这里你可以检查官方电子文档关于此主题


在加载页面时,当渲染器进程呈现页面时,将发出准备好显示的事件如果窗口尚未显示,第一次。在此事件之后显示窗口将没有可视闪光:

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

这篇关于完全加载后显示窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆