Request audio/video permissions at app startup on Mac

This commit is contained in:
Christophe Deschamps 2024-12-11 15:01:49 +01:00 committed by Julien Wadel
parent 4d426962d2
commit 656fdc8093
4 changed files with 23 additions and 9 deletions

View file

@ -432,6 +432,8 @@ void App::initCore() {
if (!settings) settings = SettingsCore::create(); if (!settings) settings = SettingsCore::create();
lDebug() << log().arg("Creating Ui"); lDebug() << log().arg("Creating Ui");
QMetaObject::invokeMethod(App::getInstance()->thread(), [this, settings] { QMetaObject::invokeMethod(App::getInstance()->thread(), [this, settings] {
// Initialize DestopTools here to have logs into files in case of errors.
DesktopTools::init();
// QML // QML
mEngine = new QQmlApplicationEngine(this); mEngine = new QQmlApplicationEngine(this);
assert(mEngine); assert(mEngine);

View file

@ -21,10 +21,10 @@
#ifndef DESKTOP_TOOLS_MAC_OS_H_ #ifndef DESKTOP_TOOLS_MAC_OS_H_
#define DESKTOP_TOOLS_MAC_OS_H_ #define DESKTOP_TOOLS_MAC_OS_H_
#include <QObject>
#include <QImage> #include <QImage>
#include <QVariantList>
#include <QList> #include <QList>
#include <QObject>
#include <QVariantList>
// ============================================================================= // =============================================================================
class VideoSourceDescriptorModel; class VideoSourceDescriptorModel;
@ -44,6 +44,9 @@ public:
static void init(); // Do first initialization static void init(); // Do first initialization
static void applicationStateChanged(Qt::ApplicationState currentState); static void applicationStateChanged(Qt::ApplicationState currentState);
// Not used yet because AVSession request automatically permissions when trying to record something.
static void requestPermissions();
static QList<QVariantMap> getWindows(); static QList<QVariantMap> getWindows();
static QImage takeScreenshot(void *window); static QImage takeScreenshot(void *window);
static QImage getWindowIcon(void *window); static QImage getWindowIcon(void *window);

View file

@ -8,15 +8,24 @@
#include <QThread> #include <QThread>
void DesktopTools::init(){ void DesktopTools::init(){
}
void DesktopTools::requestPermissions(){
// Request permissions // Request permissions
if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized) { if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized) {
qDebug() << "Requesting Video permission"; qInfo() << "Requesting Video permission";
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) {}]; [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
} qInfo() << "Video permission has" << (granted ? "" : " not") << " been granted";
}];
} else
qInfo() << "Video permission is already granted";
if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] != AVAuthorizationStatusAuthorized){ if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] != AVAuthorizationStatusAuthorized){
qDebug() << "Requesting Audio permission"; qInfo() << "Requesting Audio permission";
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL) {}]; [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
} qInfo() << "Audio permission has" << (granted ? "" : " not") << " been granted";
}];
} else
qInfo() << "Audio permission is already granted";
} }
bool isWindowMinimized(CGWindowID id) { bool isWindowMinimized(CGWindowID id) {

View file

@ -56,7 +56,7 @@ if(APPLE)
#CPack doesn't sign all files. #CPack doesn't sign all files.
if (DO_SIGNING) if (DO_SIGNING)
execute_process(COMMAND bash "@CMAKE_SOURCE_DIR@/cmake/install/sign_package.sh" codesign "@LINPHONE_BUILDER_SIGNING_IDENTITY@" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}") execute_process(COMMAND bash "@CMAKE_SOURCE_DIR@/cmake/install/sign_package.sh" codesign "@LINPHONE_BUILDER_SIGNING_IDENTITY@" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}")
#execute_process(COMMAND codesign --entitlements" "@CMAKE_CURRENT_BINARY_DIR@/../../entitlements.xml" "--force" "--deep" "--timestamp" "--options" "runtime,library" "--verbose" "-s" "@LINPHONE_BUILDER_SIGNING_IDENTITY@" "@APPLICATION_OUTPUT_DIR@/@APPLICATION_NAME@.app") execute_process(COMMAND codesign "--entitlements" "@CMAKE_CURRENT_BINARY_DIR@/cmake/install/macos/entitlements.xml" "--force" "--deep" "--timestamp" "--options" "runtime,library" "--verbose" "-s" "@LINPHONE_BUILDER_SIGNING_IDENTITY@" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@APPLICATION_NAME@.app")
else() else()
execute_process(COMMAND codesign --force --deep --sign "-" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@APPLICATION_NAME@.app" )#If not code signed, app can crash because of APPLE on "Code Signature Invalid" (spotted for ARM64) execute_process(COMMAND codesign --force --deep --sign "-" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@APPLICATION_NAME@.app" )#If not code signed, app can crash because of APPLE on "Code Signature Invalid" (spotted for ARM64)
endif() endif()