jitsi-meet-electron/main.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

/* global __dirname, process */
2018-05-24 17:12:27 +02:00
2018-06-20 21:38:53 +02:00
const {
app: APP,
BrowserWindow,
Menu,
shell
} = require('electron');
const isDev = require('electron-is-dev');
2018-06-20 21:38:53 +02:00
const windowStateKeeper = require('electron-window-state');
2017-08-04 15:15:22 +02:00
const {
2018-06-13 00:39:56 +02:00
setupAlwaysOnTopMain,
initPopupsConfigurationMain,
getPopupTarget
} = require('jitsi-meet-electron-utils');
const path = require('path');
2018-05-09 19:57:26 +02:00
const URL = require('url');
2016-12-12 21:46:47 +01:00
/**
* Load debug utilities (don't open the DevTools window by default though).
*/
require('electron-debug')({ showDevTools: false });
/**
* Path to root directory
*/
2018-06-16 08:36:05 +02:00
const basePath = isDev ? __dirname : APP.getAppPath();
2016-12-12 21:46:47 +01:00
/**
* URL for index.html which will be our entry point.
*/
2018-05-09 19:57:26 +02:00
const indexURL = URL.format({
pathname: path.resolve(basePath, './build/index.html'),
protocol: 'file:',
2016-12-12 21:46:47 +01:00
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', () => {
2018-05-24 17:12:27 +02:00
// Don't quit the application for macOS.
if (process.platform !== 'darwin') {
2016-12-12 21:46:47 +01:00
APP.quit();
}
});
APP.on('activate', () => {
2016-12-12 21:46:47 +01:00
if (jitsiMeetWindow === null) {
createJitsiMeetWindow();
}
});
APP.on('certificate-error',
2018-05-24 17:12:27 +02:00
// eslint-disable-next-line max-params
(event, webContents, url, error, certificate, callback) => {
if (url.startsWith('https://localhost')) {
event.preventDefault();
callback(true);
} else {
callback(false);
}
}
);
2016-12-12 21:46:47 +01:00
}
/**
* Opens new window with index.html(Jitsi Meet is loaded in iframe there).
*/
function createJitsiMeetWindow() {
2018-06-16 08:36:52 +02:00
Menu.setApplicationMenu(null);
2018-06-20 21:38:53 +02:00
// 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);
2018-06-20 21:38:53 +02:00
jitsiMeetWindowState.manage(jitsiMeetWindow);
2016-12-12 21:46:47 +01:00
jitsiMeetWindow.loadURL(indexURL);
2018-06-13 00:39:56 +02:00
initPopupsConfigurationMain(jitsiMeetWindow);
2016-12-12 21:46:47 +01:00
2017-08-04 15:15:22 +02:00
jitsiMeetWindow.webContents.on('new-window', (event, url, frameName) => {
2018-06-13 00:39:56 +02:00
const target = getPopupTarget(url, frameName);
if (!target || target === 'browser') {
2017-08-04 15:15:22 +02:00
event.preventDefault();
2018-06-20 21:38:53 +02:00
shell.openExternal(url);
2017-08-04 15:15:22 +02:00
}
});
2017-08-04 15:15:22 +02:00
setupAlwaysOnTopMain(jitsiMeetWindow);
jitsiMeetWindow.on('closed', () => {
2016-12-12 21:46:47 +01:00
jitsiMeetWindow = null;
});
}
// Start the application:
2016-12-12 21:46:47 +01:00
setAPPListeners();