03
2021
09

electron设计的第一个程序 全屏无边框 关闭弹出提醒 允许访问私有证书网站防止白屏

const {app, BrowserWindow, globalShortcut, dialog, Menu, ipcMain} = require('electron')
var electron = require('electron')
app.commandLine.appendSwitch('--kiosk-printing', 'true')
app.on('ready', () => {
	  Menu.setApplicationMenu(null)

    mainWindow = new BrowserWindow({
		fullscreen:true,
        width: 1920,
        height: 1080,
        minHeight: 800,
        minWidth: 1500,
        // fullscreen: true,
        webPreferences: {
            nodeIntegration: true,
            enableRemoteModule: true,
            webviewTag: true,
        },
    })
    //mainWindow.loadFile('index.html')
	//app.commandLine.appendSwitch('--ignore-certificate-errors', 'true')//忽略错误,测试不行
    mainWindow.loadURL("http://api.yccytouch.com/api/fpcx")

    //mainWindow要关闭时的方法↓
    mainWindow.on('close', e => {
        e.preventDefault(); //先阻止一下默认行为,不然直接关了,提示框只会闪一下
        electron.dialog.showMessageBox({
            type: 'info',
            title: '提示',
            message:'确认退出?',
            buttons: ['确认', '取消'],   //选择按钮,点击确认则下面的idx为0,取消为1
            cancelId: 1, //这个的值是如果直接把提示框×掉返回的值,这里设置成和“取消”按钮一样的值,下面的idx也会是1
        }).then(idx => {    
        //注意上面↑是用的then,网上好多是直接把方法做为showMessageBox的第二个参数,我的测试下不成功
            console.log(idx)
            if (idx.response == 1) {
                console.log('index==1,取消关闭')
                e.preventDefault();
            } else {
                console.log('index==0,关闭')
                mainWindow = null
                app.exit();
            }
            })
        });
})
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
    //允许私有证书
    event.preventDefault()
    callback(true)
});


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。