跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

macos-setup-bridge.m

47 行 · 2.4 KB历史下载
1#import "macos-setup-bridge.h"
2#import "macos-setup-view.h"
3
4// Build-only QA overlay. Demonstrate handing the actual VM to the main thread
5// and closing a session. It never publishes a framebuffer or accepts input.
6void CageRunSetupBridge(void *machine, void *queue, double width, double height,
7 const char *title, bool controller) {
8 (void)width; (void)height; (void)title; (void)controller;
9 @autoreleasepool {
10 if (!NSThread.isMainThread) {
11 fprintf(stderr, "Cage setup probe requires the AppKit main thread\n");
12 return;
13 }
14 NSApplication *app = [NSApplication sharedApplication];
15 [app setActivationPolicy:NSApplicationActivationPolicyProhibited];
16 VZVirtualMachine *vm = (__bridge VZVirtualMachine *)machine;
17 __block BOOL allowed = YES;
18 CageGuestSetupView *setup = [[CageGuestSetupView alloc] initWithMachine:vm
19 size:NSMakeSize(1024, 640) setupAuthorized:^BOOL { return allowed; }];
20 allowed = NO;
21 BOOL revoked = setup && ![setup snapshotPNG] && ![setup clickAtX:1 y:1] && ![setup scrollAtX:1 y:1 deltaX:0 deltaY:10];
22 fprintf(stderr, "Cage setup probe: main-thread binding and revocation %s\n", revoked ? "passed" : "failed");
23 [setup close];
24
25 // Preserve Lima's normal shutdown path while AppKit owns its main loop.
26 dispatch_queue_t vmQueue = (__bridge dispatch_queue_t)queue;
27 __block BOOL seenRunning = NO;
28 NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.25 repeats:YES block:^(NSTimer *tick) {
29 (void)tick;
30 dispatch_async(vmQueue, ^{
31 VZVirtualMachineState state = vm.state;
32 if (state == VZVirtualMachineStateRunning) seenRunning = YES;
33 if (seenRunning && (state == VZVirtualMachineStateStopped || state == VZVirtualMachineStateError)) {
34 dispatch_async(dispatch_get_main_queue(), ^{
35 [app stop:nil];
36 NSEvent *wake = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
37 location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0
38 context:nil subtype:0 data1:0 data2:0];
39 [app postEvent:wake atStart:YES];
40 });
41 }
42 });
43 }];
44 [app run];
45 [timer invalidate];
46 }
47}