22const electron = require ( 'electron' ) ;
33
44const { 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} ;
0 commit comments