Skip to content

Commit

Permalink
feat(alwaysontop): add dismiss button and event
Browse files Browse the repository at this point in the history
  • Loading branch information
gimre authored and hristoterezov committed Feb 3, 2020
1 parent cfa14d0 commit 82377d2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ alwaysOnTop.on('will-close', handleAlwaysOnTopClose);

`setupAlwaysOnTopRender` return an instance of EventEmitter with the following events:

* _dismissed_ - emitted when the always on top window is explicitly dismissed via its close button

* _will-close_ - emitted right before the always on top window is going to close

#### WiFi Stats
Expand Down
39 changes: 39 additions & 0 deletions alwaysontop/alwaysontop.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,42 @@ video {
margin: 0;
padding: 0;
}

html:hover .dismiss {
opacity: 1;
}

.dismiss {
align-items: center;
background-color: rgba(40, 52, 71, 0.7);
border-radius: 50%;
color: white;
cursor: pointer;
display: flex;
font-size: 20px;
height: 25px;
justify-content: center;
opacity: 0;
position: absolute;
right: 8px;
top: 16px;
transition: opacity .25s linear;
width: 25px;
}

.dismiss:after, .dismiss:before {
display: block;
content: ' ';
height: 2px;
background-color: white;
position: absolute;
width: calc(100% - 12px);
}

.dismiss:after {
transform: rotate(45deg);
}

.dismiss:before {
transform: rotate(-45deg);
}
8 changes: 7 additions & 1 deletion alwaysontop/alwaysontop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
onload,
onbeforeunload,
shouldImplementDrag,
getCurrentSize
getCurrentSize,
dismiss
} = window.alwaysOnTop;

/**
Expand All @@ -15,6 +16,11 @@ const {
*/
let initialSize;

const dismissButton = document.querySelector('.dismiss');
if (dismissButton) {
dismissButton.addEventListener('click', dismiss);
}

window.addEventListener('beforeunload', onbeforeunload);

window.addEventListener('dblclick', ondblclick);
Expand Down
1 change: 1 addition & 0 deletions alwaysontop/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
ALWAYSONTOP_DISMISSED: 'dismissed',
ALWAYSONTOP_WILL_CLOSE: 'will-close',
SIZE: {
width: 320,
Expand Down
14 changes: 13 additions & 1 deletion alwaysontop/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { EventEmitter } = require('events');
const os = require('os');
const path = require('path');

const { ALWAYSONTOP_WILL_CLOSE, SIZE } = require('./constants');
const { ALWAYSONTOP_DISMISSED, ALWAYSONTOP_WILL_CLOSE, SIZE } = require('./constants');

/**
* Returieves and trying to parse a numeric value from the local storage.
Expand Down Expand Up @@ -51,6 +51,7 @@ class AlwaysOnTop extends EventEmitter {
this._onConferenceJoined = this._onConferenceJoined.bind(this);
this._onConferenceLeft = this._onConferenceLeft.bind(this);
this._onIntersection = this._onIntersection.bind(this);
this._dismiss = this._dismiss.bind(this);

this._api = api;
this._jitsiMeetElectronWindow = remote.getCurrentWindow();
Expand Down Expand Up @@ -250,6 +251,15 @@ class AlwaysOnTop extends EventEmitter {
this._setupAlwaysOnTopWindow();
}
}
/**
* Dismisses always on top window.
*
* @returns {void}
*/
_dismiss() {
this.emit(ALWAYSONTOP_DISMISSED);
this._closeAlwaysOnTopWindow();
}

/**
* Sets all necessary content (HTML, CSS, JS) to the always on top window.
Expand All @@ -262,6 +272,7 @@ class AlwaysOnTop extends EventEmitter {
}
this._alwaysOnTopWindow.alwaysOnTop = {
api: this._api,
dismiss: this._dismiss,
onload: this._updateLargeVideoSrc,
onbeforeunload: () => {
this.emit(ALWAYSONTOP_WILL_CLOSE);
Expand Down Expand Up @@ -319,6 +330,7 @@ class AlwaysOnTop extends EventEmitter {
this._alwaysOnTopWindow.document.body.innerHTML = `
<div id="react"></div>
<video autoplay="" id="video" style="transform: none;" muted></video>
<div class="dismiss"></div>
<link rel="stylesheet" href="file://${ cssPath }">
`;

Expand Down

0 comments on commit 82377d2

Please sign in to comment.