dsh-gufa-code 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/client.js +50 -16
- package/desktop/float/GufaFloat.m +283 -171
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/host/dev.js +8 -4
- package/package.json +1 -1
- package/src/client/00-core.js +26 -0
- package/src/client/90-app.js +24 -16
package/README.md
CHANGED
|
@@ -69,9 +69,10 @@ dsh plugin add dsh-gufa-code
|
|
|
69
69
|
|
|
70
70
|
### 摸鱼模式 / 桌面悬浮层(实验功能,macOS arm64)
|
|
71
71
|
|
|
72
|
-
- **进入摸鱼**:IDE 标题栏点「显示器」图标 → 弹出
|
|
72
|
+
- **进入摸鱼**:IDE 标题栏点「显示器」图标 → 弹出 **运行中 App 列表**(图标 + App 名,和投屏列表类似)→ 选中一个 App,古法编程会:
|
|
73
73
|
- 把该 App 切到前台(主窗口自动被盖住,等于「隐藏主窗口」);
|
|
74
|
-
- 以**无边框、半透明(0.55
|
|
74
|
+
- 以**无边框、半透明(0.55)、永远置顶**的独立悬浮窗出现,并**自动吸附**到该 App 当前窗口:位置、大小一致,窗口移动/缩放时实时跟随。
|
|
75
|
+
- 读取窗口位置/大小走 macOS **「辅助功能」**权限(不是屏幕录制):系统设置 → 隐私与安全性 → 辅助功能 → 勾选 **DeepSeek Harness**;改完重启一次 DSH 生效。
|
|
75
76
|
- **悬浮层交互**:
|
|
76
77
|
- 顶部 22px 拖动条移动窗口(右键 = 摸鱼菜单),窗口大小/位置会记住;
|
|
77
78
|
- 全局快捷键 **⌃⌥⌘G**:切换点击穿透(穿透后鼠标直接操作下面的 App,再按一次切回来);
|
package/client.js
CHANGED
|
@@ -21,6 +21,29 @@ G.pendingEntryWorkspace = null
|
|
|
21
21
|
G.ctx = null
|
|
22
22
|
G.h = h
|
|
23
23
|
G.React = React
|
|
24
|
+
/** 官方同款 portal:把弹窗渲染到 body(与 DSH 自己的设置/会话弹窗同一层级机制),
|
|
25
|
+
* 避免被右侧停靠会话(body 级 fixed z-index 2147483040)盖住。 */
|
|
26
|
+
G.portal = (function createPortalHelper() {
|
|
27
|
+
let ReactDOM = null
|
|
28
|
+
try {
|
|
29
|
+
ReactDOM = require('react-dom')
|
|
30
|
+
} catch {
|
|
31
|
+
ReactDOM = null
|
|
32
|
+
}
|
|
33
|
+
const ensureHost = () => {
|
|
34
|
+
let host = document.getElementById('gufa-portal-root')
|
|
35
|
+
if (host === null) {
|
|
36
|
+
host = document.createElement('div')
|
|
37
|
+
host.id = 'gufa-portal-root'
|
|
38
|
+
document.body.appendChild(host)
|
|
39
|
+
}
|
|
40
|
+
return host
|
|
41
|
+
}
|
|
42
|
+
return function portal(content) {
|
|
43
|
+
if (ReactDOM === null || typeof ReactDOM.createPortal !== 'function' || typeof document === 'undefined') return content
|
|
44
|
+
return ReactDOM.createPortal(content, ensureHost())
|
|
45
|
+
}
|
|
46
|
+
})()
|
|
24
47
|
G.hooks = { useState, useEffect, useRef, useMemo, useCallback, useLayoutEffect }
|
|
25
48
|
|
|
26
49
|
/* ── 事件总线(零件之间解耦:SSH → 终端 发送命令等) ───────────────────── */
|
|
@@ -1124,6 +1147,9 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1124
1147
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1125
1148
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1126
1149
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1150
|
+
/* 官方同款 body 级 portal 容器(弹窗渲染到这里,天然在停靠会话之上) */
|
|
1151
|
+
#gufa-portal-root{position:fixed;inset:0;z-index:2147483350;pointer-events:none}
|
|
1152
|
+
#gufa-portal-root>*{pointer-events:auto}
|
|
1127
1153
|
/* 摸鱼模式:App 窗口选择器 */
|
|
1128
1154
|
.gufa-float-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;
|
|
1129
1155
|
background:rgba(0,0,0,0.42);padding:24px;box-sizing:border-box}
|
|
@@ -10240,9 +10266,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
10240
10266
|
setFloatPicker({ status: 'loading', windows: [], error: '' })
|
|
10241
10267
|
try {
|
|
10242
10268
|
const value = await G.api('float.windows')
|
|
10243
|
-
if (value?.ok === true &&
|
|
10244
|
-
setFloatPicker({ status: '
|
|
10245
|
-
} else if (value?.ok ===
|
|
10269
|
+
if (value?.ok === true && value?.accessibility !== true) {
|
|
10270
|
+
setFloatPicker({ status: 'permission', windows: [], error: '' })
|
|
10271
|
+
} else if (value?.ok === true && Array.isArray(value.apps)) {
|
|
10272
|
+
setFloatPicker({ status: 'ready', windows: value.apps, error: '' })
|
|
10273
|
+
} else if (value?.ok === false) {
|
|
10246
10274
|
setFloatPicker({ status: 'permission', windows: [], error: '' })
|
|
10247
10275
|
} else {
|
|
10248
10276
|
setFloatPicker({ status: 'error', windows: [], error: '没有读到可吸附的窗口' })
|
|
@@ -10258,7 +10286,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
10258
10286
|
setFloatBusy(true)
|
|
10259
10287
|
try {
|
|
10260
10288
|
const value = await G.api('float.start', {
|
|
10261
|
-
follow: {
|
|
10289
|
+
follow: {
|
|
10290
|
+
pid: Number(target.pid) || 0,
|
|
10291
|
+
bundleId: typeof target.bundleId === 'string' ? target.bundleId : '',
|
|
10292
|
+
title: '',
|
|
10293
|
+
},
|
|
10262
10294
|
})
|
|
10263
10295
|
setFloatRunning(value?.running === true)
|
|
10264
10296
|
setFloatPicker(null)
|
|
@@ -11393,7 +11425,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11393
11425
|
),
|
|
11394
11426
|
),
|
|
11395
11427
|
typeof G.UsageDock === 'function' ? h(G.UsageDock, { active: true }) : null,
|
|
11396
|
-
workspaceDialog === null
|
|
11428
|
+
G.portal(workspaceDialog === null
|
|
11397
11429
|
? null
|
|
11398
11430
|
: h(
|
|
11399
11431
|
'div',
|
|
@@ -11457,7 +11489,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11457
11489
|
),
|
|
11458
11490
|
),
|
|
11459
11491
|
),
|
|
11460
|
-
|
|
11492
|
+
),
|
|
11493
|
+
G.portal(branchMenu === null
|
|
11461
11494
|
? null
|
|
11462
11495
|
: h(
|
|
11463
11496
|
'div',
|
|
@@ -11526,9 +11559,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11526
11559
|
),
|
|
11527
11560
|
),
|
|
11528
11561
|
),
|
|
11562
|
+
),
|
|
11529
11563
|
/* 弹窗 */
|
|
11530
|
-
modal === null ? null : renderModal(),
|
|
11531
|
-
floatPicker !== null
|
|
11564
|
+
G.portal(modal === null ? null : renderModal()),
|
|
11565
|
+
G.portal(floatPicker !== null
|
|
11532
11566
|
? h(
|
|
11533
11567
|
'div',
|
|
11534
11568
|
{
|
|
@@ -11551,8 +11585,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11551
11585
|
? h(
|
|
11552
11586
|
'div',
|
|
11553
11587
|
{ className: 'gufa-float-permission' },
|
|
11554
|
-
h('div', { className: 'gufa-float-permission-title' }, '
|
|
11555
|
-
h('div', { className: 'gufa-hint' }, '
|
|
11588
|
+
h('div', { className: 'gufa-float-permission-title' }, '需要「辅助功能」权限'),
|
|
11589
|
+
h('div', { className: 'gufa-hint' }, '摸鱼模式需要「辅助功能」权限才能读取/跟随其他 App 的窗口位置和大小(只读窗口信息,不录屏)。请在「系统设置 → 隐私与安全性 → 辅助功能」里打开 **DeepSeek Harness** 的开关(改完可能需要重启一次 DSH),然后点「重试」。'),
|
|
11556
11590
|
h(
|
|
11557
11591
|
'div',
|
|
11558
11592
|
{ className: 'gufa-row', style: { gap: 8, marginTop: 12, flexWrap: 'wrap' } },
|
|
@@ -11585,10 +11619,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11585
11619
|
h(
|
|
11586
11620
|
'span',
|
|
11587
11621
|
{ className: 'gufa-float-meta' },
|
|
11588
|
-
h('span', { className: 'gufa-float-owner' }, win.
|
|
11589
|
-
h('span', { className: 'gufa-float-title' }, win.
|
|
11622
|
+
h('span', { className: 'gufa-float-owner' }, win.name !== undefined && win.name !== '' ? win.name : '未知 App'),
|
|
11623
|
+
h('span', { className: 'gufa-float-title' }, win.bundleId !== undefined ? win.bundleId : ''),
|
|
11590
11624
|
),
|
|
11591
|
-
h('span', { className: 'gufa-float-size' },
|
|
11625
|
+
win.frontmost === true ? h('span', { className: 'gufa-float-size' }, '当前') : null,
|
|
11592
11626
|
),
|
|
11593
11627
|
),
|
|
11594
11628
|
),
|
|
@@ -11602,9 +11636,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
11602
11636
|
),
|
|
11603
11637
|
),
|
|
11604
11638
|
)
|
|
11605
|
-
: null,
|
|
11606
|
-
sessionsOpen ? renderSessionsDialog() : null,
|
|
11607
|
-
shortcutsOpen ? renderShortcutsDialog() : null,
|
|
11639
|
+
: null),
|
|
11640
|
+
G.portal(sessionsOpen ? renderSessionsDialog() : null),
|
|
11641
|
+
G.portal(shortcutsOpen ? renderShortcutsDialog() : null),
|
|
11608
11642
|
)
|
|
11609
11643
|
|
|
11610
11644
|
function renderShortcutsDialog() {
|
|
@@ -12,14 +12,25 @@
|
|
|
12
12
|
#import <AppKit/AppKit.h>
|
|
13
13
|
#import <WebKit/WebKit.h>
|
|
14
14
|
#import <CoreGraphics/CoreGraphics.h>
|
|
15
|
+
#import <ApplicationServices/ApplicationServices.h>
|
|
15
16
|
#import <Carbon/Carbon.h>
|
|
16
17
|
#import <signal.h>
|
|
17
18
|
|
|
18
19
|
static const EventHotKeyID GufaToggleHotKey = {'gufa', 1};
|
|
19
20
|
|
|
21
|
+
/* 前置声明(实现位于文件后半部分) */
|
|
22
|
+
static NSString *GufaOutputPath = nil;
|
|
23
|
+
static void GufaEmitJSON(NSDictionary *out);
|
|
24
|
+
static BOOL GufaTrustedForAX(void);
|
|
25
|
+
static NSArray<NSDictionary *> *GufaAXWindows(void);
|
|
26
|
+
static AXUIElementRef GufaCopyAXWindow(pid_t pid, NSString *title);
|
|
27
|
+
static BOOL GufaRectFromAX(AXUIElementRef element, NSRect *out);
|
|
28
|
+
static void GufaActivateBundle(NSString *bundleId);
|
|
29
|
+
static NSArray<NSDictionary *> *GufaAXApps(void);
|
|
30
|
+
static AXUIElementRef GufaCopyAppWindow(pid_t pid);
|
|
31
|
+
|
|
20
32
|
/* SIGTERM 时先把主窗口(DeepSeek Harness)唤回前台,再退出,实现「退出摸鱼」 */
|
|
21
33
|
static void GufaInstallTermHandler(void);
|
|
22
|
-
static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows);
|
|
23
34
|
|
|
24
35
|
@class GufaAppDelegate;
|
|
25
36
|
|
|
@@ -85,8 +96,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
85
96
|
@property (nonatomic, strong) NSDictionary *options;
|
|
86
97
|
@property (nonatomic, assign) EventHotKeyRef hotKeyRef;
|
|
87
98
|
@property (nonatomic, assign) BOOL following;
|
|
88
|
-
@property (nonatomic, assign)
|
|
89
|
-
@property (nonatomic,
|
|
99
|
+
@property (nonatomic, assign) pid_t followPid;
|
|
100
|
+
@property (nonatomic, copy) NSString *followTitle;
|
|
101
|
+
@property (nonatomic, assign) AXUIElementRef followWindowRef;
|
|
90
102
|
@property (nonatomic, strong) NSTimer *followTimer;
|
|
91
103
|
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *windowCandidates;
|
|
92
104
|
- (void)loadWebContent;
|
|
@@ -128,29 +140,38 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
128
140
|
[self loadWebContent];
|
|
129
141
|
}
|
|
130
142
|
|
|
131
|
-
/** 吸附目标 App
|
|
143
|
+
/** 吸附目标 App:把它切到前台(主窗口自然被盖住 + 切到它所在的 Space)。 */
|
|
132
144
|
- (void)activateTargetApp {
|
|
133
145
|
NSDictionary *follow = self.options[@"follow"];
|
|
134
|
-
|
|
146
|
+
if (![follow isKindOfClass:[NSDictionary class]]) return;
|
|
147
|
+
NSString *bundleId = [follow[@"bundleId"] isKindOfClass:[NSString class]] ? follow[@"bundleId"] : @"";
|
|
148
|
+
if (bundleId.length > 0) {
|
|
149
|
+
GufaActivateBundle(bundleId);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
NSNumber *pid = follow[@"pid"];
|
|
135
153
|
if (![pid isKindOfClass:[NSNumber class]]) return;
|
|
136
154
|
NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:(pid_t)pid.intValue];
|
|
137
|
-
if (app
|
|
138
|
-
[app activateWithOptions:NSApplicationActivateAllWindows];
|
|
155
|
+
if (app != nil) GufaActivateBundle(app.bundleIdentifier);
|
|
139
156
|
}
|
|
140
157
|
|
|
141
|
-
/**
|
|
158
|
+
/** 启动就进入「吸附跟随」模式(摸鱼列表选好 App 后直接启动)。 */
|
|
142
159
|
- (void)beginningFollowFromOptions {
|
|
143
160
|
NSDictionary *follow = self.options[@"follow"];
|
|
144
161
|
if (![follow isKindOfClass:[NSDictionary class]]) return;
|
|
145
|
-
NSNumber *number = follow[@"windowNumber"];
|
|
146
162
|
NSNumber *pid = follow[@"pid"];
|
|
147
|
-
if (![
|
|
148
|
-
self.
|
|
149
|
-
self.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
if (![pid isKindOfClass:[NSNumber class]]) return;
|
|
164
|
+
self.followPid = (pid_t)pid.intValue;
|
|
165
|
+
self.followTitle = [follow[@"title"] isKindOfClass:[NSString class]] ? follow[@"title"] : @"";
|
|
166
|
+
/* App 刚被激活,窗口可能还没切到当前 Space;稍等再抓窗口 */
|
|
167
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
168
|
+
self.followWindowRef = GufaCopyAppWindow(self.followPid);
|
|
169
|
+
if (self.followWindowRef == NULL) return;
|
|
170
|
+
self.following = YES;
|
|
171
|
+
[self startFollowTimer];
|
|
172
|
+
[self applyFollowFrame];
|
|
173
|
+
self.statusItem.button.title = @"古法·摸鱼";
|
|
174
|
+
});
|
|
154
175
|
}
|
|
155
176
|
|
|
156
177
|
- (void)parseOptions {
|
|
@@ -232,7 +253,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
232
253
|
self.statusItem.button.title = @"古法";
|
|
233
254
|
self.statusItem.button.toolTip = @"古法编程悬浮层";
|
|
234
255
|
NSMenu *menu = [[NSMenu alloc] init];
|
|
235
|
-
[menu addItemWithTitle:@"跟随 App
|
|
256
|
+
[menu addItemWithTitle:@"跟随 App 窗口…(需辅助功能权限)" action:@selector(chooseFollowWindow:) keyEquivalent:@""].target = self;
|
|
236
257
|
[menu addItemWithTitle:@"停止跟随" action:@selector(stopFollow:) keyEquivalent:@""].target = self;
|
|
237
258
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
238
259
|
[menu addItemWithTitle:@"切换点击穿透(⌃⌥⌘G)" action:@selector(toggleClickThrough:) keyEquivalent:@""].target = self;
|
|
@@ -275,87 +296,53 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
275
296
|
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromRect(self.window.frame) forKey:self.frameKey];
|
|
276
297
|
}
|
|
277
298
|
|
|
278
|
-
/* ──
|
|
279
|
-
|
|
280
|
-
/** 枚举屏幕上的普通窗口(需要屏幕录制权限才能看到别的 App)。 */
|
|
281
|
-
- (NSArray<NSDictionary *> *)visibleWindows {
|
|
282
|
-
NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
|
|
283
|
-
CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
|
|
284
|
-
if (list == NULL) return rows;
|
|
285
|
-
NSInteger count = CFArrayGetCount(list);
|
|
286
|
-
pid_t selfPid = NSProcessInfo.processInfo.processIdentifier;
|
|
287
|
-
for (NSInteger i = 0; i < count && rows.count < 60; i++) {
|
|
288
|
-
NSDictionary *info = (__bridge NSDictionary *)CFArrayGetValueAtIndex(list, i);
|
|
289
|
-
NSNumber *layer = info[(id)kCGWindowLayer];
|
|
290
|
-
if (![layer isKindOfClass:[NSNumber class]] || layer.intValue != 0) continue;
|
|
291
|
-
NSNumber *pid = info[(id)kCGWindowOwnerPID];
|
|
292
|
-
if (![pid isKindOfClass:[NSNumber class]] || pid.intValue == selfPid) continue;
|
|
293
|
-
NSNumber *number = info[(id)kCGWindowNumber];
|
|
294
|
-
NSDictionary *bounds = info[(id)kCGWindowBounds];
|
|
295
|
-
if (number == nil || bounds == nil) continue;
|
|
296
|
-
CGRect rect = CGRectZero;
|
|
297
|
-
if (!CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)bounds, &rect)) continue;
|
|
298
|
-
if (rect.size.width < 220 || rect.size.height < 160) continue;
|
|
299
|
-
NSString *owner = info[(id)kCGWindowOwnerName];
|
|
300
|
-
NSString *title = info[(id)kCGWindowName];
|
|
301
|
-
NSString *label = [NSString stringWithFormat:@"%@%@ · %.0f×%.0f",
|
|
302
|
-
owner != nil ? owner : @"?",
|
|
303
|
-
(title.length > 0 ? [NSString stringWithFormat:@" — %@", title] : @""),
|
|
304
|
-
rect.size.width, rect.size.height];
|
|
305
|
-
[rows addObject:@{
|
|
306
|
-
@"number": number,
|
|
307
|
-
@"pid": pid,
|
|
308
|
-
@"owner": owner != nil ? owner : @"?",
|
|
309
|
-
@"title": title != nil ? title : @"",
|
|
310
|
-
@"label": label,
|
|
311
|
-
@"rect": NSStringFromRect(NSRectFromCGRect(rect)),
|
|
312
|
-
}];
|
|
313
|
-
}
|
|
314
|
-
CFRelease(list);
|
|
315
|
-
return rows;
|
|
316
|
-
}
|
|
299
|
+
/* ── 跟随选中的 App 窗口(Accessibility API) ─────────────────────── */
|
|
317
300
|
|
|
318
301
|
- (void)showPermissionGuide {
|
|
319
302
|
NSAlert *alert = [[NSAlert alloc] init];
|
|
320
|
-
alert.messageText = @"
|
|
321
|
-
alert.informativeText = @"
|
|
303
|
+
alert.messageText = @"需要「辅助功能」权限";
|
|
304
|
+
alert.informativeText = @"摸鱼列表要读取其他 App 窗口的位置和大小,需要「辅助功能」权限:\n\n系统设置 → 隐私与安全性 → 辅助功能 → 打开 DeepSeek Harness(以及「古法编程悬浮层」)的开关;改完后点「重试」。\n\n(只读取窗口尺寸/位置,不录屏、不采集画面。)";
|
|
322
305
|
[alert addButtonWithTitle:@"打开系统设置"];
|
|
323
306
|
[alert addButtonWithTitle:@"取消"];
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"]];
|
|
307
|
+
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
|
308
|
+
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"]];
|
|
327
309
|
}
|
|
328
310
|
}
|
|
329
311
|
|
|
330
312
|
- (void)chooseFollowWindow:(id)sender {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
313
|
+
if (!GufaTrustedForAX()) {
|
|
314
|
+
[self showPermissionGuide];
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
NSArray<NSDictionary *> *rows = GufaAXApps();
|
|
318
|
+
if (rows.count == 0) {
|
|
334
319
|
[self showPermissionGuide];
|
|
335
320
|
return;
|
|
336
321
|
}
|
|
337
|
-
self.windowCandidates = [rows mutableCopy];
|
|
338
|
-
|
|
339
322
|
NSAlert *alert = [[NSAlert alloc] init];
|
|
340
|
-
alert.messageText = @"
|
|
341
|
-
alert.informativeText = @"
|
|
323
|
+
alert.messageText = @"选择要吸附的 App";
|
|
324
|
+
alert.informativeText = @"悬浮层会切到该 App 的窗口并保持相同位置/大小,窗口移动时自动跟随。";
|
|
342
325
|
NSPopUpButton *popup = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 420, 26) pullsDown:NO];
|
|
343
|
-
for (NSDictionary *row in
|
|
344
|
-
[popup addItemWithTitle:row[@"label"]];
|
|
345
|
-
}
|
|
326
|
+
for (NSDictionary *row in rows) [popup addItemWithTitle:row[@"name"] ?: @"?"];
|
|
346
327
|
alert.accessoryView = popup;
|
|
347
|
-
[alert addButtonWithTitle:@"
|
|
328
|
+
[alert addButtonWithTitle:@"开始摸鱼"];
|
|
348
329
|
[alert addButtonWithTitle:@"取消"];
|
|
349
330
|
if ([alert runModal] != NSAlertFirstButtonReturn) return;
|
|
350
331
|
NSInteger index = popup.indexOfSelectedItem;
|
|
351
|
-
if (index < 0 || index >= (NSInteger)
|
|
352
|
-
NSDictionary *row =
|
|
353
|
-
self.
|
|
354
|
-
self.
|
|
355
|
-
self.
|
|
356
|
-
[
|
|
357
|
-
|
|
358
|
-
|
|
332
|
+
if (index < 0 || index >= (NSInteger)rows.count) return;
|
|
333
|
+
NSDictionary *row = rows[(NSUInteger)index];
|
|
334
|
+
self.followPid = (pid_t)[row[@"pid"] intValue];
|
|
335
|
+
self.followTitle = @"";
|
|
336
|
+
if (self.followWindowRef != NULL) { CFRelease(self.followWindowRef); self.followWindowRef = NULL; }
|
|
337
|
+
GufaActivateBundle(row[@"bundleId"]);
|
|
338
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
339
|
+
self.followWindowRef = GufaCopyAppWindow(self.followPid);
|
|
340
|
+
if (self.followWindowRef == NULL) return;
|
|
341
|
+
self.following = YES;
|
|
342
|
+
[self startFollowTimer];
|
|
343
|
+
[self applyFollowFrame];
|
|
344
|
+
self.statusItem.button.title = @"古法·摸鱼";
|
|
345
|
+
});
|
|
359
346
|
}
|
|
360
347
|
|
|
361
348
|
- (void)stopFollow:(id)sender {
|
|
@@ -379,29 +366,25 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
379
366
|
self.followTimer = nil;
|
|
380
367
|
}
|
|
381
368
|
self.following = NO;
|
|
369
|
+
if (self.followWindowRef != NULL) {
|
|
370
|
+
CFRelease(self.followWindowRef);
|
|
371
|
+
self.followWindowRef = NULL;
|
|
372
|
+
}
|
|
382
373
|
}
|
|
383
374
|
|
|
384
|
-
/**
|
|
375
|
+
/** 读取被跟随窗口当前 bounds,把悬浮窗贴上去(主屏坐标换算;多屏后续再完善)。 */
|
|
385
376
|
- (void)applyFollowFrame {
|
|
386
|
-
if (!self.following
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
NSNumber *number = info[(id)kCGWindowNumber];
|
|
395
|
-
if (![number isKindOfClass:[NSNumber class]] || number.intValue != self.followWindowNumber) continue;
|
|
396
|
-
NSNumber *pid = info[(id)kCGWindowOwnerPID];
|
|
397
|
-
if (![pid isKindOfClass:[NSNumber class]] || pid.intValue != self.followOwnerPID) continue;
|
|
398
|
-
NSDictionary *bounds = info[(id)kCGWindowBounds];
|
|
399
|
-
if (bounds != nil && CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)bounds, &target)) found = YES;
|
|
400
|
-
break;
|
|
377
|
+
if (!self.following) return;
|
|
378
|
+
if (self.followWindowRef == NULL) {
|
|
379
|
+
self.followWindowRef = GufaCopyAXWindow(self.followPid, self.followTitle);
|
|
380
|
+
if (self.followWindowRef == NULL) {
|
|
381
|
+
[self stopFollowTimer];
|
|
382
|
+
self.statusItem.button.title = @"古法";
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
401
385
|
}
|
|
402
|
-
|
|
403
|
-
if (!
|
|
404
|
-
/* 目标窗口关闭:停止跟随,保持当前位置 */
|
|
386
|
+
NSRect target = NSZeroRect;
|
|
387
|
+
if (!GufaRectFromAX(self.followWindowRef, &target)) {
|
|
405
388
|
[self stopFollowTimer];
|
|
406
389
|
self.statusItem.button.title = @"古法";
|
|
407
390
|
return;
|
|
@@ -409,7 +392,6 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
409
392
|
CGFloat screenHeight = NSScreen.mainScreen.frame.size.height;
|
|
410
393
|
NSRect frame = NSMakeRect(target.origin.x, screenHeight - target.origin.y - target.size.height, target.size.width, target.size.height);
|
|
411
394
|
[self.window setFrame:frame display:YES animate:NO];
|
|
412
|
-
[self saveFrame];
|
|
413
395
|
}
|
|
414
396
|
|
|
415
397
|
/* 全局快捷键 ⌃⌥⌘G(四键,避免冲突):穿透后窗口收不到鼠标事件,靠它切回来(Carbon 热键不需要辅助功能权限) */
|
|
@@ -445,10 +427,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
445
427
|
}
|
|
446
428
|
|
|
447
429
|
- (void)restoreMainWindow {
|
|
448
|
-
|
|
449
|
-
for (NSRunningApplication *app in apps) {
|
|
450
|
-
[app activateWithOptions:NSApplicationActivateAllWindows];
|
|
451
|
-
}
|
|
430
|
+
GufaActivateBundle(@"com.deepseek.dsh");
|
|
452
431
|
}
|
|
453
432
|
|
|
454
433
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return YES; }
|
|
@@ -460,10 +439,7 @@ static void GufaInstallTermHandler(void) {
|
|
|
460
439
|
signal(SIGTERM, SIG_IGN);
|
|
461
440
|
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
|
|
462
441
|
dispatch_source_set_event_handler(source, ^{
|
|
463
|
-
|
|
464
|
-
for (NSRunningApplication *app in apps) {
|
|
465
|
-
[app activateWithOptions:NSApplicationActivateAllWindows];
|
|
466
|
-
}
|
|
442
|
+
GufaActivateBundle(@"com.deepseek.dsh");
|
|
467
443
|
[NSApp terminate:nil];
|
|
468
444
|
});
|
|
469
445
|
dispatch_resume(source);
|
|
@@ -477,60 +453,170 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
477
453
|
return noErr;
|
|
478
454
|
}
|
|
479
455
|
|
|
480
|
-
/* ──
|
|
456
|
+
/* ── 窗口枚举:用 Accessibility(辅助功能)API ─────────────────────
|
|
457
|
+
* 不用 CGWindowList(它需要「屏幕录制」,ad-hoc 签名的 helper 拿不到授权);
|
|
458
|
+
* 辅助功能权限按 responsible app(DeepSeek Harness)继承,用户只需在
|
|
459
|
+
* 「隐私与安全性 → 辅助功能」里勾选 DeepSeek Harness 即可。
|
|
460
|
+
*/
|
|
481
461
|
|
|
482
|
-
static
|
|
462
|
+
static BOOL GufaStringFromAX(AXUIElementRef element, CFStringRef attribute, NSString **out) {
|
|
463
|
+
CFTypeRef value = NULL;
|
|
464
|
+
if (AXUIElementCopyAttributeValue(element, attribute, &value) != kAXErrorSuccess || value == NULL) return NO;
|
|
465
|
+
if (CFGetTypeID(value) != CFStringGetTypeID()) { CFRelease(value); return NO; }
|
|
466
|
+
if (out != NULL) *out = (__bridge_transfer NSString *)value;
|
|
467
|
+
else CFRelease(value);
|
|
468
|
+
return YES;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
static BOOL GufaRectFromAX(AXUIElementRef element, NSRect *out) {
|
|
472
|
+
CFTypeRef posRef = NULL;
|
|
473
|
+
CFTypeRef sizeRef = NULL;
|
|
474
|
+
CGPoint pos = CGPointZero;
|
|
475
|
+
CGSize size = CGSizeZero;
|
|
476
|
+
BOOL ok = NO;
|
|
477
|
+
if (AXUIElementCopyAttributeValue(element, (CFStringRef)CFSTR("AXPosition"), &posRef) == kAXErrorSuccess && posRef != NULL) {
|
|
478
|
+
AXValueGetValue((AXValueRef)posRef, kAXValueCGPointType, &pos);
|
|
479
|
+
CFRelease(posRef);
|
|
480
|
+
}
|
|
481
|
+
if (AXUIElementCopyAttributeValue(element, (CFStringRef)CFSTR("AXSize"), &sizeRef) == kAXErrorSuccess && sizeRef != NULL) {
|
|
482
|
+
AXValueGetValue((AXValueRef)sizeRef, kAXValueCGSizeType, &size);
|
|
483
|
+
CFRelease(sizeRef);
|
|
484
|
+
ok = YES;
|
|
485
|
+
}
|
|
486
|
+
if (out != NULL) *out = NSMakeRect(pos.x, pos.y, size.width, size.height);
|
|
487
|
+
return ok;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** 枚举所有可见窗口,返回 [{pid, owner, title, rect, icon}]。 */
|
|
491
|
+
static NSArray<NSDictionary *> *GufaAXWindows(void) {
|
|
483
492
|
NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
|
|
484
|
-
CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
|
|
485
|
-
if (list == NULL) return rows;
|
|
486
|
-
NSInteger count = CFArrayGetCount(list);
|
|
487
|
-
pid_t selfPid = NSProcessInfo.processInfo.processIdentifier;
|
|
488
493
|
NSMutableDictionary<NSNumber *, NSData *> *iconCache = [NSMutableDictionary dictionary];
|
|
489
|
-
for (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
|
|
494
|
-
if (
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
494
|
+
for (NSRunningApplication *app in [NSWorkspace sharedWorkspace].runningApplications) {
|
|
495
|
+
if (app.activationPolicy != NSApplicationActivationPolicyRegular) continue;
|
|
496
|
+
AXUIElementRef appElement = AXUIElementCreateApplication(app.processIdentifier);
|
|
497
|
+
if (appElement == NULL) continue;
|
|
498
|
+
CFTypeRef winsRef = NULL;
|
|
499
|
+
if (AXUIElementCopyAttributeValue(appElement, (CFStringRef)CFSTR("AXWindows"), &winsRef) == kAXErrorSuccess && winsRef != NULL) {
|
|
500
|
+
NSArray *wins = (__bridge_transfer NSArray *)winsRef;
|
|
501
|
+
for (id win in wins) {
|
|
502
|
+
AXUIElementRef window = (__bridge AXUIElementRef)win;
|
|
503
|
+
NSRect rect = NSZeroRect;
|
|
504
|
+
if (!GufaRectFromAX(window, &rect)) continue;
|
|
505
|
+
if (rect.size.width < 200 || rect.size.height < 140) continue;
|
|
506
|
+
NSString *title = @"";
|
|
507
|
+
GufaStringFromAX(window, (CFStringRef)CFSTR("AXTitle"), &title);
|
|
508
|
+
NSNumber *pidKey = @(app.processIdentifier);
|
|
509
|
+
NSData *iconData = iconCache[pidKey];
|
|
510
|
+
if (iconData == nil) {
|
|
511
|
+
iconData = NSData.data;
|
|
512
|
+
NSImage *icon = app.icon;
|
|
513
|
+
if (icon != nil) {
|
|
514
|
+
NSImage *resized = [[NSImage alloc] initWithSize:NSMakeSize(32, 32)];
|
|
515
|
+
[resized lockFocus];
|
|
516
|
+
[icon drawInRect:NSMakeRect(0, 0, 32, 32) fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0 respectFlipped:YES hints:nil];
|
|
517
|
+
[resized unlockFocus];
|
|
518
|
+
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:resized.TIFFRepresentation];
|
|
519
|
+
NSData *png = [rep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
|
|
520
|
+
if (png != nil) iconData = png;
|
|
521
|
+
}
|
|
522
|
+
iconCache[pidKey] = iconData;
|
|
523
|
+
}
|
|
524
|
+
[rows addObject:@{
|
|
525
|
+
@"pid": pidKey,
|
|
526
|
+
@"owner": app.localizedName ?: @"",
|
|
527
|
+
@"title": title,
|
|
528
|
+
@"x": @(rect.origin.x),
|
|
529
|
+
@"y": @(rect.origin.y),
|
|
530
|
+
@"width": @(rect.size.width),
|
|
531
|
+
@"height": @(rect.size.height),
|
|
532
|
+
@"icon": [iconData base64EncodedStringWithOptions:0] ?: @"",
|
|
533
|
+
}];
|
|
516
534
|
}
|
|
517
|
-
|
|
535
|
+
}
|
|
536
|
+
CFRelease(appElement);
|
|
537
|
+
}
|
|
538
|
+
return rows;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** 枚举运行中的普通 App(不依赖任何权限),按「最前 → 后台」排序。 */
|
|
542
|
+
static NSArray<NSDictionary *> *GufaAXApps(void) {
|
|
543
|
+
NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
|
|
544
|
+
NSRunningApplication *front = [NSWorkspace sharedWorkspace].frontmostApplication;
|
|
545
|
+
CGFloat iconScale = 32.0;
|
|
546
|
+
for (NSRunningApplication *app in [NSWorkspace sharedWorkspace].runningApplications) {
|
|
547
|
+
if (app.activationPolicy != NSApplicationActivationPolicyRegular) continue;
|
|
548
|
+
if (app.bundleIdentifier.length == 0) continue;
|
|
549
|
+
NSData *iconData = NSData.data;
|
|
550
|
+
NSImage *icon = app.icon;
|
|
551
|
+
if (icon != nil) {
|
|
552
|
+
NSImage *resized = [[NSImage alloc] initWithSize:NSMakeSize(iconScale, iconScale)];
|
|
553
|
+
[resized lockFocus];
|
|
554
|
+
[icon drawInRect:NSMakeRect(0, 0, iconScale, iconScale) fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0 respectFlipped:YES hints:nil];
|
|
555
|
+
[resized unlockFocus];
|
|
556
|
+
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:resized.TIFFRepresentation];
|
|
557
|
+
NSData *png = [rep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
|
|
558
|
+
if (png != nil) iconData = png;
|
|
518
559
|
}
|
|
519
560
|
[rows addObject:@{
|
|
520
|
-
@"
|
|
521
|
-
@"
|
|
522
|
-
@"
|
|
523
|
-
@"
|
|
524
|
-
@"width": @(rect.size.width),
|
|
525
|
-
@"height": @(rect.size.height),
|
|
561
|
+
@"pid": @(app.processIdentifier),
|
|
562
|
+
@"bundleId": app.bundleIdentifier,
|
|
563
|
+
@"name": app.localizedName ?: @"",
|
|
564
|
+
@"frontmost": @(front != nil && front.processIdentifier == app.processIdentifier),
|
|
526
565
|
@"icon": [iconData base64EncodedStringWithOptions:0] ?: @"",
|
|
527
566
|
}];
|
|
528
567
|
}
|
|
529
|
-
|
|
568
|
+
[rows sortUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
|
|
569
|
+
BOOL fa = [a[@"frontmost"] boolValue];
|
|
570
|
+
BOOL fb = [b[@"frontmost"] boolValue];
|
|
571
|
+
if (fa != fb) return fa ? NSOrderedAscending : NSOrderedDescending;
|
|
572
|
+
return [a[@"name"] localizedCompare:b[@"name"]];
|
|
573
|
+
}];
|
|
530
574
|
return rows;
|
|
531
575
|
}
|
|
532
576
|
|
|
533
|
-
|
|
577
|
+
/** 找某个 App 的窗口:优先 focused/main,其次最大的窗口。 */
|
|
578
|
+
static AXUIElementRef GufaCopyAppWindow(pid_t pid) {
|
|
579
|
+
AXUIElementRef appElement = AXUIElementCreateApplication(pid);
|
|
580
|
+
if (appElement == NULL) return NULL;
|
|
581
|
+
CFTypeRef windowRef = NULL;
|
|
582
|
+
AXUIElementRef found = NULL;
|
|
583
|
+
if (AXUIElementCopyAttributeValue(appElement, (CFStringRef)CFSTR("AXFocusedWindow"), &windowRef) == kAXErrorSuccess && windowRef != NULL) {
|
|
584
|
+
found = (AXUIElementRef)CFRetain(windowRef);
|
|
585
|
+
CFRelease(windowRef);
|
|
586
|
+
}
|
|
587
|
+
if (found == NULL && AXUIElementCopyAttributeValue(appElement, (CFStringRef)CFSTR("AXMainWindow"), &windowRef) == kAXErrorSuccess && windowRef != NULL) {
|
|
588
|
+
found = (AXUIElementRef)CFRetain(windowRef);
|
|
589
|
+
CFRelease(windowRef);
|
|
590
|
+
}
|
|
591
|
+
if (found == NULL) {
|
|
592
|
+
CFTypeRef winsRef = NULL;
|
|
593
|
+
if (AXUIElementCopyAttributeValue(appElement, (CFStringRef)CFSTR("AXWindows"), &winsRef) == kAXErrorSuccess && winsRef != NULL) {
|
|
594
|
+
NSArray *wins = (__bridge NSArray *)winsRef;
|
|
595
|
+
CGFloat bestArea = 0;
|
|
596
|
+
for (id win in wins) {
|
|
597
|
+
AXUIElementRef window = (__bridge AXUIElementRef)win;
|
|
598
|
+
NSRect rect = NSZeroRect;
|
|
599
|
+
if (!GufaRectFromAX(window, &rect)) continue;
|
|
600
|
+
CGFloat area = rect.size.width * rect.size.height;
|
|
601
|
+
if (area > bestArea && rect.size.width >= 200 && rect.size.height >= 140) {
|
|
602
|
+
if (found != NULL) CFRelease(found);
|
|
603
|
+
found = (AXUIElementRef)CFRetain(window);
|
|
604
|
+
bestArea = area;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
CFRelease(winsRef);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
CFRelease(appElement);
|
|
611
|
+
return found;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
static BOOL GufaTrustedForAX(void) {
|
|
615
|
+
if (AXIsProcessTrusted()) return YES;
|
|
616
|
+
NSDictionary *options = @{(__bridge NSString *)kAXTrustedCheckOptionPrompt: @YES};
|
|
617
|
+
AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options);
|
|
618
|
+
return NO;
|
|
619
|
+
}
|
|
534
620
|
|
|
535
621
|
static void GufaEmitJSON(NSDictionary *out) {
|
|
536
622
|
NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
|
|
@@ -543,33 +629,59 @@ static void GufaEmitJSON(NSDictionary *out) {
|
|
|
543
629
|
fputc('\n', stdout);
|
|
544
630
|
}
|
|
545
631
|
|
|
546
|
-
static
|
|
547
|
-
|
|
632
|
+
static int GufaListWindowsMode(void) {
|
|
633
|
+
NSArray<NSDictionary *> *rows = GufaAXApps();
|
|
634
|
+
GufaEmitJSON(@{@"ok": @YES, @"apps": rows, @"accessibility": @(GufaTrustedForAX())});
|
|
635
|
+
return 0;
|
|
548
636
|
}
|
|
549
637
|
|
|
550
|
-
/**
|
|
551
|
-
static
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
638
|
+
/** 激活目标 App(LaunchServices open -b,能切到它的 Space)。 */
|
|
639
|
+
static void GufaActivateBundle(NSString *bundleId) {
|
|
640
|
+
if (bundleId.length == 0) return;
|
|
641
|
+
NSTask *task = [[NSTask alloc] init];
|
|
642
|
+
task.executableURL = [NSURL fileURLWithPath:@"/usr/bin/open"];
|
|
643
|
+
task.arguments = @[@"-b", bundleId];
|
|
644
|
+
@try {
|
|
645
|
+
[task launchAndReturnError:NULL];
|
|
646
|
+
} @catch (NSException *exception) {
|
|
647
|
+
/* ignore */
|
|
559
648
|
}
|
|
560
|
-
return NO;
|
|
561
649
|
}
|
|
562
650
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
651
|
+
/** 按 pid + title 查找对应 AX window(follow 用)。 */
|
|
652
|
+
static AXUIElementRef GufaCopyAXWindow(pid_t pid, NSString *title) {
|
|
653
|
+
AXUIElementRef appElement = AXUIElementCreateApplication(pid);
|
|
654
|
+
if (appElement == NULL) return NULL;
|
|
655
|
+
CFTypeRef winsRef = NULL;
|
|
656
|
+
AXUIElementRef found = NULL;
|
|
657
|
+
if (AXUIElementCopyAttributeValue(appElement, (CFStringRef)CFSTR("AXWindows"), &winsRef) == kAXErrorSuccess && winsRef != NULL) {
|
|
658
|
+
NSArray *wins = (__bridge NSArray *)winsRef;
|
|
659
|
+
for (id win in wins) {
|
|
660
|
+
AXUIElementRef window = (__bridge AXUIElementRef)win;
|
|
661
|
+
NSRect rect = NSZeroRect;
|
|
662
|
+
if (!GufaRectFromAX(window, &rect)) continue;
|
|
663
|
+
NSString *candidateTitle = @"";
|
|
664
|
+
GufaStringFromAX(window, (CFStringRef)CFSTR("AXTitle"), &candidateTitle);
|
|
665
|
+
if (title.length > 0 && ![candidateTitle isEqualToString:title]) continue;
|
|
666
|
+
if (rect.size.width < 200 || rect.size.height < 140) continue;
|
|
667
|
+
found = (AXUIElementRef)CFRetain(window);
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
if (found == NULL && title.length == 0) {
|
|
671
|
+
/* 没标题时退化为第一个够大的窗口 */
|
|
672
|
+
for (id win in wins) {
|
|
673
|
+
AXUIElementRef window = (__bridge AXUIElementRef)win;
|
|
674
|
+
NSRect rect = NSZeroRect;
|
|
675
|
+
if (!GufaRectFromAX(window, &rect)) continue;
|
|
676
|
+
if (rect.size.width < 200 || rect.size.height < 140) continue;
|
|
677
|
+
found = (AXUIElementRef)CFRetain(window);
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
CFRelease(winsRef);
|
|
570
682
|
}
|
|
571
|
-
|
|
572
|
-
return
|
|
683
|
+
CFRelease(appElement);
|
|
684
|
+
return found;
|
|
573
685
|
}
|
|
574
686
|
|
|
575
687
|
int main(int argc, const char *argv[]) {
|
|
Binary file
|
|
Binary file
|
package/host/dev.js
CHANGED
|
@@ -176,7 +176,7 @@ export function register(router, env) {
|
|
|
176
176
|
router.method('float.openPrivacy', async () => {
|
|
177
177
|
if (process.platform !== 'darwin') return { ok: false }
|
|
178
178
|
try {
|
|
179
|
-
spawn('open', ['x-apple.systempreferences:com.apple.preference.security?
|
|
179
|
+
spawn('open', ['x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility'], { detached: true, stdio: 'ignore' }).unref()
|
|
180
180
|
return { ok: true }
|
|
181
181
|
} catch {
|
|
182
182
|
return { ok: false }
|
|
@@ -187,9 +187,13 @@ export function register(router, env) {
|
|
|
187
187
|
if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
|
|
188
188
|
if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
|
|
189
189
|
const follow = body !== null && typeof body === 'object' && body.follow !== null && typeof body.follow === 'object'
|
|
190
|
-
? {
|
|
190
|
+
? {
|
|
191
|
+
pid: Number(body.follow.pid) || 0,
|
|
192
|
+
bundleId: typeof body.follow.bundleId === 'string' ? body.follow.bundleId : '',
|
|
193
|
+
title: typeof body.follow.title === 'string' ? body.follow.title : '',
|
|
194
|
+
}
|
|
191
195
|
: null
|
|
192
|
-
if (follow !== null && follow.
|
|
196
|
+
if (follow !== null && follow.pid > 0) {
|
|
193
197
|
await killFloat()
|
|
194
198
|
} else if (await floatRunningAsync()) {
|
|
195
199
|
return { running: true, pid: (await listFloatPids())[0] ?? null }
|
|
@@ -201,7 +205,7 @@ export function register(router, env) {
|
|
|
201
205
|
}
|
|
202
206
|
const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
|
|
203
207
|
const authUrl = connection.authenticatedUrl(`${base}/`)
|
|
204
|
-
const payload = JSON.stringify({ authUrl, appUrl: `${base}/`, follow: follow !== null && follow.
|
|
208
|
+
const payload = JSON.stringify({ authUrl, appUrl: `${base}/`, follow: follow !== null && follow.pid > 0 ? follow : undefined })
|
|
205
209
|
await openApp([payload])
|
|
206
210
|
await new Promise((resolve) => setTimeout(resolve, 300))
|
|
207
211
|
const pids = await listFloatPids()
|
package/package.json
CHANGED
package/src/client/00-core.js
CHANGED
|
@@ -13,6 +13,29 @@ G.pendingEntryWorkspace = null
|
|
|
13
13
|
G.ctx = null
|
|
14
14
|
G.h = h
|
|
15
15
|
G.React = React
|
|
16
|
+
/** 官方同款 portal:把弹窗渲染到 body(与 DSH 自己的设置/会话弹窗同一层级机制),
|
|
17
|
+
* 避免被右侧停靠会话(body 级 fixed z-index 2147483040)盖住。 */
|
|
18
|
+
G.portal = (function createPortalHelper() {
|
|
19
|
+
let ReactDOM = null
|
|
20
|
+
try {
|
|
21
|
+
ReactDOM = require('react-dom')
|
|
22
|
+
} catch {
|
|
23
|
+
ReactDOM = null
|
|
24
|
+
}
|
|
25
|
+
const ensureHost = () => {
|
|
26
|
+
let host = document.getElementById('gufa-portal-root')
|
|
27
|
+
if (host === null) {
|
|
28
|
+
host = document.createElement('div')
|
|
29
|
+
host.id = 'gufa-portal-root'
|
|
30
|
+
document.body.appendChild(host)
|
|
31
|
+
}
|
|
32
|
+
return host
|
|
33
|
+
}
|
|
34
|
+
return function portal(content) {
|
|
35
|
+
if (ReactDOM === null || typeof ReactDOM.createPortal !== 'function' || typeof document === 'undefined') return content
|
|
36
|
+
return ReactDOM.createPortal(content, ensureHost())
|
|
37
|
+
}
|
|
38
|
+
})()
|
|
16
39
|
G.hooks = { useState, useEffect, useRef, useMemo, useCallback, useLayoutEffect }
|
|
17
40
|
|
|
18
41
|
/* ── 事件总线(零件之间解耦:SSH → 终端 发送命令等) ───────────────────── */
|
|
@@ -1116,6 +1139,9 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1116
1139
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1117
1140
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1118
1141
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1142
|
+
/* 官方同款 body 级 portal 容器(弹窗渲染到这里,天然在停靠会话之上) */
|
|
1143
|
+
#gufa-portal-root{position:fixed;inset:0;z-index:2147483350;pointer-events:none}
|
|
1144
|
+
#gufa-portal-root>*{pointer-events:auto}
|
|
1119
1145
|
/* 摸鱼模式:App 窗口选择器 */
|
|
1120
1146
|
.gufa-float-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;
|
|
1121
1147
|
background:rgba(0,0,0,0.42);padding:24px;box-sizing:border-box}
|
package/src/client/90-app.js
CHANGED
|
@@ -852,9 +852,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
852
852
|
setFloatPicker({ status: 'loading', windows: [], error: '' })
|
|
853
853
|
try {
|
|
854
854
|
const value = await G.api('float.windows')
|
|
855
|
-
if (value?.ok === true &&
|
|
856
|
-
setFloatPicker({ status: '
|
|
857
|
-
} else if (value?.ok ===
|
|
855
|
+
if (value?.ok === true && value?.accessibility !== true) {
|
|
856
|
+
setFloatPicker({ status: 'permission', windows: [], error: '' })
|
|
857
|
+
} else if (value?.ok === true && Array.isArray(value.apps)) {
|
|
858
|
+
setFloatPicker({ status: 'ready', windows: value.apps, error: '' })
|
|
859
|
+
} else if (value?.ok === false) {
|
|
858
860
|
setFloatPicker({ status: 'permission', windows: [], error: '' })
|
|
859
861
|
} else {
|
|
860
862
|
setFloatPicker({ status: 'error', windows: [], error: '没有读到可吸附的窗口' })
|
|
@@ -870,7 +872,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
870
872
|
setFloatBusy(true)
|
|
871
873
|
try {
|
|
872
874
|
const value = await G.api('float.start', {
|
|
873
|
-
follow: {
|
|
875
|
+
follow: {
|
|
876
|
+
pid: Number(target.pid) || 0,
|
|
877
|
+
bundleId: typeof target.bundleId === 'string' ? target.bundleId : '',
|
|
878
|
+
title: '',
|
|
879
|
+
},
|
|
874
880
|
})
|
|
875
881
|
setFloatRunning(value?.running === true)
|
|
876
882
|
setFloatPicker(null)
|
|
@@ -2005,7 +2011,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2005
2011
|
),
|
|
2006
2012
|
),
|
|
2007
2013
|
typeof G.UsageDock === 'function' ? h(G.UsageDock, { active: true }) : null,
|
|
2008
|
-
workspaceDialog === null
|
|
2014
|
+
G.portal(workspaceDialog === null
|
|
2009
2015
|
? null
|
|
2010
2016
|
: h(
|
|
2011
2017
|
'div',
|
|
@@ -2069,7 +2075,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2069
2075
|
),
|
|
2070
2076
|
),
|
|
2071
2077
|
),
|
|
2072
|
-
|
|
2078
|
+
),
|
|
2079
|
+
G.portal(branchMenu === null
|
|
2073
2080
|
? null
|
|
2074
2081
|
: h(
|
|
2075
2082
|
'div',
|
|
@@ -2138,9 +2145,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2138
2145
|
),
|
|
2139
2146
|
),
|
|
2140
2147
|
),
|
|
2148
|
+
),
|
|
2141
2149
|
/* 弹窗 */
|
|
2142
|
-
modal === null ? null : renderModal(),
|
|
2143
|
-
floatPicker !== null
|
|
2150
|
+
G.portal(modal === null ? null : renderModal()),
|
|
2151
|
+
G.portal(floatPicker !== null
|
|
2144
2152
|
? h(
|
|
2145
2153
|
'div',
|
|
2146
2154
|
{
|
|
@@ -2163,8 +2171,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2163
2171
|
? h(
|
|
2164
2172
|
'div',
|
|
2165
2173
|
{ className: 'gufa-float-permission' },
|
|
2166
|
-
h('div', { className: 'gufa-float-permission-title' }, '
|
|
2167
|
-
h('div', { className: 'gufa-hint' }, '
|
|
2174
|
+
h('div', { className: 'gufa-float-permission-title' }, '需要「辅助功能」权限'),
|
|
2175
|
+
h('div', { className: 'gufa-hint' }, '摸鱼模式需要「辅助功能」权限才能读取/跟随其他 App 的窗口位置和大小(只读窗口信息,不录屏)。请在「系统设置 → 隐私与安全性 → 辅助功能」里打开 **DeepSeek Harness** 的开关(改完可能需要重启一次 DSH),然后点「重试」。'),
|
|
2168
2176
|
h(
|
|
2169
2177
|
'div',
|
|
2170
2178
|
{ className: 'gufa-row', style: { gap: 8, marginTop: 12, flexWrap: 'wrap' } },
|
|
@@ -2197,10 +2205,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2197
2205
|
h(
|
|
2198
2206
|
'span',
|
|
2199
2207
|
{ className: 'gufa-float-meta' },
|
|
2200
|
-
h('span', { className: 'gufa-float-owner' }, win.
|
|
2201
|
-
h('span', { className: 'gufa-float-title' }, win.
|
|
2208
|
+
h('span', { className: 'gufa-float-owner' }, win.name !== undefined && win.name !== '' ? win.name : '未知 App'),
|
|
2209
|
+
h('span', { className: 'gufa-float-title' }, win.bundleId !== undefined ? win.bundleId : ''),
|
|
2202
2210
|
),
|
|
2203
|
-
h('span', { className: 'gufa-float-size' },
|
|
2211
|
+
win.frontmost === true ? h('span', { className: 'gufa-float-size' }, '当前') : null,
|
|
2204
2212
|
),
|
|
2205
2213
|
),
|
|
2206
2214
|
),
|
|
@@ -2214,9 +2222,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2214
2222
|
),
|
|
2215
2223
|
),
|
|
2216
2224
|
)
|
|
2217
|
-
: null,
|
|
2218
|
-
sessionsOpen ? renderSessionsDialog() : null,
|
|
2219
|
-
shortcutsOpen ? renderShortcutsDialog() : null,
|
|
2225
|
+
: null),
|
|
2226
|
+
G.portal(sessionsOpen ? renderSessionsDialog() : null),
|
|
2227
|
+
G.portal(shortcutsOpen ? renderShortcutsDialog() : null),
|
|
2220
2228
|
)
|
|
2221
2229
|
|
|
2222
2230
|
function renderShortcutsDialog() {
|