tam
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
package winapi
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework CoreWLAN -framework CoreLocation -framework Foundation
|
||||
#cgo LDFLAGS: -framework CoreWLAN -framework CoreLocation -framework Foundation -framework AVFoundation -framework CoreGraphics
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -12,7 +12,12 @@ typedef struct {
|
||||
} CWifiInfo;
|
||||
|
||||
void RequestLocationPermission();
|
||||
void RequestCameraAndMicPermission();
|
||||
void RequestScreenCapturePermission();
|
||||
CWifiInfo GetCurrentWifiInfo();
|
||||
int GetCameraPermissionStatus();
|
||||
int GetMicrophonePermissionStatus();
|
||||
int GetScreenCapturePermissionStatus();
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
@@ -24,6 +29,31 @@ func RequestLocationAccess() {
|
||||
C.RequestLocationPermission()
|
||||
}
|
||||
|
||||
// RequestCameraAndMicAccess requests Camera and Microphone permissions on macOS
|
||||
func RequestCameraAndMicAccess() {
|
||||
C.RequestCameraAndMicPermission()
|
||||
}
|
||||
|
||||
// RequestScreenCaptureAccess requests Screen Capture permission on macOS
|
||||
func RequestScreenCaptureAccess() {
|
||||
C.RequestScreenCapturePermission()
|
||||
}
|
||||
|
||||
// GetCameraPermission status on macOS
|
||||
func GetCameraPermission() int {
|
||||
return int(C.GetCameraPermissionStatus())
|
||||
}
|
||||
|
||||
// GetMicrophonePermission status on macOS
|
||||
func GetMicrophonePermission() int {
|
||||
return int(C.GetMicrophonePermissionStatus())
|
||||
}
|
||||
|
||||
// GetScreenCapturePermission status on macOS
|
||||
func GetScreenCapturePermission() int {
|
||||
return int(C.GetScreenCapturePermissionStatus())
|
||||
}
|
||||
|
||||
// GetWifiConnection đọc SSID và BSSID từ CoreWLAN (macOS)
|
||||
func GetWifiConnection() WifiConnection {
|
||||
info := C.GetCurrentWifiInfo()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#import <CoreWLAN/CoreWLAN.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
static CLLocationManager *locationManager = nil;
|
||||
@@ -15,6 +17,60 @@ void RequestLocationPermission() {
|
||||
});
|
||||
}
|
||||
|
||||
void RequestCameraAndMicPermission() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (@available(macOS 10.14, *)) {
|
||||
// Request Camera
|
||||
AVAuthorizationStatus cameraStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if (cameraStatus == AVAuthorizationStatusNotDetermined) {
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
||||
// Camera permission requested
|
||||
}];
|
||||
}
|
||||
|
||||
// Request Microphone
|
||||
AVAuthorizationStatus micStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
|
||||
if (micStatus == AVAuthorizationStatusNotDetermined) {
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
|
||||
// Mic permission requested
|
||||
}];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void RequestScreenCapturePermission() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (@available(macOS 11.0, *)) {
|
||||
BOOL hasAccess = CGPreflightScreenCaptureAccess();
|
||||
if (!hasAccess) {
|
||||
CGRequestScreenCaptureAccess();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int GetCameraPermissionStatus() {
|
||||
if (@available(macOS 10.14, *)) {
|
||||
return (int)[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetMicrophonePermissionStatus() {
|
||||
if (@available(macOS 10.14, *)) {
|
||||
return (int)[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetScreenCapturePermissionStatus() {
|
||||
if (@available(macOS 11.0, *)) {
|
||||
return CGPreflightScreenCaptureAccess() ? 1 : 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char* ssid;
|
||||
char* bssid;
|
||||
|
||||
@@ -9,3 +9,18 @@ func GetWifiConnection() WifiConnection {
|
||||
|
||||
// RequestLocationAccess requests Location permission (stub for other systems)
|
||||
func RequestLocationAccess() {}
|
||||
|
||||
// RequestCameraAndMicAccess stub
|
||||
func RequestCameraAndMicAccess() {}
|
||||
|
||||
// RequestScreenCaptureAccess stub
|
||||
func RequestScreenCaptureAccess() {}
|
||||
|
||||
// GetCameraPermission stub
|
||||
func GetCameraPermission() int { return -1 }
|
||||
|
||||
// GetMicrophonePermission stub
|
||||
func GetMicrophonePermission() int { return -1 }
|
||||
|
||||
// GetScreenCapturePermission stub
|
||||
func GetScreenCapturePermission() int { return -1 }
|
||||
|
||||
@@ -41,3 +41,18 @@ func GetWifiConnection() WifiConnection {
|
||||
|
||||
// RequestLocationAccess requests Location permission (stub for Windows)
|
||||
func RequestLocationAccess() {}
|
||||
|
||||
// RequestCameraAndMicAccess stub
|
||||
func RequestCameraAndMicAccess() {}
|
||||
|
||||
// RequestScreenCaptureAccess stub
|
||||
func RequestScreenCaptureAccess() {}
|
||||
|
||||
// GetCameraPermission stub
|
||||
func GetCameraPermission() int { return -1 }
|
||||
|
||||
// GetMicrophonePermission stub
|
||||
func GetMicrophonePermission() int { return -1 }
|
||||
|
||||
// GetScreenCapturePermission stub
|
||||
func GetScreenCapturePermission() int { return -1 }
|
||||
|
||||
Reference in New Issue
Block a user