Skip to content

Commit 406ad1f

Browse files
Potecaru TudorTudor-Ovidiu Avram
andauthored
fix(screenshare): reset permissions for screen capturer on osx >= 10.15
Co-authored-by: Tudor-Ovidiu Avram <tudor.potecaru@8x8.com>
1 parent 364d6ad commit 406ad1f

File tree

5 files changed

+199
-10
lines changed

5 files changed

+199
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const {
5656
// jitsiMeetWindow - The BrowserWindow instance of the window where Jitsi Meet is loaded.
5757
// appName - Application name which will be displayed inside the content sharing tracking window
5858
// i.e. [appName] is sharing your screen.
59-
setupScreenSharingMain(mainWindow, appName);
59+
// osxBundleId - Mac Application bundleId for which screen capturer permissions will be reset if user denied them.
60+
setupScreenSharingMain(mainWindow, appName, osxBundleId);
6061
```
6162

6263

package-lock.json

Lines changed: 156 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 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.3",
3+
"version": "2.0.4",
44
"description": "Utilities for jitsi-meet-electron project",
55
"main": "index.js",
66
"scripts": {
@@ -26,6 +26,7 @@
2626
"license": "Apache-2.0",
2727
"gypfile": true,
2828
"dependencies": {
29+
"mac-screen-capture-permissions": "^1.1.0",
2930
"nan": "^2.14.0",
3031
"postis": "^2.2.0",
3132
"prebuild-install": "^5.3.0",

screensharing/main.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const electron = require('electron');
33

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

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

26+
if (osxBundleId && isMac()) {
27+
this._verifyScreenCapturePermissions(osxBundleId);
28+
}
29+
2530
// Listen for events coming in from the main render window and the screen share tracker window.
2631
electron.ipcMain.on(SCREEN_SHARE_EVENTS_CHANNEL, this._onScreenSharingEvent);
2732

@@ -72,8 +77,8 @@ class ScreenShareMainHook {
7277
this._screenShareTracker = new electron.BrowserWindow({
7378
height: TRACKER_SIZE.height,
7479
width: TRACKER_SIZE.width,
75-
x:(display.workArea.width - TRACKER_SIZE.width) / 2,
76-
y:display.workArea.height - TRACKER_SIZE.height - 5,
80+
x: (display.workArea.width - TRACKER_SIZE.width) / 2,
81+
y: display.workArea.height - TRACKER_SIZE.height - 5,
7782
transparent: true,
7883
minimizable: true,
7984
maximizable: false,
@@ -99,6 +104,27 @@ class ScreenShareMainHook {
99104
this._screenShareTracker
100105
.loadURL(`file://${__dirname}/screenSharingTracker.html?sharingIdentity=${this._identity}`);
101106
}
107+
108+
/**
109+
* Verifies whether app has already asked for capture permissions.
110+
* If it did but the user denied, resets permissions for the app
111+
*
112+
* @param {string} bundleId- OSX Application BundleId
113+
*/
114+
_verifyScreenCapturePermissions(bundleId) {
115+
const {
116+
hasPromptedForPermission,
117+
hasScreenCapturePermission,
118+
resetPermissions,
119+
} = require('mac-screen-capture-permissions');
120+
121+
const hasPermission = hasScreenCapturePermission();
122+
const promptedAlready = hasPromptedForPermission();
123+
124+
if (promptedAlready && !hasPermission) {
125+
resetPermissions({ bundleId });
126+
}
127+
}
102128
}
103129

104130
/**
@@ -107,7 +133,8 @@ class ScreenShareMainHook {
107133
* @param {BrowserWindow} jitsiMeetWindow - the BrowserWindow object which displays Jitsi Meet
108134
* @param {string} identity - Name of the application doing screen sharing, will be displayed in the
109135
* screen sharing tracker window text i.e. {identity} is sharing your screen.
136+
* @param {string} bundleId- OSX Application BundleId
110137
*/
111-
module.exports = function setupScreenSharingMain(jitsiMeetWindow, identity) {
112-
return new ScreenShareMainHook(jitsiMeetWindow, identity);
138+
module.exports = function setupScreenSharingMain(jitsiMeetWindow, identity, osxBundleId) {
139+
return new ScreenShareMainHook(jitsiMeetWindow, identity, osxBundleId);
113140
};

screensharing/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* global process */
2+
3+
const isMac = () => process.platform === 'darwin';
4+
5+
module.exports = {
6+
isMac,
7+
};

0 commit comments

Comments
 (0)