From dafe9387b89ed6ff5d36406d3600a0ca68a1a76a Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Wed, 14 Jun 2023 11:55:07 +0200 Subject: [PATCH] possible fix for the missing camera permission popup (#3252) * possible fix for the missing camera permission popup That apple review does not reject our app. * add changelog entry --- CHANGELOG.md | 3 +++ src/main/windows/main.ts | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0af4a355b4..462b5a970d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - update in-app help (2023-06-07) - If clipboard contains a file and text, then only paste the file into deltachat. #3261 +### Fixed +- possibly fix asking for camera permission on MacOS #3252 + ## [1.37.0] - 2023-06-05 diff --git a/src/main/windows/main.ts b/src/main/windows/main.ts index 02d64d6382..fa9d079b88 100644 --- a/src/main/windows/main.ts +++ b/src/main/windows/main.ts @@ -1,5 +1,10 @@ import debounce from 'debounce' -import electron, { BrowserWindow, Rectangle, session } from 'electron' +import electron, { + BrowserWindow, + Rectangle, + session, + systemPreferences, +} from 'electron' import { appWindowTitle } from '../../shared/constants' import { getLogger } from '../../shared/logger' import { appIcon, windowDefaults, htmlDistDir } from '../application-constants' @@ -126,11 +131,21 @@ export function init(options: { hidden: boolean }) { } } window.webContents.session.setPermissionCheckHandler((_wc, permission) => { + if (permission === 'camera') { + return systemPreferences.getMediaAccessStatus('camera') === 'granted' + } + // if (permission === "microphone") { + // return systemPreferences.getMediaAccessStatus("microphone") === "granted" + // } return permission_handler(permission as any) }) window.webContents.session.setPermissionRequestHandler( (_wc, permission, callback) => { - callback(permission_handler(permission)) + if (permission === 'media') { + systemPreferences.askForMediaAccess('camera').then(callback) + } else { + callback(permission_handler(permission)) + } } ) }