mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 17:31:36 -06:00
ELECTRON-491 - Change method to use getFocusedWindow instead of fromWebContents (#368)
This commit is contained in:
parent
c36b639296
commit
2362febc58
@ -496,32 +496,35 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
* @param webContents Web contents of the window
|
* @param webContents Web contents of the window
|
||||||
*/
|
*/
|
||||||
function handlePermissionRequests(webContents) {
|
function handlePermissionRequests(webContents) {
|
||||||
|
|
||||||
let session = webContents.session;
|
let session = webContents.session;
|
||||||
|
|
||||||
getConfigField('permissions')
|
getConfigField('permissions')
|
||||||
.then((permissions) => {
|
.then((permissions) => {
|
||||||
|
|
||||||
if (!permissions) {
|
if (!permissions) {
|
||||||
log.send(logLevels.ERROR, 'permissions configuration is invalid, so, everything will be true by default!');
|
log.send(logLevels.ERROR, 'permissions configuration is invalid, so, everything will be true by default!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setPermissionRequestHandler((sessionWebContents, permission, callback) => {
|
session.setPermissionRequestHandler((sessionWebContents, permission, callback) => {
|
||||||
|
|
||||||
function handleSessionPermissions(userPermission, message, cb) {
|
function handleSessionPermissions(userPermission, message, cb) {
|
||||||
|
|
||||||
log.send(logLevels.INFO, 'permission is -> ' + userPermission);
|
log.send(logLevels.INFO, 'permission is -> ' + userPermission);
|
||||||
|
|
||||||
if (!userPermission) {
|
if (!userPermission) {
|
||||||
let fullMessage = `Your administrator has disabled ${message}. Please contact your admin for help.`;
|
let fullMessage = `Your administrator has disabled ${message}. Please contact your admin for help.`;
|
||||||
electron.dialog.showMessageBox(BrowserWindow.fromWebContents(webContents), {type: 'error', title: 'Permission Denied!', message: fullMessage});
|
const browserWindow = BrowserWindow.getFocusedWindow();
|
||||||
|
if (browserWindow && !browserWindow.isDestroyed()) {
|
||||||
|
electron.dialog.showMessageBox(browserWindow, {type: 'error', title: 'Permission Denied!', message: fullMessage});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(userPermission);
|
return cb(userPermission);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let PERMISSION_MEDIA = 'media';
|
let PERMISSION_MEDIA = 'media';
|
||||||
let PERMISSION_LOCATION = 'geolocation';
|
let PERMISSION_LOCATION = 'geolocation';
|
||||||
let PERMISSION_NOTIFICATIONS = 'notifications';
|
let PERMISSION_NOTIFICATIONS = 'notifications';
|
||||||
@ -529,40 +532,40 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
let PERMISSION_POINTER_LOCK = 'pointerLock';
|
let PERMISSION_POINTER_LOCK = 'pointerLock';
|
||||||
let PERMISSION_FULL_SCREEN = 'fullscreen';
|
let PERMISSION_FULL_SCREEN = 'fullscreen';
|
||||||
let PERMISSION_OPEN_EXTERNAL = 'openExternal';
|
let PERMISSION_OPEN_EXTERNAL = 'openExternal';
|
||||||
|
|
||||||
switch (permission) {
|
switch (permission) {
|
||||||
|
|
||||||
case PERMISSION_MEDIA:
|
case PERMISSION_MEDIA:
|
||||||
return handleSessionPermissions(permissions.media, 'sharing your camera, microphone, and speakers', callback);
|
return handleSessionPermissions(permissions.media, 'sharing your camera, microphone, and speakers', callback);
|
||||||
|
|
||||||
case PERMISSION_LOCATION:
|
case PERMISSION_LOCATION:
|
||||||
return handleSessionPermissions(permissions.geolocation, 'sharing your location', callback);
|
return handleSessionPermissions(permissions.geolocation, 'sharing your location', callback);
|
||||||
|
|
||||||
case PERMISSION_NOTIFICATIONS:
|
case PERMISSION_NOTIFICATIONS:
|
||||||
return handleSessionPermissions(permissions.notifications, 'notifications', callback);
|
return handleSessionPermissions(permissions.notifications, 'notifications', callback);
|
||||||
|
|
||||||
case PERMISSION_MIDI_SYSEX:
|
case PERMISSION_MIDI_SYSEX:
|
||||||
return handleSessionPermissions(permissions.midiSysex, 'MIDI Sysex', callback);
|
return handleSessionPermissions(permissions.midiSysex, 'MIDI Sysex', callback);
|
||||||
|
|
||||||
case PERMISSION_POINTER_LOCK:
|
case PERMISSION_POINTER_LOCK:
|
||||||
return handleSessionPermissions(permissions.pointerLock, 'Pointer Lock', callback);
|
return handleSessionPermissions(permissions.pointerLock, 'Pointer Lock', callback);
|
||||||
|
|
||||||
case PERMISSION_FULL_SCREEN:
|
case PERMISSION_FULL_SCREEN:
|
||||||
return handleSessionPermissions(permissions.fullscreen, 'Full Screen', callback);
|
return handleSessionPermissions(permissions.fullscreen, 'Full Screen', callback);
|
||||||
|
|
||||||
case PERMISSION_OPEN_EXTERNAL:
|
case PERMISSION_OPEN_EXTERNAL:
|
||||||
return handleSessionPermissions(permissions.openExternal, 'Opening External App', callback);
|
return handleSessionPermissions(permissions.openExternal, 'Opening External App', callback);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return callback(false);
|
return callback(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
log.send(logLevels.ERROR, 'unable to get permissions configuration, so, everything will be true by default! ' + error);
|
log.send(logLevels.ERROR, 'unable to get permissions configuration, so, everything will be true by default! ' + error);
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user