Skip to content

Commit

Permalink
fix(screenshare): reset permissions for screen capturer on osx >= 10.15
Browse files Browse the repository at this point in the history
Co-authored-by: Tudor-Ovidiu Avram <[email protected]>
  • Loading branch information
quitrk and quitrk authored Apr 9, 2020
1 parent 364d6ad commit 406ad1f
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const {
// jitsiMeetWindow - The BrowserWindow instance of the window where Jitsi Meet is loaded.
// appName - Application name which will be displayed inside the content sharing tracking window
// i.e. [appName] is sharing your screen.
setupScreenSharingMain(mainWindow, appName);
// osxBundleId - Mac Application bundleId for which screen capturer permissions will be reset if user denied them.
setupScreenSharingMain(mainWindow, appName, osxBundleId);
```


Expand Down
159 changes: 156 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jitsi-meet-electron-utils",
"version": "2.0.3",
"version": "2.0.4",
"description": "Utilities for jitsi-meet-electron project",
"main": "index.js",
"scripts": {
Expand All @@ -26,6 +26,7 @@
"license": "Apache-2.0",
"gypfile": true,
"dependencies": {
"mac-screen-capture-permissions": "^1.1.0",
"nan": "^2.14.0",
"postis": "^2.2.0",
"prebuild-install": "^5.3.0",
Expand Down
37 changes: 32 additions & 5 deletions screensharing/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const electron = require('electron');

const { SCREEN_SHARE_EVENTS_CHANNEL, SCREEN_SHARE_EVENTS, TRACKER_SIZE } = require('./constants');
const { isMac } = require('./utils');

/**
* Main process component that sets up electron specific screen sharing functionality, like screen sharing
Expand All @@ -17,11 +18,15 @@ class ScreenShareMainHook {
* @param {string} identity - Name of the application doing screen sharing, will be displayed in the
* screen sharing tracker window text i.e. {identity} is sharing your screen.
*/
constructor(jitsiMeetWindow, identity) {
constructor(jitsiMeetWindow, identity, osxBundleId) {
this._jitsiMeetWindow = jitsiMeetWindow;
this._identity = identity;
this._onScreenSharingEvent = this._onScreenSharingEvent.bind(this);

if (osxBundleId && isMac()) {
this._verifyScreenCapturePermissions(osxBundleId);
}

// Listen for events coming in from the main render window and the screen share tracker window.
electron.ipcMain.on(SCREEN_SHARE_EVENTS_CHANNEL, this._onScreenSharingEvent);

Expand Down Expand Up @@ -72,8 +77,8 @@ class ScreenShareMainHook {
this._screenShareTracker = new electron.BrowserWindow({
height: TRACKER_SIZE.height,
width: TRACKER_SIZE.width,
x:(display.workArea.width - TRACKER_SIZE.width) / 2,
y:display.workArea.height - TRACKER_SIZE.height - 5,
x: (display.workArea.width - TRACKER_SIZE.width) / 2,
y: display.workArea.height - TRACKER_SIZE.height - 5,
transparent: true,
minimizable: true,
maximizable: false,
Expand All @@ -99,6 +104,27 @@ class ScreenShareMainHook {
this._screenShareTracker
.loadURL(`file://${__dirname}/screenSharingTracker.html?sharingIdentity=${this._identity}`);
}

/**
* Verifies whether app has already asked for capture permissions.
* If it did but the user denied, resets permissions for the app
*
* @param {string} bundleId- OSX Application BundleId
*/
_verifyScreenCapturePermissions(bundleId) {
const {
hasPromptedForPermission,
hasScreenCapturePermission,
resetPermissions,
} = require('mac-screen-capture-permissions');

const hasPermission = hasScreenCapturePermission();
const promptedAlready = hasPromptedForPermission();

if (promptedAlready && !hasPermission) {
resetPermissions({ bundleId });
}
}
}

/**
Expand All @@ -107,7 +133,8 @@ class ScreenShareMainHook {
* @param {BrowserWindow} jitsiMeetWindow - the BrowserWindow object which displays Jitsi Meet
* @param {string} identity - Name of the application doing screen sharing, will be displayed in the
* screen sharing tracker window text i.e. {identity} is sharing your screen.
* @param {string} bundleId- OSX Application BundleId
*/
module.exports = function setupScreenSharingMain(jitsiMeetWindow, identity) {
return new ScreenShareMainHook(jitsiMeetWindow, identity);
module.exports = function setupScreenSharingMain(jitsiMeetWindow, identity, osxBundleId) {
return new ScreenShareMainHook(jitsiMeetWindow, identity, osxBundleId);
};
7 changes: 7 additions & 0 deletions screensharing/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* global process */

const isMac = () => process.platform === 'darwin';

module.exports = {
isMac,
};

0 comments on commit 406ad1f

Please sign in to comment.