diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 40efaa9a9f..e3624105c7 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -241,9 +241,11 @@ void Call::startIncoming() { } void Call::answer() { - _delegate->requestMicrophonePermissionOrFail([this](){ actuallyAnswer(); }); + _delegate->requestMicrophonePermissionOrFail(crl::guard(this, [=] { + actuallyAnswer(); + })); } - + void Call::actuallyAnswer() { Expects(_type == Type::Incoming); diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 1ce388a3f3..f51bf1f0ae 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -40,9 +40,9 @@ void Instance::startOutgoingCall(not_null user) { Ui::show(Box(lng_call_error_not_available(lt_user, App::peerName(user)))); return; } - requestMicrophonePermissionOrFail([this, user](){ + requestMicrophonePermissionOrFail(crl::guard(this, [=] { createCall(user, Call::Type::Outgoing); - }); + })); } void Instance::callFinished(not_null call) { @@ -288,13 +288,13 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) { bool Instance::alreadyInCall() { return (_currentCall && _currentCall->state() != Call::State::Busy); } - + void Instance::requestMicrophonePermissionOrFail(Fn onSuccess) { Platform::PermissionStatus status=Platform::GetPermissionStatus(Platform::PermissionType::Microphone); if (status==Platform::PermissionStatus::Granted) { onSuccess(); } else if(status==Platform::PermissionStatus::CanRequest) { - Platform::RequestPermission(Platform::PermissionType::Microphone, [this, onSuccess](Platform::PermissionStatus status){ + Platform::RequestPermission(Platform::PermissionType::Microphone, crl::guard(this, [=](Platform::PermissionStatus status) { if (status==Platform::PermissionStatus::Granted) { crl::on_main(onSuccess); } else { @@ -302,15 +302,15 @@ void Instance::requestMicrophonePermissionOrFail(Fn onSuccess) { _currentCall->hangup(); } } - }); + })); } else { if (alreadyInCall()) { _currentCall->hangup(); } - Ui::show(Box(lang(lng_no_mic_permission), lang(lng_menu_settings), [](){ + Ui::show(Box(lang(lng_no_mic_permission), lang(lng_menu_settings), crl::guard(this, [] { Platform::OpenSystemSettingsForPermission(Platform::PermissionType::Microphone); Ui::hideLayer(); - })); + }))); } } diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index 4e9f26cf8a..99f48b62c8 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -28,7 +28,7 @@ enum class PeerToPeer { class Panel; -class Instance : private MTP::Sender, private Call::Delegate, private base::Subscriber { +class Instance : private MTP::Sender, private Call::Delegate, private base::Subscriber, public base::has_weak_ptr { public: Instance(); diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index a8fdd79af5..d11b912871 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -438,11 +438,10 @@ PermissionStatus GetPermissionStatus(PermissionType type){ } void RequestPermission(PermissionType type, Fn resultCallback){ - + resultCallback(PermissionStatus::Granted); } void OpenSystemSettingsForPermission(PermissionType type){ - } namespace ThirdParty { diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index d2883e0076..67b98cf842 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -288,7 +288,8 @@ void RegisterCustomScheme() { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" PermissionStatus GetPermissionStatus(PermissionType type) { - switch(type) { +#ifndef OS_MAC_OLD + switch (type) { case PermissionType::Microphone: if([AVCaptureDevice respondsToSelector: @selector(authorizationStatusForMediaType:)]) { // Available starting with 10.14 switch([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) { @@ -301,32 +302,38 @@ PermissionStatus GetPermissionStatus(PermissionType type) { return PermissionStatus::Denied; } } - return PermissionStatus::Granted; + break; } +#endif // OS_MAC_OLD return PermissionStatus::Granted; } void RequestPermission(PermissionType type, Fn resultCallback) { - switch(type) { +#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) { - resultCallback(granted ? PermissionStatus::Granted : PermissionStatus::Denied); - }]; - }else{ - resultCallback(PermissionStatus::Granted); + 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; } +#endif // OS_MAC_OLD + resultCallback(PermissionStatus::Granted); } #pragma clang diagnostic pop // -Wunguarded-availability - + void OpenSystemSettingsForPermission(PermissionType type) { - switch(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; } +#endif // OS_MAC_OLD } } // namespace Platform diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 266e23d36b..03a32b2af8 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -11,12 +11,13 @@ namespace Platform { void start(); void finish(); - + enum class PermissionStatus { Granted, CanRequest, Denied, }; + enum class PermissionType { Microphone, }; diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 1a8aab63d1..e4087f1d9d 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -627,7 +627,7 @@ void RegisterCustomScheme() { } PermissionStatus GetPermissionStatus(PermissionType type) { - if(type==PermissionType::Microphone) { + if (type==PermissionType::Microphone) { PermissionStatus result=PermissionStatus::Granted; HKEY hKey; LSTATUS res=RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\CapabilityAccessManager\\ConsentStore\\microphone", 0, KEY_QUERY_VALUE, &hKey); @@ -648,11 +648,11 @@ PermissionStatus GetPermissionStatus(PermissionType type) { } void RequestPermission(PermissionType type, Fn resultCallback) { - + resultCallback(PermissionStatus::Granted); } void OpenSystemSettingsForPermission(PermissionType type) { - if(type==PermissionType::Microphone) { + if (type==PermissionType::Microphone) { ShellExecute(NULL, L"open", L"ms-settings:privacy-microphone", NULL, NULL, SW_SHOWDEFAULT); } }