2016-12-28 03:03:52 +01:00
|
|
|
/* 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');
|
2018-05-24 16:02:27 +02:00
|
|
|
const isDev = require('electron-is-dev');
|
2018-07-15 21:27:03 +02:00
|
|
|
const { autoUpdater } = require('electron-updater');
|
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
|
2018-05-09 10:21:31 +02:00
|
|
|
} = 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
|
|
|
|
2018-07-15 21:27:03 +02:00
|
|
|
autoUpdater.logger = require('electron-log');
|
|
|
|
autoUpdater.logger.transports.file.level = 'info';
|
|
|
|
|
2018-06-16 08:43:05 +02:00
|
|
|
/**
|
|
|
|
* Load debug utilities (don't open the DevTools window by default though).
|
|
|
|
*/
|
|
|
|
require('electron-debug')({ showDevTools: false });
|
2018-05-24 16:02:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path to root directory
|
|
|
|
*/
|
2018-06-16 08:36:05 +02:00
|
|
|
const basePath = isDev ? __dirname : APP.getAppPath();
|
2018-05-24 16:02:27 +02:00
|
|
|
|
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({
|
2018-05-24 16:02:27 +02:00
|
|
|
pathname: path.resolve(basePath, './build/index.html'),
|
2018-05-09 10:21:31 +02:00
|
|
|
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;
|
|
|
|
|
2018-07-12 00:23:40 +02:00
|
|
|
/**
|
|
|
|
* Force Single Instance Application
|
|
|
|
*/
|
|
|
|
const isSecondInstance = APP.makeSingleInstance(() => {
|
|
|
|
/**
|
|
|
|
* If someone creates second instance of the application, set focus on
|
|
|
|
* existing window.
|
|
|
|
*/
|
|
|
|
if (jitsiMeetWindow) {
|
|
|
|
if (jitsiMeetWindow.isMinimized()) {
|
|
|
|
jitsiMeetWindow.restore();
|
|
|
|
}
|
|
|
|
jitsiMeetWindow.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We should quit the second instance.
|
|
|
|
*/
|
|
|
|
if (isSecondInstance) {
|
|
|
|
APP.quit();
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2016-12-12 21:46:47 +01:00
|
|
|
/**
|
|
|
|
* Sets the APP object listeners.
|
|
|
|
*/
|
2018-05-09 10:21:31 +02:00
|
|
|
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.
|
2018-05-09 10:21:31 +02:00
|
|
|
if (process.platform !== 'darwin') {
|
2016-12-12 21:46:47 +01:00
|
|
|
APP.quit();
|
|
|
|
}
|
|
|
|
});
|
2018-05-09 10:21:31 +02:00
|
|
|
APP.on('activate', () => {
|
2016-12-12 21:46:47 +01:00
|
|
|
if (jitsiMeetWindow === null) {
|
|
|
|
createJitsiMeetWindow();
|
|
|
|
}
|
|
|
|
});
|
2017-03-27 10:37:48 +02:00
|
|
|
APP.on('certificate-error',
|
2018-05-24 17:12:27 +02:00
|
|
|
// eslint-disable-next-line max-params
|
2017-03-27 10:37:48 +02:00
|
|
|
(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
|
|
|
}
|
|
|
|
|
2018-07-16 03:18:55 +02:00
|
|
|
/**
|
|
|
|
* Template for Application menu (MacOS)
|
|
|
|
*/
|
|
|
|
const template = [ {
|
|
|
|
label: APP.getName(),
|
|
|
|
submenu: [ {
|
|
|
|
label: 'Quit',
|
|
|
|
accelerator: 'Command+Q',
|
|
|
|
click() {
|
|
|
|
APP.quit();
|
|
|
|
}
|
|
|
|
} ]
|
|
|
|
}, {
|
|
|
|
label: 'Edit',
|
|
|
|
submenu: [ {
|
|
|
|
label: 'Undo',
|
|
|
|
accelerator: 'CmdOrCtrl+Z',
|
|
|
|
selector: 'undo:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Redo',
|
|
|
|
accelerator: 'Shift+CmdOrCtrl+Z',
|
|
|
|
selector: 'redo:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'separator'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Cut',
|
|
|
|
accelerator: 'CmdOrCtrl+X',
|
|
|
|
selector: 'cut:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Copy',
|
|
|
|
accelerator: 'CmdOrCtrl+C',
|
|
|
|
selector: 'copy:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Paste',
|
|
|
|
accelerator: 'CmdOrCtrl+V',
|
|
|
|
selector: 'paste:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Select All',
|
|
|
|
accelerator: 'CmdOrCtrl+A',
|
|
|
|
selector: 'selectAll:'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
} ];
|
|
|
|
|
2016-12-12 21:46:47 +01:00
|
|
|
/**
|
|
|
|
* Opens new window with index.html(Jitsi Meet is loaded in iframe there).
|
|
|
|
*/
|
2018-05-09 10:21:31 +02:00
|
|
|
function createJitsiMeetWindow() {
|
2018-07-16 03:18:55 +02:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
|
|
|
} else {
|
|
|
|
Menu.setApplicationMenu(null);
|
|
|
|
}
|
2018-06-16 08:36:52 +02:00
|
|
|
|
2018-07-15 21:27:03 +02:00
|
|
|
// Check for Updates.
|
|
|
|
autoUpdater.checkForUpdatesAndNotify();
|
|
|
|
|
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,
|
2018-07-01 23:12:29 +02:00
|
|
|
icon: path.resolve(basePath, './resources/icons/icon_512x512.png'),
|
2018-06-20 21:38:53 +02:00
|
|
|
minWidth: 800,
|
|
|
|
minHeight: 600,
|
2018-07-04 05:03:40 +02:00
|
|
|
show: false,
|
2018-06-20 21:38:53 +02:00
|
|
|
titleBarStyle: 'hidden',
|
|
|
|
webPreferences: {
|
|
|
|
nativeWindowOpen: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-09 14:20:57 +01:00
|
|
|
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-05-02 10:01:17 +02:00
|
|
|
});
|
|
|
|
|
2017-08-04 15:15:22 +02:00
|
|
|
setupAlwaysOnTopMain(jitsiMeetWindow);
|
|
|
|
|
2018-05-09 10:21:31 +02:00
|
|
|
jitsiMeetWindow.on('closed', () => {
|
2016-12-12 21:46:47 +01:00
|
|
|
jitsiMeetWindow = null;
|
|
|
|
});
|
2018-07-04 05:03:40 +02:00
|
|
|
jitsiMeetWindow.once('ready-to-show', () => {
|
|
|
|
jitsiMeetWindow.show();
|
|
|
|
});
|
2016-12-12 21:46:47 +01:00
|
|
|
}
|
|
|
|
|
2018-05-09 10:21:31 +02:00
|
|
|
// Start the application:
|
2016-12-12 21:46:47 +01:00
|
|
|
setAPPListeners();
|