ELECTRON-492 - Disable screen share when media permissions are disabled (#431)

This commit is contained in:
Kiran Niranjan 2018-07-17 10:42:33 +05:30 committed by Vishwas Shashidhar
parent 4395d18dc0
commit a14a4ae9ae
4 changed files with 75 additions and 2 deletions

View File

@ -58,6 +58,11 @@
</p>
<br>
<hr>
<p>Change language:<p>
<button id='set-locale-en-US'>Change language to English - US</button>
<button id='set-locale-ja-JP'>Change language to Japanese</button>
<br>
<hr>
<p>Badge Count:<p>
<button id='inc-badge'>increment badge count</button>
<br>
@ -262,5 +267,16 @@
});
});
var setLocaleToEn = document.getElementById('set-locale-en-US');
setLocaleToEn.addEventListener('click', function () {
ssf.setLocale('en-US');
document.location.reload();
});
var setLocaleToJa = document.getElementById('set-locale-ja-JP');
setLocaleToJa.addEventListener('click', function () {
ssf.setLocale('ja-JP');
document.location.reload();
});
</script>
</html>

View File

@ -22,6 +22,8 @@ const USER_CANCELLED = 'User Cancelled';
let nextId = 0;
let includes = [].includes;
let screenShareArgv;
let isScreenShareEnabled = false;
let dialogContent;
function getNextId() {
return ++nextId;
@ -78,6 +80,21 @@ function getSource(options, callback) {
sourceTypes.push('screen');
}
// displays a dialog if media permissions are disable
if (!isScreenShareEnabled) {
let focusedWindow = remote.BrowserWindow.getFocusedWindow();
if (focusedWindow && !focusedWindow.isDestroyed()) {
remote.dialog.showMessageBox(focusedWindow, dialogContent ||
{
type: 'error',
title: 'Permission Denied!',
message: 'Your administrator has disabled screen share. Please contact your admin for help'
});
callback(new Error('Permission Denied'));
return;
}
}
id = getNextId();
desktopCapturer.getSources({ types: sourceTypes, thumbnailSize: updatedOptions.thumbnailSize }, (event, sources) => {
@ -133,4 +150,12 @@ ipcRenderer.once('screen-share-argv', (event, arg) => {
}
});
// event that updates screen share permission
ipcRenderer.on('is-screen-share-enabled', (event, screenShare, content) => {
dialogContent = content;
if (typeof screenShare === 'boolean' && screenShare) {
isScreenShareEnabled = true;
}
});
module.exports = getSource;

View File

@ -17,6 +17,8 @@ const { isWindowsOS } = require('../utils/misc');
let includes = [].includes;
let screenShareArgv;
let isScreenShareEnabled = false;
let dialogContent;
/**
* Checks if the options and their types are valid
@ -68,6 +70,21 @@ function getSources(options, callback) {
sourceTypes.push('screen');
}
// displays a dialog if media permissions are disable
if (!isScreenShareEnabled) {
let focusedWindow = remote.BrowserWindow.getFocusedWindow();
if (focusedWindow && !focusedWindow.isDestroyed()) {
remote.dialog.showMessageBox(focusedWindow, dialogContent ||
{
type: 'error',
title: 'Permission Denied!',
message: 'Your administrator has disabled screen share. Please contact your admin for help'
});
callback(new Error('Permission Denied'));
return;
}
}
desktopCapturer.getSources({ types: sourceTypes, thumbnailSize: updatedOptions.thumbnailSize }, (event, sources) => {
if (screenShareArgv) {
@ -114,6 +131,14 @@ ipcRenderer.once('screen-share-argv', (event, arg) => {
}
});
// event that updates screen share permission
ipcRenderer.on('is-screen-share-enabled', (event, screenShare, content) => {
dialogContent = content;
if (typeof screenShare === 'boolean' && screenShare) {
isScreenShareEnabled = true;
}
});
/**
* @deprecated instead use getSource
* @type {getSources}

View File

@ -276,6 +276,13 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
if (screenShareArg && typeof screenShareArg === 'string') {
mainWindow.webContents.send('screen-share-argv', screenShareArg);
}
if (config && config.permissions) {
const permission = ' screen sharing';
const fullMessage = i18n.getMessageFor('Your administrator has disabled') + permission + '. ' + i18n.getMessageFor('Please contact your admin for help');
const dialogContent = { type: 'error', title: i18n.getMessageFor('Permission Denied') + '!', message: fullMessage };
mainWindow.webContents.send('is-screen-share-enabled', config.permissions.media, dialogContent);
}
});
mainWindow.webContents.on('did-fail-load', function (event, errorCode,
@ -602,10 +609,10 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
log.send(logLevels.INFO, 'permission is -> ' + userPermission);
if (!userPermission) {
let fullMessage = i18n.getMessageFor('Your administrator has disabled') + message + '. ' + i18n.getMessageFor('Please contact your admin for help');
const fullMessage = `${i18n.getMessageFor('Your administrator has disabled')} ${message}. ${i18n.getMessageFor('Please contact your admin for help')}`;
const browserWindow = BrowserWindow.getFocusedWindow();
if (browserWindow && !browserWindow.isDestroyed()) {
electron.dialog.showMessageBox(browserWindow, {type: 'error', title: i18n.getMessageFor('Permission Denied') + '!', message: fullMessage});
electron.dialog.showMessageBox(browserWindow, {type: 'error', title: `${i18n.getMessageFor('Permission Denied')}!`, message: fullMessage});
}
}