|
|
@@ -18,6 +18,7 @@
|
|
|
#include <sstream>
|
|
|
#include <dlfcn.h>
|
|
|
#include <util/base.h>
|
|
|
+#include <util/threading.h>
|
|
|
#include <obs-config.h>
|
|
|
#include "platform.hpp"
|
|
|
#include "obs-app.hpp"
|
|
|
@@ -26,6 +27,9 @@
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
+#import <CoreFoundation/CoreFoundation.h>
|
|
|
+#import <AVFoundation/AVFoundation.h>
|
|
|
+#import <ApplicationServices/ApplicationServices.h>
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
@@ -238,6 +242,136 @@ void EnableOSXDockIcon(bool enable)
|
|
|
}
|
|
|
@end
|
|
|
|
|
|
+MacPermissionStatus CheckPermissionWithPrompt(MacPermissionType type,
|
|
|
+ bool prompt_for_permission)
|
|
|
+{
|
|
|
+ __block MacPermissionStatus permissionResponse =
|
|
|
+ kPermissionNotDetermined;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case kAudioDeviceAccess: {
|
|
|
+ if (@available(macOS 10.14, *)) {
|
|
|
+ AVAuthorizationStatus audioStatus = [AVCaptureDevice
|
|
|
+ authorizationStatusForMediaType:AVMediaTypeAudio];
|
|
|
+
|
|
|
+ if (audioStatus == AVAuthorizationStatusNotDetermined &&
|
|
|
+ prompt_for_permission) {
|
|
|
+ os_event_t *block_finished;
|
|
|
+ os_event_init(&block_finished,
|
|
|
+ OS_EVENT_TYPE_MANUAL);
|
|
|
+ [AVCaptureDevice
|
|
|
+ requestAccessForMediaType:AVMediaTypeAudio
|
|
|
+ completionHandler:^(
|
|
|
+ BOOL granted
|
|
|
+ __attribute((unused))) {
|
|
|
+ os_event_signal(
|
|
|
+ block_finished);
|
|
|
+ }];
|
|
|
+ os_event_wait(block_finished);
|
|
|
+ os_event_destroy(block_finished);
|
|
|
+ audioStatus = [AVCaptureDevice
|
|
|
+ authorizationStatusForMediaType:
|
|
|
+ AVMediaTypeAudio];
|
|
|
+ }
|
|
|
+
|
|
|
+ permissionResponse = (MacPermissionStatus)audioStatus;
|
|
|
+ } else {
|
|
|
+ permissionResponse = kPermissionAuthorized;
|
|
|
+ }
|
|
|
+
|
|
|
+ blog(LOG_INFO, "[macOS] Permission for audio device access %s.",
|
|
|
+ permissionResponse == kPermissionAuthorized ? "granted"
|
|
|
+ : "denied");
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case kVideoDeviceAccess: {
|
|
|
+ if (@available(macOS 10.14, *)) {
|
|
|
+ AVAuthorizationStatus videoStatus = [AVCaptureDevice
|
|
|
+ authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
|
+
|
|
|
+ if (videoStatus == AVAuthorizationStatusNotDetermined &&
|
|
|
+ prompt_for_permission) {
|
|
|
+ os_event_t *block_finished;
|
|
|
+ os_event_init(&block_finished,
|
|
|
+ OS_EVENT_TYPE_MANUAL);
|
|
|
+ [AVCaptureDevice
|
|
|
+ requestAccessForMediaType:AVMediaTypeVideo
|
|
|
+ completionHandler:^(
|
|
|
+ BOOL granted
|
|
|
+ __attribute((unused))) {
|
|
|
+ os_event_signal(
|
|
|
+ block_finished);
|
|
|
+ }];
|
|
|
+
|
|
|
+ os_event_wait(block_finished);
|
|
|
+ os_event_destroy(block_finished);
|
|
|
+ videoStatus = [AVCaptureDevice
|
|
|
+ authorizationStatusForMediaType:
|
|
|
+ AVMediaTypeVideo];
|
|
|
+ }
|
|
|
+
|
|
|
+ permissionResponse = (MacPermissionStatus)videoStatus;
|
|
|
+ } else {
|
|
|
+ permissionResponse = kPermissionAuthorized;
|
|
|
+ }
|
|
|
+
|
|
|
+ blog(LOG_INFO, "[macOS] Permission for video device access %s.",
|
|
|
+ permissionResponse == kPermissionAuthorized ? "granted"
|
|
|
+ : "denied");
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case kScreenCapture: {
|
|
|
+ if (@available(macOS 10.15, *)) {
|
|
|
+ permissionResponse = (CGPreflightScreenCaptureAccess()
|
|
|
+ ? kPermissionAuthorized
|
|
|
+ : kPermissionDenied);
|
|
|
+
|
|
|
+ if (permissionResponse != kPermissionAuthorized &&
|
|
|
+ prompt_for_permission) {
|
|
|
+ permissionResponse =
|
|
|
+ (CGRequestScreenCaptureAccess()
|
|
|
+ ? kPermissionAuthorized
|
|
|
+ : kPermissionDenied);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ permissionResponse = kPermissionAuthorized;
|
|
|
+ }
|
|
|
+
|
|
|
+ blog(LOG_INFO, "[macOS] Permission for screen capture %s.",
|
|
|
+ permissionResponse == kPermissionAuthorized ? "granted"
|
|
|
+ : "denied");
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case kAccessibility: {
|
|
|
+ permissionResponse = (AXIsProcessTrusted()
|
|
|
+ ? kPermissionAuthorized
|
|
|
+ : kPermissionDenied);
|
|
|
+
|
|
|
+ if (permissionResponse != kPermissionAuthorized &&
|
|
|
+ prompt_for_permission) {
|
|
|
+ NSDictionary *options = @{
|
|
|
+ (__bridge id)kAXTrustedCheckOptionPrompt: @YES
|
|
|
+ };
|
|
|
+ permissionResponse = (AXIsProcessTrustedWithOptions(
|
|
|
+ (CFDictionaryRef)options)
|
|
|
+ ? kPermissionAuthorized
|
|
|
+ : kPermissionDenied);
|
|
|
+ }
|
|
|
+
|
|
|
+ blog(LOG_INFO, "[macOS] Permission for accessibility %s.",
|
|
|
+ permissionResponse == kPermissionAuthorized ? "granted"
|
|
|
+ : "denied");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return permissionResponse;
|
|
|
+}
|
|
|
+
|
|
|
void TaskbarOverlayInit() {}
|
|
|
void TaskbarOverlaySetStatus(TaskbarOverlayStatus status)
|
|
|
{
|