Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Handle missing screen sharing permission gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
yannhodiesne committed Nov 6, 2021
1 parent f2e81f7 commit 3aa3124
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions build/entitlements.mac.inherit.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,10 @@ app.on('activate', () => {
the signal to exit and wants to start closing windows */
app.on('before-quit', () => (willQuitApp = true));

ipcMain.handle('checkScreenPermission', async () => {
ipcMain.on('checkScreenPermission', async () => {
if (!hasScreenCapturePermission()) {
await openSystemPreferences();
return false;
}

return true;
});

ipcMain.on('updateBadgeCount', (e, args) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
"discord-badge-count.js",
"discord-context-menu.js",
"discord-platform-osx.js",
"discord-downloadapps-icon.js",
"windows"
"discord-downloadapps-icon.js"
],
"mac": {
"category": "public.app-category.social-networking",
Expand Down
21 changes: 10 additions & 11 deletions preload-get-display-media-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const openScreenSelection = async (resolve, reject) => {
titleBarStyle: 'hiddenInset',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
contextIsolation: false,
enableBlinkFeatures: 'CSSColorSchemeUARendering',
},
});

Expand All @@ -49,18 +50,16 @@ const openScreenSelection = async (resolve, reject) => {
}
};

window.navigator.mediaDevices.getDisplayMedia = () => {
return new Promise((resolve, reject) => {
ipcRenderer.invoke('checkScreenPermission').then((hasPermission) => {
if (hasPermission) {
if (window.navigator.mediaDevices) {
window.navigator.mediaDevices.getDisplayMedia = () => {
return new Promise((resolve, reject) => {
ipcRenderer.send('checkScreenPermission', {});

if (remote.systemPreferences.getMediaAccessStatus('screen') === 'granted') {
openScreenSelection(resolve, reject);
} else {
reject(new Error('Discord does not have the permission to share the screen'));
}
}).catch((err) => {
console.error('Screen sharing permission check failed with ', err);

reject(new Error('An error occured when trying to check screen sharing permissions'));
});
});
};
};
}
1 change: 1 addition & 0 deletions windows/getDisplayMedia/getDisplayMedia.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="color-scheme" content="light dark">
<title>Select a screen or a window</title>
<link rel="stylesheet" href="getDisplayMedia.css">
</head>
Expand Down

0 comments on commit 3aa3124

Please sign in to comment.