"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerFullScreen = registerFullScreen;
exports.unregisterFullScreen = unregisterFullScreen;
var electron_1 = require("electron");
var constant_1 = require("../constant");
var IPC_EVENT = {
    ENTER_FULLSCREEN: 'MAIN_WINDOW_ENTER_FULLSCREEN',
    QUIT_FULLSCREEN: 'MAIN_WINDOW_QUIT_FULLSCREEN',
    IS_FULLSCREEN: 'MAIN_WINDOW_IS_FULLSCREEN',
};
function registerFullScreen(mainWindow) {
    var _isMaximized = false;
    electron_1.ipcMain.on(IPC_EVENT.ENTER_FULLSCREEN, function () {
        if (!mainWindow || mainWindow.isDestroyed()) {
            return;
        }
        // linux 不设置，否则最大化窗口再全屏会有问题
        if (!constant_1.isLinux) {
            mainWindow.setFullScreenable(true);
            _isMaximized = mainWindow.isMaximized();
            _isMaximized && mainWindow.unmaximize();
        }
        !mainWindow.isFullScreenPrivate && mainWindow.setFullScreen(true);
    });
    electron_1.ipcMain.on(IPC_EVENT.QUIT_FULLSCREEN, function () {
        if (!mainWindow || mainWindow.isDestroyed()) {
            return;
        }
        !constant_1.isLinux && mainWindow.setFullScreenable(true);
        mainWindow.isFullScreenPrivate && mainWindow.setFullScreen(false);
        !constant_1.isLinux && _isMaximized && mainWindow.maximize();
    });
    electron_1.ipcMain.handle(IPC_EVENT.IS_FULLSCREEN, function () {
        if (!mainWindow || mainWindow.isDestroyed()) {
            return;
        }
        var isFullScreen = (mainWindow === null || mainWindow === void 0 ? void 0 : mainWindow.isFullScreen()) || mainWindow.isFullScreenPrivate;
        return isFullScreen;
    });
}
function unregisterFullScreen() {
    electron_1.ipcMain.removeHandler(IPC_EVENT.ENTER_FULLSCREEN);
    electron_1.ipcMain.removeHandler(IPC_EVENT.QUIT_FULLSCREEN);
    electron_1.ipcMain.removeHandler(IPC_EVENT.IS_FULLSCREEN);
}