mirror of
https://github.com/netzbegruenung/jitsi-meet-electron.git
synced 2024-04-27 14:34:52 +02:00
Misc style fixes
This commit is contained in:
parent
e58a887690
commit
36c2978782
275
main.js
275
main.js
|
@ -1,18 +1,18 @@
|
||||||
/* global __dirname, process */
|
/* global __dirname, process */
|
||||||
|
|
||||||
const {
|
const {
|
||||||
app: APP,
|
|
||||||
BrowserWindow,
|
BrowserWindow,
|
||||||
Menu,
|
Menu,
|
||||||
|
app,
|
||||||
shell
|
shell
|
||||||
} = require('electron');
|
} = require('electron');
|
||||||
const isDev = require('electron-is-dev');
|
const isDev = require('electron-is-dev');
|
||||||
const { autoUpdater } = require('electron-updater');
|
const { autoUpdater } = require('electron-updater');
|
||||||
const windowStateKeeper = require('electron-window-state');
|
const windowStateKeeper = require('electron-window-state');
|
||||||
const {
|
const {
|
||||||
setupAlwaysOnTopMain,
|
|
||||||
initPopupsConfigurationMain,
|
initPopupsConfigurationMain,
|
||||||
getPopupTarget
|
getPopupTarget,
|
||||||
|
setupAlwaysOnTopMain
|
||||||
} = require('jitsi-meet-electron-utils');
|
} = require('jitsi-meet-electron-utils');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const URL = require('url');
|
const URL = require('url');
|
||||||
|
@ -25,155 +25,104 @@ autoUpdater.logger.transports.file.level = 'info';
|
||||||
*/
|
*/
|
||||||
require('electron-debug')({ showDevTools: false });
|
require('electron-debug')({ showDevTools: false });
|
||||||
|
|
||||||
/**
|
|
||||||
* Path to root directory
|
|
||||||
*/
|
|
||||||
const basePath = isDev ? __dirname : APP.getAppPath();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* URL for index.html which will be our entry point.
|
|
||||||
*/
|
|
||||||
const indexURL = URL.format({
|
|
||||||
pathname: path.resolve(basePath, './build/index.html'),
|
|
||||||
protocol: 'file:',
|
|
||||||
slashes: true
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The window object that will load the iframe with Jitsi Meet.
|
* The window object that will load the iframe with Jitsi Meet.
|
||||||
* IMPORTANT: Must be defined as global in order to not be garbage collected
|
* IMPORTANT: Must be defined as global in order to not be garbage collected
|
||||||
* acidentally.
|
* acidentally.
|
||||||
*/
|
*/
|
||||||
let jitsiMeetWindow = null;
|
let mainWindow = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force Single Instance Application
|
* Sets the application menu. It is hidden on all platforms except macOS because
|
||||||
|
* otherwise copy and paste functionality is not available.
|
||||||
*/
|
*/
|
||||||
const isSecondInstance = APP.makeSingleInstance(() => {
|
function setApplicationMenu() {
|
||||||
/**
|
if (process.platform === 'darwin') {
|
||||||
* If someone creates second instance of the application, set focus on
|
const template = [ {
|
||||||
* existing window.
|
label: app.getName(),
|
||||||
*/
|
submenu: [ {
|
||||||
if (jitsiMeetWindow) {
|
label: 'Quit',
|
||||||
if (jitsiMeetWindow.isMinimized()) {
|
accelerator: 'Command+Q',
|
||||||
jitsiMeetWindow.restore();
|
click() {
|
||||||
}
|
app.quit();
|
||||||
jitsiMeetWindow.focus();
|
}
|
||||||
}
|
} ]
|
||||||
});
|
}, {
|
||||||
|
label: 'Edit',
|
||||||
/**
|
submenu: [ {
|
||||||
* We should quit the second instance.
|
label: 'Undo',
|
||||||
*/
|
accelerator: 'CmdOrCtrl+Z',
|
||||||
if (isSecondInstance) {
|
selector: 'undo:'
|
||||||
APP.quit();
|
},
|
||||||
process.exit(0);
|
{
|
||||||
}
|
label: 'Redo',
|
||||||
|
accelerator: 'Shift+CmdOrCtrl+Z',
|
||||||
/**
|
selector: 'redo:'
|
||||||
* Sets the APP object listeners.
|
},
|
||||||
*/
|
{
|
||||||
function setAPPListeners() {
|
type: 'separator'
|
||||||
APP.on('ready', createJitsiMeetWindow);
|
},
|
||||||
APP.on('window-all-closed', () => {
|
{
|
||||||
// Don't quit the application for macOS.
|
label: 'Cut',
|
||||||
if (process.platform !== 'darwin') {
|
accelerator: 'CmdOrCtrl+X',
|
||||||
APP.quit();
|
selector: 'cut:'
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
APP.on('activate', () => {
|
label: 'Copy',
|
||||||
if (jitsiMeetWindow === null) {
|
accelerator: 'CmdOrCtrl+C',
|
||||||
createJitsiMeetWindow();
|
selector: 'copy:'
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
APP.on('certificate-error',
|
label: 'Paste',
|
||||||
// eslint-disable-next-line max-params
|
accelerator: 'CmdOrCtrl+V',
|
||||||
(event, webContents, url, error, certificate, callback) => {
|
selector: 'paste:'
|
||||||
if (url.startsWith('https://localhost')) {
|
},
|
||||||
event.preventDefault();
|
{
|
||||||
callback(true);
|
label: 'Select All',
|
||||||
} else {
|
accelerator: 'CmdOrCtrl+A',
|
||||||
callback(false);
|
selector: 'selectAll:'
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
);
|
} ];
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
||||||
* Template for Application menu (MacOS)
|
} else {
|
||||||
*/
|
Menu.setApplicationMenu(null);
|
||||||
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:'
|
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
} ];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens new window with index.html(Jitsi Meet is loaded in iframe there).
|
* Opens new window with index.html(Jitsi Meet is loaded in iframe there).
|
||||||
*/
|
*/
|
||||||
function createJitsiMeetWindow() {
|
function createJitsiMeetWindow() {
|
||||||
if (process.platform === 'darwin') {
|
// Application menu.
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
setApplicationMenu();
|
||||||
} else {
|
|
||||||
Menu.setApplicationMenu(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Updates.
|
// Check for Updates.
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
|
|
||||||
// Load the previous state with fallback to defaults
|
// Load the previous window state with fallback to defaults.
|
||||||
const jitsiMeetWindowState = windowStateKeeper({
|
const windowState = windowStateKeeper({
|
||||||
defaultWidth: 800,
|
defaultWidth: 800,
|
||||||
defaultHeight: 600
|
defaultHeight: 600
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Path to root directory.
|
||||||
|
const basePath = isDev ? __dirname : app.getAppPath();
|
||||||
|
|
||||||
|
// URL for index.html which will be our entry point.
|
||||||
|
const indexURL = URL.format({
|
||||||
|
pathname: path.resolve(basePath, './build/index.html'),
|
||||||
|
protocol: 'file:',
|
||||||
|
slashes: true
|
||||||
|
});
|
||||||
|
|
||||||
// Options used when creating the main Jitsi Meet window.
|
// Options used when creating the main Jitsi Meet window.
|
||||||
const jitsiMeetWindowOptions = {
|
const options = {
|
||||||
x: jitsiMeetWindowState.x,
|
x: windowState.x,
|
||||||
y: jitsiMeetWindowState.y,
|
y: windowState.y,
|
||||||
width: jitsiMeetWindowState.width,
|
width: windowState.width,
|
||||||
height: jitsiMeetWindowState.height,
|
height: windowState.height,
|
||||||
icon: path.resolve(basePath, './resources/icons/icon_512x512.png'),
|
icon: path.resolve(basePath, './resources/icons/icon_512x512.png'),
|
||||||
minWidth: 800,
|
minWidth: 800,
|
||||||
minHeight: 600,
|
minHeight: 600,
|
||||||
|
@ -184,12 +133,14 @@ function createJitsiMeetWindow() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jitsiMeetWindow = new BrowserWindow(jitsiMeetWindowOptions);
|
mainWindow = new BrowserWindow(options);
|
||||||
jitsiMeetWindowState.manage(jitsiMeetWindow);
|
windowState.manage(mainWindow);
|
||||||
jitsiMeetWindow.loadURL(indexURL);
|
mainWindow.loadURL(indexURL);
|
||||||
initPopupsConfigurationMain(jitsiMeetWindow);
|
|
||||||
|
|
||||||
jitsiMeetWindow.webContents.on('new-window', (event, url, frameName) => {
|
initPopupsConfigurationMain(mainWindow);
|
||||||
|
setupAlwaysOnTopMain(mainWindow);
|
||||||
|
|
||||||
|
mainWindow.webContents.on('new-window', (event, url, frameName) => {
|
||||||
const target = getPopupTarget(url, frameName);
|
const target = getPopupTarget(url, frameName);
|
||||||
|
|
||||||
if (!target || target === 'browser') {
|
if (!target || target === 'browser') {
|
||||||
|
@ -197,16 +148,58 @@ function createJitsiMeetWindow() {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mainWindow.on('closed', () => {
|
||||||
setupAlwaysOnTopMain(jitsiMeetWindow);
|
mainWindow = null;
|
||||||
|
|
||||||
jitsiMeetWindow.on('closed', () => {
|
|
||||||
jitsiMeetWindow = null;
|
|
||||||
});
|
});
|
||||||
jitsiMeetWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
jitsiMeetWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the application:
|
/**
|
||||||
setAPPListeners();
|
* Force Single Instance Application.
|
||||||
|
*/
|
||||||
|
const isSecondInstance = app.makeSingleInstance(() => {
|
||||||
|
/**
|
||||||
|
* If someone creates second instance of the application, set focus on
|
||||||
|
* existing window.
|
||||||
|
*/
|
||||||
|
if (mainWindow) {
|
||||||
|
if (mainWindow.isMinimized()) {
|
||||||
|
mainWindow.restore();
|
||||||
|
}
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isSecondInstance) {
|
||||||
|
app.quit();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the application.
|
||||||
|
*/
|
||||||
|
app.on('activate', () => {
|
||||||
|
if (mainWindow === 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
app.on('ready', createJitsiMeetWindow);
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
// Don't quit the application for macOS.
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue