better permissions mac

This commit is contained in:
test
2026-06-04 20:41:10 -05:00
parent 4e267f4d36
commit a35de5d129
15 changed files with 256 additions and 10 deletions
@@ -6,6 +6,7 @@ import (
"errors"
"io"
"os"
"os/exec"
"path/filepath"
)
@@ -29,6 +30,30 @@ func DarwinPermissions() map[string]bool {
}
}
func RequestDarwinPermissions(requested []string) map[string]bool {
want := make(map[string]bool, len(requested))
for _, key := range requested {
want[key] = true
}
if len(want) == 0 {
want["accessibility"] = true
want["screenRecording"] = true
want["fullDiskAccess"] = true
}
if want["accessibility"] {
darwinRequestAccessibilityPermission()
}
if want["screenRecording"] {
darwinRequestScreenRecordingPermission()
}
if want["fullDiskAccess"] {
_ = exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles").Start()
}
return DarwinPermissions()
}
func darwinFullDiskAccessPermission() bool {
home, _ := os.UserHomeDir()
candidates := []string{
@@ -13,3 +13,7 @@ func Elevation() string {
func DarwinPermissions() map[string]bool {
return nil
}
func RequestDarwinPermissions(_ []string) map[string]bool {
return nil
}
@@ -19,3 +19,7 @@ func Elevation() string {
func DarwinPermissions() map[string]bool {
return nil
}
func RequestDarwinPermissions(_ []string) map[string]bool {
return nil
}
@@ -65,3 +65,7 @@ func isTrustedInstallerSID(sid *windows.SID) bool {
func DarwinPermissions() map[string]bool {
return nil
}
func RequestDarwinPermissions(_ []string) map[string]bool {
return nil
}
@@ -3,13 +3,15 @@
package sysinfo
/*
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics -framework CoreFoundation
#include <ApplicationServices/ApplicationServices.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CoreGraphics.h>
#include <stdbool.h>
extern bool CGPreflightScreenCaptureAccess(void) __attribute__((weak_import));
extern bool CGRequestScreenCaptureAccess(void) __attribute__((weak_import));
static int checkAccessibilityPermission(void) {
return AXIsProcessTrusted() ? 1 : 0;
@@ -19,6 +21,27 @@ static int checkScreenRecordingPermission(void) {
if (CGPreflightScreenCaptureAccess == NULL) return 0;
return CGPreflightScreenCaptureAccess() ? 1 : 0;
}
static int requestAccessibilityPermission(void) {
const void *keys[] = { kAXTrustedCheckOptionPrompt };
const void *values[] = { kCFBooleanTrue };
CFDictionaryRef opts = CFDictionaryCreate(
kCFAllocatorDefault,
keys,
values,
1,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks
);
Boolean trusted = AXIsProcessTrustedWithOptions(opts);
if (opts != NULL) CFRelease(opts);
return trusted ? 1 : 0;
}
static int requestScreenRecordingPermission(void) {
if (CGRequestScreenCaptureAccess == NULL) return checkScreenRecordingPermission();
return CGRequestScreenCaptureAccess() ? 1 : 0;
}
*/
import "C"
@@ -29,3 +52,11 @@ func darwinAccessibilityPermission() bool {
func darwinScreenRecordingPermission() bool {
return C.checkScreenRecordingPermission() == 1
}
func darwinRequestAccessibilityPermission() bool {
return C.requestAccessibilityPermission() == 1
}
func darwinRequestScreenRecordingPermission() bool {
return C.requestScreenRecordingPermission() == 1
}
@@ -9,3 +9,11 @@ func darwinAccessibilityPermission() bool {
func darwinScreenRecordingPermission() bool {
return false
}
func darwinRequestAccessibilityPermission() bool {
return false
}
func darwinRequestScreenRecordingPermission() bool {
return false
}
@@ -57,7 +57,7 @@ func batteryStatus() (*int, bool) {
return nil, false
}
lower := strings.ToLower(text)
charging := strings.Contains(lower, "charging") || strings.Contains(lower, "charged")
charging := !strings.Contains(lower, "discharging") && (strings.Contains(lower, "charging") || strings.Contains(lower, "charged"))
return &percent, charging
}