/*
模板1
*/
const { app, BrowserWindow } = global.electron
let indexWindow;
let winH = -1;
let winW = -1;
app.on('ready', function() {
    const { screen } = global.electron
    winH = screen.getPrimaryDisplay().workAreaSize.height;
    winW = screen.getPrimaryDisplay().workAreaSize.width;
})

function showWindow() {
    createIndexWindow();
};

function closeWindow() {
    if (indexWindow) {

        indexWindow.destroy()
    }
};

function createIndexWindow() {
    // 创建浏览器窗口。

    indexWindow = new BrowserWindow({ width: 1000, height: 600, darkTheme: "true", title: "CCR播放器" });

    // 加载应用的 index.html。
    indexWindow.loadURL(`file://${global.dirname}/template/openZip.html`);
	console.log("这个窗口激活两次");

    // 当 window 被关闭，这个事件会被触发。
    indexWindow.on('close', (e) => {
        // console.log(e);
        //if (indexWindow == null) return;
        indexWindow = null;
        app.quit();
    });
};
function openErrorWindow(data) {
	if(!indexWindow||!indexWindow.webContents)return;
	indexWindow.webContents.send('openZip_error', data);
}
module.exports.openErrorWindow =openErrorWindow;
module.exports.showWindow = showWindow;
module.exports.closeWindow = closeWindow;