Skip to content
Snippets Groups Projects
main.js 3.13 KiB
Newer Older
Akshit Kr Nagpal's avatar
Akshit Kr Nagpal committed
const {
    app: APP,
    BrowserWindow,
    Menu,
    shell
} = require('electron');
const isDev = require('electron-is-dev');
Akshit Kr Nagpal's avatar
Akshit Kr Nagpal committed
const windowStateKeeper = require('electron-window-state');
const {
hristoterezov's avatar
hristoterezov committed
    setupAlwaysOnTopMain,
    initPopupsConfigurationMain,
    getPopupTarget
} = require('jitsi-meet-electron-utils');
const path = require('path');
const URL = require('url');
hristoterezov's avatar
hristoterezov committed

/**
 * Load debug utilities (don't open the DevTools window by default though).
 */
require('electron-debug')({ showDevTools: false });
Saúl Ibarra Corretgé's avatar
Saúl Ibarra Corretgé committed
const basePath = isDev ? __dirname : APP.getAppPath();
hristoterezov's avatar
hristoterezov committed
/**
 * URL for index.html which will be our entry point.
 */
const indexURL = URL.format({
    pathname: path.resolve(basePath, './build/index.html'),
hristoterezov's avatar
hristoterezov committed
    slashes: true
});

/**
 * The window object that will load the iframe with Jitsi Meet.
 * IMPORTANT: Must be defined as global in order to not be garbage collected
 * acidentally.
 */
let jitsiMeetWindow = null;

/**
 * Sets the APP object listeners.
 */
function setAPPListeners() {
    APP.on('ready', createJitsiMeetWindow);
    APP.on('window-all-closed', () => {
        // Don't quit the application for macOS.
        if (process.platform !== 'darwin') {
hristoterezov's avatar
hristoterezov committed
            APP.quit();
        }
    });
    APP.on('activate', () => {
hristoterezov's avatar
hristoterezov committed
        if (jitsiMeetWindow === null) {
            createJitsiMeetWindow();
        }
    });
    APP.on('certificate-error',
        // eslint-disable-next-line max-params
        (event, webContents, url, error, certificate, callback) => {
            if (url.startsWith('https://localhost')) {
                event.preventDefault();
                callback(true);
            } else {
                callback(false);
            }
        }
    );
hristoterezov's avatar
hristoterezov committed
}

/**
 * Opens new window with index.html(Jitsi Meet is loaded in iframe there).
 */
function createJitsiMeetWindow() {
    Menu.setApplicationMenu(null);

Akshit Kr Nagpal's avatar
Akshit Kr Nagpal committed
    // Load the previous state with fallback to defaults
    const jitsiMeetWindowState = windowStateKeeper({
        defaultWidth: 800,
        defaultHeight: 600
    });

    // Options used when creating the main Jitsi Meet window.
    const jitsiMeetWindowOptions = {
        x: jitsiMeetWindowState.x,
        y: jitsiMeetWindowState.y,
        width: jitsiMeetWindowState.width,
        height: jitsiMeetWindowState.height,
        minWidth: 800,
        minHeight: 600,
        titleBarStyle: 'hidden',
        webPreferences: {
            nativeWindowOpen: true
        }
    };

    jitsiMeetWindow = new BrowserWindow(jitsiMeetWindowOptions);
Akshit Kr Nagpal's avatar
Akshit Kr Nagpal committed
    jitsiMeetWindowState.manage(jitsiMeetWindow);
hristoterezov's avatar
hristoterezov committed
    jitsiMeetWindow.loadURL(indexURL);
hristoterezov's avatar
hristoterezov committed
    initPopupsConfigurationMain(jitsiMeetWindow);
hristoterezov's avatar
hristoterezov committed

    jitsiMeetWindow.webContents.on('new-window', (event, url, frameName) => {
hristoterezov's avatar
hristoterezov committed
        const target = getPopupTarget(url, frameName);

        if (!target || target === 'browser') {
            event.preventDefault();
Akshit Kr Nagpal's avatar
Akshit Kr Nagpal committed
            shell.openExternal(url);
    setupAlwaysOnTopMain(jitsiMeetWindow);

    jitsiMeetWindow.on('closed', () => {
hristoterezov's avatar
hristoterezov committed
        jitsiMeetWindow = null;
    });
}

//  Start the application:
hristoterezov's avatar
hristoterezov committed
setAPPListeners();