webpack+electron(桌面系统双平系统)

新建屏幕

function createWindow() {

mainWindow = new BrowserWindow({
    webPreferences: {
        webSecurity: false
    },
    width: 1024,
    height: 768,
    icon: 'static/icon.ico',
    transparent: false,
    frame: false,
    minimizable: true,
    titleBarStyle: 'hiddenInset'
})
mainWindow.once('ready-to-show', () => {
    mainWindow.show()
})
let displays = electron.screen.getAllDisplays()
let externalDisplay = displays.find((display) => {
    return display.bounds.x !== 0 || display.bounds.y !== 0
})

if(externalDisplay) {
    win = new BrowserWindow({
        width: 1024,
        height: 768,
        transparent: false,
        frame: false,
        x: externalDisplay.bounds.x,
        y: externalDisplay.bounds.y,
        closable: true,    //是否可以关闭
        skipTaskbar: true //不显示在任务栏
    })
    win.once('ready-to-show', () => {
        win.show()
    })
    win.loadURL(`file://${__dirname}/pingmuad.html`)
    //设置全屏
    win.setFullScreen(true);

}
//设置全屏
mainWindow.setFullScreen(true);
// and load the index.html of the app.
mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
}))
trayIcon = path.join(__dirname, 'static');
appTray = new Tray(path.join(trayIcon, 'icon.ico'));
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
    mainWindow.on('closed', function() {
        // Dereference the window object, usually you would store windows
        // in an array if your app supports multi windows, this is the time
        // when you should delete the corresponding element.
        mainWindow = null;
        app.quit()
    })

}
开启第二块平面
ipc.on(“pingmuorder”, (event, arg) => {

win.loadURL(`file://${__dirname}/pingmuorder.html`);
win.setMenu(null);
win.webContents.on('did-finish-load', () => {
    win.webContents.send('request', arg);
});

});

准备启动项目
app.on(‘ready’, createWindow)

关闭屏幕退出
app.on(‘window-all-closed’, function() {

if(process.platform !== 'darwin') {
    app.quit()
}

})

    原文作者:三月
    原文地址: https://segmentfault.com/a/1190000015195896
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞