electron如何让页面加载完后,窗口再显示

首先创建窗口的时候,加一个属性show:false,创建完窗口先让它不显示,然后加载页面,加载完页面再显示窗口。
例子如下:

const {app,BrowserWindow} = require('electron');

function createWindow(){
   win = new BrowserWindow({
    show:false,
    webPreferences: {
        nodeIntegration: true
    }
   });
   win.loadFile('index.html');
   win.on('ready-to-show',()=>{
    win.show()
   });
   win.on('closed',()=>{
    console.log('closed');
    win = null;
   });
   
}

app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
    console.log('window-all-closed');
    if(process.platform != 'darwin'){
        app.quit();
    }
});
app.on('activate',()=>{
    console.log('activate');
    if(win == null) {
        createWindow();
    }
});

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: