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,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);

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))));
return;
}
requestMicrophonePermissionOrFail([this, user](){
requestMicrophonePermissionOrFail(crl::guard(this, [=] {
createCall(user, Call::Type::Outgoing);
});
}));
}
void Instance::callFinished(not_null<Call*> 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<void()> 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<void()> onSuccess) {
_currentCall->hangup();
}
}
});
}));
} else {
if (alreadyInCall()) {
_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);
Ui::hideLayer();
}));
})));
}
}

View file

@ -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();

View file

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

View file

@ -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<void(PermissionStatus)> 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

View file

@ -11,12 +11,13 @@ namespace Platform {
void start();
void finish();
enum class PermissionStatus {
Granted,
CanRequest,
Denied,
};
enum class PermissionType {
Microphone,
};

View file

@ -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<void(PermissionStatus)> 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);
}
}