1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/* global __dirname, process */
const {
BrowserWindow,
Menu,
app,
shell
} = require('electron');
const isDev = require('electron-is-dev');
const { autoUpdater } = require('electron-updater');
const windowStateKeeper = require('electron-window-state');
const {
initPopupsConfigurationMain,
getPopupTarget,
setupAlwaysOnTopMain
} = require('jitsi-meet-electron-utils');
const path = require('path');
const URL = require('url');
autoUpdater.logger = require('electron-log');
autoUpdater.logger.transports.file.level = 'info';
/**
* Load debug utilities (don't open the DevTools window by default though).
*/
require('electron-debug')({ showDevTools: false });
/**
* 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 mainWindow = null;
/**
* Sets the application menu. It is hidden on all platforms except macOS because
* otherwise copy and paste functionality is not available.
*/
function setApplicationMenu() {
if (process.platform === 'darwin') {
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:'
}
]
} ];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
} else {
Menu.setApplicationMenu(null);
}
}
/**
* Opens new window with index.html(Jitsi Meet is loaded in iframe there).
*/
function createJitsiMeetWindow() {
// Application menu.
setApplicationMenu();
// Check for Updates.
autoUpdater.checkForUpdatesAndNotify();
// Load the previous window state with fallback to defaults.
const windowState = windowStateKeeper({
defaultWidth: 800,
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.
const options = {
x: windowState.x,
y: windowState.y,
width: windowState.width,
height: windowState.height,
icon: path.resolve(basePath, './resources/icons/icon_512x512.png'),
minWidth: 800,
minHeight: 600,
show: false,
titleBarStyle: 'hidden',
webPreferences: {
nativeWindowOpen: true
}
};
mainWindow = new BrowserWindow(options);
windowState.manage(mainWindow);
mainWindow.loadURL(indexURL);
initPopupsConfigurationMain(mainWindow);
setupAlwaysOnTopMain(mainWindow);
mainWindow.webContents.on('new-window', (event, url, frameName) => {
const target = getPopupTarget(url, frameName);
if (!target || target === 'browser') {
event.preventDefault();
shell.openExternal(url);
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
}
/**
* 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();
}
});
|