more mac imporvements and refresh
This commit is contained in:
@@ -2281,6 +2281,7 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
case "darwin_request_permissions":
|
||||
payload, _ := envelope["payload"].(map[string]interface{})
|
||||
var requested []string
|
||||
refreshOnly, _ := payload["refreshOnly"].(bool)
|
||||
if raw, ok := payload["permissions"].([]interface{}); ok {
|
||||
for _, item := range raw {
|
||||
if key, ok := item.(string); ok && key != "" {
|
||||
@@ -2288,9 +2289,16 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
}
|
||||
}
|
||||
}
|
||||
perms := sysinfo.RequestDarwinPermissions(requested)
|
||||
perms := sysinfo.DarwinPermissionsRefresh()
|
||||
if !refreshOnly {
|
||||
perms = sysinfo.RequestDarwinPermissions(requested)
|
||||
}
|
||||
missing := make([]string, 0)
|
||||
for _, key := range []string{"accessibility", "screenRecording", "fullDiskAccess"} {
|
||||
keys := []string{"accessibility", "screenRecording", "fullDiskAccess"}
|
||||
if !refreshOnly {
|
||||
keys = append(keys, "inputMonitoring")
|
||||
}
|
||||
for _, key := range keys {
|
||||
if perms == nil || !perms[key] {
|
||||
missing = append(missing, key)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,16 @@ func Elevation() string {
|
||||
}
|
||||
|
||||
func DarwinPermissions() map[string]bool {
|
||||
return map[string]bool{
|
||||
"screenRecording": darwinScreenRecordingPermission(),
|
||||
"accessibility": darwinAccessibilityPermission(),
|
||||
"inputMonitoring": darwinInputMonitoringPermission(),
|
||||
"fullDiskAccess": darwinFullDiskAccessPermission(),
|
||||
"root": os.Getuid() == 0,
|
||||
}
|
||||
}
|
||||
|
||||
func DarwinPermissionsRefresh() map[string]bool {
|
||||
return map[string]bool{
|
||||
"screenRecording": darwinScreenRecordingPermission(),
|
||||
"accessibility": darwinAccessibilityPermission(),
|
||||
@@ -38,6 +48,7 @@ func RequestDarwinPermissions(requested []string) map[string]bool {
|
||||
if len(want) == 0 {
|
||||
want["accessibility"] = true
|
||||
want["screenRecording"] = true
|
||||
want["inputMonitoring"] = true
|
||||
want["fullDiskAccess"] = true
|
||||
}
|
||||
|
||||
@@ -47,6 +58,10 @@ func RequestDarwinPermissions(requested []string) map[string]bool {
|
||||
if want["screenRecording"] {
|
||||
darwinRequestScreenRecordingPermission()
|
||||
}
|
||||
if want["inputMonitoring"] {
|
||||
darwinRequestInputMonitoringPermission()
|
||||
_ = exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent").Start()
|
||||
}
|
||||
if want["fullDiskAccess"] {
|
||||
_ = exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles").Start()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DarwinPermissionsRefresh() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DarwinPermissionsRefresh() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DarwinPermissionsRefresh() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
package sysinfo
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics -framework CoreFoundation
|
||||
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics -framework CoreFoundation -framework IOKit
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
#include <IOKit/hidsystem/IOHIDLib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool CGPreflightScreenCaptureAccess(void) __attribute__((weak_import));
|
||||
@@ -22,6 +23,10 @@ static int checkScreenRecordingPermission(void) {
|
||||
return CGPreflightScreenCaptureAccess() ? 1 : 0;
|
||||
}
|
||||
|
||||
static int checkInputMonitoringPermission(void) {
|
||||
return IOHIDCheckAccess(kIOHIDRequestTypeListenEvent) == kIOHIDAccessTypeGranted ? 1 : 0;
|
||||
}
|
||||
|
||||
static int requestAccessibilityPermission(void) {
|
||||
const void *keys[] = { kAXTrustedCheckOptionPrompt };
|
||||
const void *values[] = { kCFBooleanTrue };
|
||||
@@ -42,6 +47,10 @@ static int requestScreenRecordingPermission(void) {
|
||||
if (CGRequestScreenCaptureAccess == NULL) return checkScreenRecordingPermission();
|
||||
return CGRequestScreenCaptureAccess() ? 1 : 0;
|
||||
}
|
||||
|
||||
static int requestInputMonitoringPermission(void) {
|
||||
return IOHIDRequestAccess(kIOHIDRequestTypeListenEvent) == kIOHIDAccessTypeGranted ? 1 : 0;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
@@ -53,6 +62,10 @@ func darwinScreenRecordingPermission() bool {
|
||||
return C.checkScreenRecordingPermission() == 1
|
||||
}
|
||||
|
||||
func darwinInputMonitoringPermission() bool {
|
||||
return C.checkInputMonitoringPermission() == 1
|
||||
}
|
||||
|
||||
func darwinRequestAccessibilityPermission() bool {
|
||||
return C.requestAccessibilityPermission() == 1
|
||||
}
|
||||
@@ -60,3 +73,7 @@ func darwinRequestAccessibilityPermission() bool {
|
||||
func darwinRequestScreenRecordingPermission() bool {
|
||||
return C.requestScreenRecordingPermission() == 1
|
||||
}
|
||||
|
||||
func darwinRequestInputMonitoringPermission() bool {
|
||||
return C.requestInputMonitoringPermission() == 1
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ func darwinScreenRecordingPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func darwinInputMonitoringPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func darwinRequestAccessibilityPermission() bool {
|
||||
return false
|
||||
}
|
||||
@@ -17,3 +21,7 @@ func darwinRequestAccessibilityPermission() bool {
|
||||
func darwinRequestScreenRecordingPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func darwinRequestInputMonitoringPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user