Beta version 1.4.4: Add some checks.

This commit is contained in:
John Preston 2018-10-17 09:09:59 +03:00
parent 44eac2bf07
commit a429e22b93
7 changed files with 36 additions and 27 deletions

View File

@ -241,7 +241,9 @@ void Call::startIncoming() {
} }
void Call::answer() { void Call::answer() {
_delegate->requestMicrophonePermissionOrFail([this](){ actuallyAnswer(); }); _delegate->requestMicrophonePermissionOrFail(crl::guard(this, [=] {
actuallyAnswer();
}));
} }
void Call::actuallyAnswer() { void Call::actuallyAnswer() {

View File

@ -40,9 +40,9 @@ void Instance::startOutgoingCall(not_null<UserData*> user) {
Ui::show(Box<InformBox>(lng_call_error_not_available(lt_user, App::peerName(user)))); Ui::show(Box<InformBox>(lng_call_error_not_available(lt_user, App::peerName(user))));
return; return;
} }
requestMicrophonePermissionOrFail([this, user](){ requestMicrophonePermissionOrFail(crl::guard(this, [=] {
createCall(user, Call::Type::Outgoing); createCall(user, Call::Type::Outgoing);
}); }));
} }
void Instance::callFinished(not_null<Call*> call) { void Instance::callFinished(not_null<Call*> call) {
@ -294,7 +294,7 @@ void Instance::requestMicrophonePermissionOrFail(Fn<void()> onSuccess) {
if (status==Platform::PermissionStatus::Granted) { if (status==Platform::PermissionStatus::Granted) {
onSuccess(); onSuccess();
} else if(status==Platform::PermissionStatus::CanRequest) { } 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) { if (status==Platform::PermissionStatus::Granted) {
crl::on_main(onSuccess); crl::on_main(onSuccess);
} else { } else {
@ -302,15 +302,15 @@ void Instance::requestMicrophonePermissionOrFail(Fn<void()> onSuccess) {
_currentCall->hangup(); _currentCall->hangup();
} }
} }
}); }));
} else { } else {
if (alreadyInCall()) { if (alreadyInCall()) {
_currentCall->hangup(); _currentCall->hangup();
} }
Ui::show(Box<ConfirmBox>(lang(lng_no_mic_permission), lang(lng_menu_settings), [](){ Ui::show(Box<ConfirmBox>(lang(lng_no_mic_permission), lang(lng_menu_settings), crl::guard(this, [] {
Platform::OpenSystemSettingsForPermission(Platform::PermissionType::Microphone); Platform::OpenSystemSettingsForPermission(Platform::PermissionType::Microphone);
Ui::hideLayer(); Ui::hideLayer();
})); })));
} }
} }

View File

@ -28,7 +28,7 @@ enum class PeerToPeer {
class Panel; 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: public:
Instance(); Instance();

View File

@ -438,11 +438,10 @@ PermissionStatus GetPermissionStatus(PermissionType type){
} }
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback){ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback){
resultCallback(PermissionStatus::Granted);
} }
void OpenSystemSettingsForPermission(PermissionType type){ void OpenSystemSettingsForPermission(PermissionType type){
} }
namespace ThirdParty { namespace ThirdParty {

View File

@ -288,7 +288,8 @@ void RegisterCustomScheme() {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability" #pragma clang diagnostic ignored "-Wunguarded-availability"
PermissionStatus GetPermissionStatus(PermissionType type) { PermissionStatus GetPermissionStatus(PermissionType type) {
switch(type) { #ifndef OS_MAC_OLD
switch (type) {
case PermissionType::Microphone: case PermissionType::Microphone:
if([AVCaptureDevice respondsToSelector: @selector(authorizationStatusForMediaType:)]) { // Available starting with 10.14 if([AVCaptureDevice respondsToSelector: @selector(authorizationStatusForMediaType:)]) { // Available starting with 10.14
switch([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) { switch([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
@ -301,32 +302,38 @@ PermissionStatus GetPermissionStatus(PermissionType type) {
return PermissionStatus::Denied; return PermissionStatus::Denied;
} }
} }
return PermissionStatus::Granted; break;
} }
#endif // OS_MAC_OLD
return PermissionStatus::Granted; return PermissionStatus::Granted;
} }
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback) { void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback) {
switch(type) { #ifndef OS_MAC_OLD
switch (type) {
case PermissionType::Microphone: case PermissionType::Microphone:
if([AVCaptureDevice respondsToSelector: @selector(requestAccessForMediaType:completionHandler:)]) { // Available starting with 10.14 if ([AVCaptureDevice respondsToSelector: @selector(requestAccessForMediaType:completionHandler:)]) { // Available starting with 10.14
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
crl::on_main([=] {
resultCallback(granted ? PermissionStatus::Granted : PermissionStatus::Denied); resultCallback(granted ? PermissionStatus::Granted : PermissionStatus::Denied);
});
}]; }];
}else{
resultCallback(PermissionStatus::Granted);
} }
break; break;
} }
#endif // OS_MAC_OLD
resultCallback(PermissionStatus::Granted);
} }
#pragma clang diagnostic pop // -Wunguarded-availability #pragma clang diagnostic pop // -Wunguarded-availability
void OpenSystemSettingsForPermission(PermissionType type) { void OpenSystemSettingsForPermission(PermissionType type) {
switch(type) { #ifndef OS_MAC_OLD
switch (type) {
case PermissionType::Microphone: case PermissionType::Microphone:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"]]; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"]];
break; break;
} }
#endif // OS_MAC_OLD
} }
} // namespace Platform } // namespace Platform

View File

@ -17,6 +17,7 @@ enum class PermissionStatus {
CanRequest, CanRequest,
Denied, Denied,
}; };
enum class PermissionType { enum class PermissionType {
Microphone, Microphone,
}; };

View File

@ -627,7 +627,7 @@ void RegisterCustomScheme() {
} }
PermissionStatus GetPermissionStatus(PermissionType type) { PermissionStatus GetPermissionStatus(PermissionType type) {
if(type==PermissionType::Microphone) { if (type==PermissionType::Microphone) {
PermissionStatus result=PermissionStatus::Granted; PermissionStatus result=PermissionStatus::Granted;
HKEY hKey; HKEY hKey;
LSTATUS res=RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\CapabilityAccessManager\\ConsentStore\\microphone", 0, KEY_QUERY_VALUE, &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<void(PermissionStatus)> resultCallback) { void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback) {
resultCallback(PermissionStatus::Granted);
} }
void OpenSystemSettingsForPermission(PermissionType type) { 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); ShellExecute(NULL, L"open", L"ms-settings:privacy-microphone", NULL, NULL, SW_SHOWDEFAULT);
} }
} }