Files
SimpleRemoter/macos/Permissions.h
T
yuanyuanxianganddeepseek-flash c2b59f5d4a Feat(client): restart the macOS client once permissions are granted
macOS applies TCC grants per process, so ticking Screen Recording and
Accessibility in System Settings does nothing for a running client.
install.sh resets both with tccutil and re-signs the bundle ad-hoc, and a
rebuilt binary carries a new cdhash, so every update costs two rounds of
"grant one, kill the app, reopen it".

When a permission is missing at startup the client now starts a watcher
that polls CGPreflightScreenCaptureAccess and AXIsProcessTrusted -- only
for the permission that is actually missing, so a screen grant the startup
capture already proved is never re-judged by preflight, whose false
negatives after re-signing would otherwise block the restart forever.

Once everything reads granted the main loop disconnects and hands over to
a fresh process instead of exec'ing in place: TCC re-evaluates by pid, and
the child closes every fd above 2 before exec, so the old main and
sub-connection sockets cannot keep the server holding a dead host. The
parent exits only after the child starts; a child that dies on the spot
(exec failure, AMFI rejecting an un-re-signed binary, dyld abort) keeps
the current process alive instead, and a stop request during the hand-off
terminates it again. GHOST_AUTO_RELAUNCHED bounds this to one auto-restart
per launch, and the new process logs that it was started this way, which
is what the 运行日志 dialog shows.

Not built or run on a Mac yet.

Co-Authored-By: deepseek-flash
2026-11-14 12:52:48 +01:00

50 lines
1.9 KiB
Objective-C

#pragma once
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <ApplicationServices/ApplicationServices.h>
class Permissions {
public:
// Check if screen recording permission is granted
// Returns true if granted, false otherwise
static bool checkScreenCapture();
// 只查授权状态、不真的抓屏(macOS 10.15+,更早的版本恒为 true)。
// 授权看守线程用它轮询:checkScreenCapture() 每调一次就抓一整帧(视网膜屏
// 20+ MB),而这里只需要「用户刚在设置里勾上了」这个状态位。它在二进制重签名
// 后可能报假阴性 —— 正因如此,启动时的那次检查仍用 checkScreenCapture()。
static bool checkScreenCapturePreflight();
// Request screen recording permission (shows system dialog, macOS 10.15+)
static void requestScreenCapture();
// Check if accessibility permission is granted (for input simulation)
// Returns true if granted, false otherwise
static bool checkAccessibility();
// Request accessibility permission (shows system dialog)
static void requestAccessibility();
// Open System Preferences to Screen Recording settings
static void openScreenCaptureSettings();
// Open System Preferences to Accessibility settings
static void openAccessibilitySettings();
// Check if Full Disk Access permission is granted
// Returns true if granted, false otherwise
static bool checkFullDiskAccess();
// Open System Preferences to Full Disk Access settings
static void openFullDiskAccessSettings();
// Check all required permissions
// Returns true if all permissions are granted
static bool checkAllPermissions();
// Wait for permissions to be granted (blocking)
// Returns true if all granted within timeout, false otherwise
static bool waitForPermissions(int timeoutSeconds);
};