From 656fdc80934343fc1144476b8336c09218e34e23 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Wed, 11 Dec 2024 15:01:49 +0100 Subject: [PATCH] Request audio/video permissions at app startup on Mac --- Linphone/core/App.cpp | 2 ++ Linphone/tool/native/DesktopToolsMacOs.hpp | 7 +++++-- .../tool/native/DesktopToolsMacOsNative.mm | 21 +++++++++++++------ cmake/install/cleanCPack.cmake.in | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 840914e47..86c6cb93d 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -432,6 +432,8 @@ void App::initCore() { if (!settings) settings = SettingsCore::create(); lDebug() << log().arg("Creating Ui"); QMetaObject::invokeMethod(App::getInstance()->thread(), [this, settings] { + // Initialize DestopTools here to have logs into files in case of errors. + DesktopTools::init(); // QML mEngine = new QQmlApplicationEngine(this); assert(mEngine); diff --git a/Linphone/tool/native/DesktopToolsMacOs.hpp b/Linphone/tool/native/DesktopToolsMacOs.hpp index 8bb7b4d22..64fb2e066 100644 --- a/Linphone/tool/native/DesktopToolsMacOs.hpp +++ b/Linphone/tool/native/DesktopToolsMacOs.hpp @@ -21,10 +21,10 @@ #ifndef DESKTOP_TOOLS_MAC_OS_H_ #define DESKTOP_TOOLS_MAC_OS_H_ -#include #include -#include #include +#include +#include // ============================================================================= class VideoSourceDescriptorModel; @@ -44,6 +44,9 @@ public: static void init(); // Do first initialization static void applicationStateChanged(Qt::ApplicationState currentState); + // Not used yet because AVSession request automatically permissions when trying to record something. + static void requestPermissions(); + static QList getWindows(); static QImage takeScreenshot(void *window); static QImage getWindowIcon(void *window); diff --git a/Linphone/tool/native/DesktopToolsMacOsNative.mm b/Linphone/tool/native/DesktopToolsMacOsNative.mm index 0d5e65185..7ddc5c56e 100644 --- a/Linphone/tool/native/DesktopToolsMacOsNative.mm +++ b/Linphone/tool/native/DesktopToolsMacOsNative.mm @@ -8,15 +8,24 @@ #include void DesktopTools::init(){ +} + +void DesktopTools::requestPermissions(){ // Request permissions if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized) { - qDebug() << "Requesting Video permission"; - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) {}]; - } + qInfo() << "Requesting Video permission"; + [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){ - qDebug() << "Requesting Audio permission"; - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL) {}]; - } + qInfo() << "Requesting Audio permission"; + [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) { diff --git a/cmake/install/cleanCPack.cmake.in b/cmake/install/cleanCPack.cmake.in index 48f186092..96f1dbbb1 100644 --- a/cmake/install/cleanCPack.cmake.in +++ b/cmake/install/cleanCPack.cmake.in @@ -56,7 +56,7 @@ if(APPLE) #CPack doesn't sign all files. 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 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() 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()