diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 41ef4b96de..81e285735a 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -217,7 +217,7 @@ void Call::startIncoming() { } void Call::answer() { - _delegate->requestMicrophonePermissionOrFail(crl::guard(this, [=] { + _delegate->requestPermissionsOrFail(crl::guard(this, [=] { actuallyAnswer(); })); } diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index f82e4ed70a..582f72fa16 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -46,7 +46,7 @@ public: Ended, }; virtual void playSound(Sound sound) = 0; - virtual void requestMicrophonePermissionOrFail(Fn result) = 0; + virtual void requestPermissionsOrFail(Fn result) = 0; virtual ~Delegate() = default; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index c1aab32fbc..0ae72fc19f 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -55,7 +55,7 @@ void Instance::startOutgoingCall(not_null user) { tr::lng_call_error_not_available(tr::now, lt_user, user->name))); return; } - requestMicrophonePermissionOrFail(crl::guard(this, [=] { + requestPermissionsOrFail(crl::guard(this, [=] { createCall(user, Call::Type::Outgoing); })); } @@ -317,13 +317,23 @@ rpl::producer Instance::currentCallValue() const { return _currentCallChanges.events_starting_with(currentCall()); } -void Instance::requestMicrophonePermissionOrFail(Fn onSuccess) { - Platform::PermissionStatus status=Platform::GetPermissionStatus(Platform::PermissionType::Microphone); - if (status==Platform::PermissionStatus::Granted) { +void Instance::requestPermissionsOrFail(Fn onSuccess) { + using Type = Platform::PermissionType; + requestPermissionOrFail(Type::Microphone, [=] { + requestPermissionOrFail(Type::Camera, [=] { + crl::on_main(onSuccess); + }); + }); +} + +void Instance::requestPermissionOrFail(Platform::PermissionType type, Fn onSuccess) { + using Status = Platform::PermissionStatus; + const auto status = Platform::GetPermissionStatus(type); + if (status == Status::Granted) { onSuccess(); - } else if(status==Platform::PermissionStatus::CanRequest) { - Platform::RequestPermission(Platform::PermissionType::Microphone, crl::guard(this, [=](Platform::PermissionStatus status) { - if (status==Platform::PermissionStatus::Granted) { + } else if (status == Status::CanRequest) { + Platform::RequestPermission(type, crl::guard(this, [=](Status status) { + if (status == Status::Granted) { crl::on_main(onSuccess); } else { if (_currentCall) { @@ -335,8 +345,8 @@ void Instance::requestMicrophonePermissionOrFail(Fn onSuccess) { if (alreadyInCall()) { _currentCall->hangup(); } - Ui::show(Box(tr::lng_no_mic_permission(tr::now), tr::lng_menu_settings(tr::now), crl::guard(this, [] { - Platform::OpenSystemSettingsForPermission(Platform::PermissionType::Microphone); + Ui::show(Box(tr::lng_no_mic_permission(tr::now), tr::lng_menu_settings(tr::now), crl::guard(this, [=] { + Platform::OpenSystemSettingsForPermission(type); Ui::hideLayer(); }))); } diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index 41dac34007..4bd159acdc 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "calls/calls_call.h" +namespace Platform { +enum class PermissionType; +} // namespace Platform + namespace Media { namespace Audio { class Track; @@ -57,7 +61,8 @@ private: void createCall(not_null user, Call::Type type); void destroyCall(not_null call); void destroyCurrentPanel(); - void requestMicrophonePermissionOrFail(Fn onSuccess) override; + void requestPermissionsOrFail(Fn onSuccess) override; + void requestPermissionOrFail(Platform::PermissionType type, Fn onSuccess); void handleSignalingData(const MTPDupdatePhoneCallSignalingData &data); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 91f98ea9dc..f2334247a7 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -170,19 +170,23 @@ void RegisterCustomScheme(bool force) { PermissionStatus GetPermissionStatus(PermissionType type) { #ifndef OS_MAC_OLD switch (type) { - case PermissionType::Microphone: - if([AVCaptureDevice respondsToSelector: @selector(authorizationStatusForMediaType:)]) { // Available starting with 10.14 - switch([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) { - case AVAuthorizationStatusNotDetermined: - return PermissionStatus::CanRequest; - case AVAuthorizationStatusAuthorized: - return PermissionStatus::Granted; - case AVAuthorizationStatusDenied: - case AVAuthorizationStatusRestricted: - return PermissionStatus::Denied; - } + case PermissionType::Microphone: + case PermissionType::Camera: + const auto nativeType = (type == PermissionType::Microphone) + ? AVMediaTypeAudio + : AVMediaTypeVideo; + if ([AVCaptureDevice respondsToSelector: @selector(authorizationStatusForMediaType:)]) { // Available starting with 10.14 + switch ([AVCaptureDevice authorizationStatusForMediaType:nativeType]) { + case AVAuthorizationStatusNotDetermined: + return PermissionStatus::CanRequest; + case AVAuthorizationStatusAuthorized: + return PermissionStatus::Granted; + case AVAuthorizationStatusDenied: + case AVAuthorizationStatusRestricted: + return PermissionStatus::Denied; } - break; + } + break; } #endif // OS_MAC_OLD return PermissionStatus::Granted; @@ -191,15 +195,19 @@ PermissionStatus GetPermissionStatus(PermissionType type) { void RequestPermission(PermissionType type, Fn resultCallback) { #ifndef OS_MAC_OLD switch (type) { - case PermissionType::Microphone: - if ([AVCaptureDevice respondsToSelector: @selector(requestAccessForMediaType:completionHandler:)]) { // Available starting with 10.14 - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { - crl::on_main([=] { - resultCallback(granted ? PermissionStatus::Granted : PermissionStatus::Denied); - }); - }]; - } - break; + case PermissionType::Microphone: + case PermissionType::Camera: + const auto nativeType = (type == PermissionType::Microphone) + ? AVMediaTypeAudio + : AVMediaTypeVideo; + if ([AVCaptureDevice respondsToSelector: @selector(requestAccessForMediaType:completionHandler:)]) { // Available starting with 10.14 + [AVCaptureDevice requestAccessForMediaType:nativeType completionHandler:^(BOOL granted) { + crl::on_main([=] { + resultCallback(granted ? PermissionStatus::Granted : PermissionStatus::Denied); + }); + }]; + } + break; } #endif // OS_MAC_OLD resultCallback(PermissionStatus::Granted); @@ -209,9 +217,12 @@ void RequestPermission(PermissionType type, Fn resultCal void OpenSystemSettingsForPermission(PermissionType type) { #ifndef OS_MAC_OLD switch (type) { - case PermissionType::Microphone: - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"]]; - break; + case PermissionType::Microphone: + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"]]; + break; + case PermissionType::Camera: + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Camera"]]; + break; } #endif // OS_MAC_OLD } diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 1939738e06..ec419bab7b 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -22,6 +22,7 @@ enum class PermissionStatus { enum class PermissionType { Microphone, + Camera, }; enum class SystemSettingsType { diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index af4435e35a..0506a89588 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -41,6 +41,8 @@ NSMicrophoneUsageDescription We need access to your microphone so that you can record voice messages and make calls. + NSCameraUsageDescription + We need access to your camera so that you can record video messages and make video calls. NSPrincipalClass NSApplication NSSupportsAutomaticGraphicsSwitching diff --git a/Telegram/Telegram/Telegram.entitlements b/Telegram/Telegram/Telegram.entitlements index b572d9c04e..97c1f6d587 100644 --- a/Telegram/Telegram/Telegram.entitlements +++ b/Telegram/Telegram/Telegram.entitlements @@ -4,5 +4,7 @@ com.apple.security.device.audio-input + com.apple.security.device.camera + diff --git a/Telegram/build/build.sh b/Telegram/build/build.sh index 19da165c6f..dd01830004 100755 --- a/Telegram/build/build.sh +++ b/Telegram/build/build.sh @@ -267,6 +267,10 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "osx" ] || [ "$BuildTarget fi if [ "$NotarizeRequestId" == "" ]; then + rm "$ReleasePath/$BinaryName.app/Contents/Info.plist" + rm "$ProjectPath/Telegram/CMakeFiles/Telegram.dir/Info.plist" + rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature" + ./configure.sh cd $ProjectPath @@ -490,8 +494,6 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "osx" ] || [ "$BuildTarget mv "$ReleasePath/$BinaryName.app.dSYM" "$DeployPath/" rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" rm "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater" - rm "$ReleasePath/$BinaryName.app/Contents/Info.plist" - rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature" mv "$ReleasePath/$UpdateFile" "$DeployPath/" mv "$ReleasePath/$SetupFile" "$DeployPath/" @@ -518,8 +520,6 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "osx" ] || [ "$BuildTarget mv "$ReleasePath/$BinaryName.pkg" "$DeployPath/" mv "$ReleasePath/$BinaryName.app.dSYM" "$DeployPath/" rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" - rm "$ReleasePath/$BinaryName.app/Contents/Info.plist" - rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature" fi fi