Skip to content

Commit 5a22a6a

Browse files
hristoterezovsaghul
authored andcommitted
feat(AOT): Optimisation for hidden AOT.
1 parent 4f57cc5 commit 5a22a6a

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

alwaysontop/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function onAlwaysOnTopWindow(
8686

8787
win.webContents.on('error', error => {
8888
console.warn(error, 'Unhandled AOT webContents error');
89-
})
89+
});
9090

9191
setAspectRatioToResizeableWindow(win, ASPECT_RATIO);
9292

alwaysontop/render.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class AlwaysOnTop extends EventEmitter {
6868
this._api = api;
6969
this._jitsiMeetElectronWindow = remote.getCurrentWindow();
7070
this._intersectionObserver = new IntersectionObserver(this._onIntersection);
71+
this._isHidden = true;
7172

7273
if (!api) {
7374
throw new Error('Wrong arguments!');
@@ -292,6 +293,7 @@ class AlwaysOnTop extends EventEmitter {
292293
onload: this._updateLargeVideoSrc,
293294
onbeforeunload: () => {
294295
this.emit(ALWAYSONTOP_WILL_CLOSE);
296+
this._isHidden = true;
295297
this._api.removeListener(
296298
'largeVideoChanged',
297299
this._updateLargeVideoSrc
@@ -324,7 +326,9 @@ class AlwaysOnTop extends EventEmitter {
324326
width: initialSize.width,
325327
height: initialSize.height
326328
});
327-
} catch (ignore) {}
329+
} catch (ignore) {
330+
// ignore
331+
}
328332
}
329333
},
330334
/**
@@ -336,31 +340,33 @@ class AlwaysOnTop extends EventEmitter {
336340
try {
337341
const [width, height] = this._alwaysOnTopBrowserWindow.getSize();
338342
return { width, height };
339-
} catch (ignore) {}
343+
} catch (ignore) {
344+
// ignore
345+
}
340346
}
341347

342348
return SIZE;
343349
}
344350
};
345351

346-
const cssPath = path.join(__dirname, './alwaysontop.css');
347-
const jsPath = path.join(__dirname, './alwaysontop.js');
352+
const cssPath = path.join(__dirname, './alwaysontop.css');
353+
const jsPath = path.join(__dirname, './alwaysontop.js');
348354

349-
// Add the markup for the JS to manipulate and load the CSS.
350-
this._alwaysOnTopWindow.document.body.innerHTML = `
351-
<div id="react"></div>
352-
<video autoplay="" id="video" style="transform: none;" muted></video>
353-
<div class="dismiss"></div>
354-
<link rel="stylesheet" href="file://${ cssPath }">
355-
`;
355+
// Add the markup for the JS to manipulate and load the CSS.
356+
this._alwaysOnTopWindow.document.body.innerHTML = `
357+
<div id="react"></div>
358+
<video autoplay="" id="video" style="transform: none;" muted></video>
359+
<div class="dismiss"></div>
360+
<link rel="stylesheet" href="file://${ cssPath }">
361+
`;
356362

357-
// JS must be loaded through a script tag, as setting it through
358-
// inner HTML maybe not trigger script load.
359-
const scriptTag
360-
= this._alwaysOnTopWindow.document.createElement('script');
363+
// JS must be loaded through a script tag, as setting it through
364+
// inner HTML maybe not trigger script load.
365+
const scriptTag
366+
= this._alwaysOnTopWindow.document.createElement('script');
361367

362-
scriptTag.setAttribute('src', `file://${ jsPath }`);
363-
this._alwaysOnTopWindow.document.head.appendChild(scriptTag);
368+
scriptTag.setAttribute('src', `file://${ jsPath }`);
369+
this._alwaysOnTopWindow.document.head.appendChild(scriptTag);
364370
}
365371

366372
/**
@@ -380,6 +386,7 @@ class AlwaysOnTop extends EventEmitter {
380386
// cross-origin redirect can cause any set global variables to be blown
381387
// away.
382388
this._alwaysOnTopWindow = window.open('', 'AlwaysOnTop');
389+
this._isHidden = false;
383390
}
384391

385392
/**
@@ -397,14 +404,17 @@ class AlwaysOnTop extends EventEmitter {
397404
x: position[0],
398405
y: position[1]
399406
};
400-
} catch (ignore) {}
407+
} catch (ignore) {
408+
// ignore
409+
}
401410
}
402411

403412
if (this._alwaysOnTopWindow) {
404413
// we need to check the BrowserWindow reference here because
405414
// window.closed is not reliable due to Electron quirkiness
406415
if(exists(this._alwaysOnTopBrowserWindow)) {
407416
this._alwaysOnTopWindow.close();
417+
this._isHidden = true;
408418
}
409419

410420
ipcRenderer.removeListener('jitsi-always-on-top', this._onMessageReceived);
@@ -426,9 +436,13 @@ class AlwaysOnTop extends EventEmitter {
426436
*/
427437
_showAlwaysOnTopWindow() {
428438
if (exists(this._alwaysOnTopBrowserWindow)) {
439+
this._isHidden = false;
440+
this._updateLargeVideoSrc();
429441
try {
430442
this._alwaysOnTopBrowserWindow.showInactive();
431-
} catch (ignore) {}
443+
} catch (ignore) {
444+
// ignore
445+
}
432446
}
433447
}
434448

@@ -442,7 +456,12 @@ class AlwaysOnTop extends EventEmitter {
442456
this.emit(ALWAYSONTOP_WILL_CLOSE);
443457
try {
444458
this._alwaysOnTopBrowserWindow.hide();
445-
} catch (ignore) {}
459+
this._isHidden = true;
460+
this._alwaysOnTopWindowVideo.style.display = 'none';
461+
this._alwaysOnTopWindowVideo.srcObject = null;
462+
} catch (ignore) {
463+
// ignore
464+
}
446465
}
447466
}
448467

@@ -453,7 +472,7 @@ class AlwaysOnTop extends EventEmitter {
453472
* @returns {void}
454473
*/
455474
_updateLargeVideoSrc() {
456-
if (!this._alwaysOnTopWindowVideo) {
475+
if (this._isHidden || !this._alwaysOnTopWindowVideo) {
457476
return;
458477
}
459478

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jitsi-meet-electron-utils",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "Utilities for jitsi-meet-electron project",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)