dsh-gufa-code 1.1.8 → 1.2.0

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 CHANGED
@@ -67,6 +67,17 @@ dsh plugin add dsh-gufa-code
67
67
  - **会话弹窗里可以直接切换工作区**:点弹窗右上角的工作区名,选任意工作区后下方会话列表随之切换,点会话即打开(IDE 项目同时切到该工作区),不用再先切左侧工作区;
68
68
  - 会话里的文件链接、diff 标签页属于 DSH 右侧栏,被覆盖层挡住时点「打开完整对话」即可查看。
69
69
 
70
+ ### 桌面悬浮层(实验功能,macOS arm64)
71
+
72
+ - IDE 标题栏点「显示器」图标 → 屏幕上出现一个**无边框、半透明(0.55)、永远置顶**的独立悬浮窗,里面就是古法编程;
73
+ - 顶部 22px 拖动条移动窗口,窗口大小/位置会记住;
74
+ - 菜单栏「古法」图标:
75
+ - **跟随 App 窗口…**:选一个正在运行的 App 窗口,悬浮层自动对齐并实时跟随它的位置/大小(需要授予「屏幕录制」权限——只读窗口尺寸,不录屏);
76
+ - **停止跟随**:恢复自由拖动;
77
+ - **切换点击穿透**:穿透后鼠标直接操作下层 App;
78
+ - **关闭悬浮层**。
79
+ - 限制:目前仅 macOS arm64;跟随多显示器时按主屏坐标换算;helper 未签名(本地 ad-hoc 签名),分发前需要正式签名/notarize。
80
+
70
81
  ### 外观
71
82
 
72
83
  - 颜色全部走 DSH 主题 token,亮/暗主题自动跟随;界面宽度、开关状态持久化到 localStorage;
package/client.js CHANGED
@@ -1027,6 +1027,33 @@ G.errorText = (error) => {
1027
1027
  G.CSS = `
1028
1028
  .gufa-overlay-root{position:fixed;inset:0;z-index:1;display:flex;box-sizing:border-box;background:var(--gufa-solid-bg, var(--dsw-alias-bg-base));pointer-events:auto;overflow:hidden}
1029
1029
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1030
+ /* 桌面悬浮层模式:整窗半透明(0.55),顶部留出 22px 拖动条 */
1031
+ html[data-gufa-float] body{background:transparent!important}
1032
+ html[data-gufa-float] .gufa-overlay-root,
1033
+ html[data-gufa-float] .gufa-root{
1034
+ --gufa-solid-bg:rgba(13,15,19,0.55);--gufa-bg:rgba(13,15,19,0.55);
1035
+ --gufa-solid-layer:rgba(20,22,27,0.55);--gufa-layer:rgba(20,22,27,0.55);
1036
+ --gufa-solid-layer2:rgba(26,28,34,0.55);--gufa-layer2:rgba(26,28,34,0.55);
1037
+ --gufa-solid-overlay:rgba(30,33,40,0.72);
1038
+ }
1039
+ html[data-gufa-float] .gufa-overlay-root{background:transparent!important;padding-top:22px;box-sizing:border-box}
1040
+ html[data-gufa-float] .gufa-backdrop{opacity:0.5}
1041
+ /* 悬浮模式:右侧停靠的官方会话内部也半透明(DSH 主题变量在停靠根上覆盖) */
1042
+ html[data-gufa-float] [data-gufa-dock]{
1043
+ --dsw-alias-bg-base:rgba(13,15,19,0.55);
1044
+ --dsw-alias-bg-layer-1:rgba(20,22,27,0.55);
1045
+ --dsw-alias-bg-layer-2:rgba(26,28,34,0.55);
1046
+ --dsw-alias-bg-overlay:rgba(30,33,40,0.72);
1047
+ background:rgba(13,15,19,0.55)!important;
1048
+ }
1049
+ html[data-gufa-float] [data-gufa-dock] [data-conversation-scroll],
1050
+ html[data-gufa-float] [data-gufa-dock] [data-conversation-content]{background:transparent!important}
1051
+ /* 经典 DSH 界面在悬浮窗里整体隐藏(保留古法覆盖层与右侧停靠会话),否则半透明下会透出「另一个 DSH」 */
1052
+ html[data-gufa-float] #root{visibility:hidden!important}
1053
+ html[data-gufa-float] #root .gufa-overlay-root,
1054
+ html[data-gufa-float] #root [data-gufa-dock],
1055
+ html[data-gufa-float] #root .gufa-overlay-root *,
1056
+ html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1030
1057
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1031
1058
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1032
1059
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
@@ -1775,6 +1802,10 @@ const ICON_PATHS = {
1775
1802
  ['path', { d: 'M12 5v14' }],
1776
1803
  ['path', { d: 'M6 13l6 6 6-6' }],
1777
1804
  ],
1805
+ monitor: [
1806
+ ['rect', { x: 3, y: 4.5, width: 18, height: 12, rx: 2 }],
1807
+ ['path', { d: 'M9 20h6M12 16.5V20' }],
1808
+ ],
1778
1809
  graph: [
1779
1810
  ['circle', { cx: 6, cy: 6, r: 2.2 }],
1780
1811
  ['circle', { cx: 6, cy: 18, r: 2.2 }],
@@ -8146,7 +8177,10 @@ function gufaPlaceDockedConversation(root, host, options) {
8146
8177
  /* ignore */
8147
8178
  }
8148
8179
  const backdropMode = options !== null && options !== undefined && options.translucent === true
8149
- if (backdropMode && dockBackground !== '') root.style.background = `color-mix(in srgb, ${dockBackground} 34%, transparent)`
8180
+ let floatMode = false
8181
+ try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
8182
+ if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
8183
+ else if (backdropMode && dockBackground !== '') root.style.background = `color-mix(in srgb, ${dockBackground} 34%, transparent)`
8150
8184
  else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
8151
8185
  root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
8152
8186
  root.style.boxSizing = 'border-box'
@@ -9400,6 +9434,8 @@ G.GufaApp = function GufaApp(props) {
9400
9434
  const sessionTitle = useSessions !== undefined ? useSessions(selectSessionTitle) : null
9401
9435
  const currentSessionId = useSessions !== undefined ? useSessions(selectMainSessionId) : null
9402
9436
  const [sessionsOpen, setSessionsOpen] = useState(false)
9437
+ const [floatRunning, setFloatRunning] = useState(false)
9438
+ const [floatBusy, setFloatBusy] = useState(false)
9403
9439
  /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
9404
9440
  const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
9405
9441
  const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
@@ -10035,6 +10071,63 @@ G.GufaApp = function GufaApp(props) {
10035
10071
  /* 会话弹窗里选了别的工作区的会话:右侧会话保持不动,不再自动把 IDE 项目切过去 */
10036
10072
  const sessionPinnedRef = useRef(false)
10037
10073
 
10074
+ /* ── 桌面悬浮层:URL 带 ?gufa-float=1 时自动进入 IDE 并用半透明皮肤 ── */
10075
+ const floatRequested = (() => {
10076
+ try {
10077
+ if (typeof location !== 'undefined' && /[?&]gufa-float=1/.test(location.search)) return true
10078
+ return typeof localStorage !== 'undefined' && localStorage.getItem('gufa-code:float') === '1'
10079
+ } catch {
10080
+ return false
10081
+ }
10082
+ })()
10083
+ useEffect(() => {
10084
+ if (floatRequested !== true) return undefined
10085
+ try { document.documentElement.setAttribute('data-gufa-float', '1') } catch { /* ignore */ }
10086
+ const enter = (attempt) => {
10087
+ try {
10088
+ if (typeof G.mode?.get === 'function' && G.mode.get() !== true) G.mode.set(true)
10089
+ } catch { /* ignore */ }
10090
+ void G.api('dev.log', {
10091
+ message: `float-mode enter attempt=${attempt} mode=${String(typeof G.mode?.get === 'function' ? G.mode.get() : 'n/a')} overlay=${document.querySelector('.gufa-overlay-root') !== null}`,
10092
+ }).catch(() => {})
10093
+ }
10094
+ const first = window.setTimeout(() => enter(1), 400)
10095
+ const second = window.setTimeout(() => enter(2), 2000)
10096
+ return () => {
10097
+ window.clearTimeout(first)
10098
+ window.clearTimeout(second)
10099
+ }
10100
+ }, [floatRequested])
10101
+
10102
+ /* 悬浮层运行状态(主窗口里显示按钮状态用) */
10103
+ useEffect(() => {
10104
+ let cancelled = false
10105
+ void G.api('float.status').then((value) => {
10106
+ if (!cancelled) setFloatRunning(value?.running === true)
10107
+ }).catch(() => { /* 旧 host 没有该方法 */ })
10108
+ return () => { cancelled = true }
10109
+ }, [])
10110
+
10111
+ const toggleFloatWindow = useCallback(async () => {
10112
+ if (floatBusy) return
10113
+ setFloatBusy(true)
10114
+ try {
10115
+ if (floatRunning) {
10116
+ await G.api('float.stop')
10117
+ setFloatRunning(false)
10118
+ setBanner('悬浮层已关闭')
10119
+ } else {
10120
+ const value = await G.api('float.start')
10121
+ setFloatRunning(value?.running === true)
10122
+ setBanner('悬浮层已启动:屏幕上的半透明窗口,菜单栏「古法」可切换点击穿透')
10123
+ }
10124
+ } catch (error) {
10125
+ setBanner(G.errorText(error))
10126
+ } finally {
10127
+ setFloatBusy(false)
10128
+ }
10129
+ }, [floatBusy, floatRunning])
10130
+
10038
10131
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
10039
10132
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
10040
10133
  * (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
@@ -10944,6 +11037,12 @@ G.GufaApp = function GufaApp(props) {
10944
11037
  }),
10945
11038
  }, h(G.Icon, { name: 'image', size: 16 }))
10946
11039
  : null,
11040
+ h(G.IconButton, {
11041
+ title: floatRunning ? '关闭桌面悬浮层' : '打开桌面悬浮层(半透明置顶窗口)',
11042
+ 'data-active': floatRunning ? '' : undefined,
11043
+ disabled: floatBusy,
11044
+ onClick: () => void toggleFloatWindow(),
11045
+ }, h(G.Icon, { name: 'monitor', size: 15 })),
10947
11046
  h(G.IconButton, { title: t('app.refresh'), onClick: () => { setRefreshToken((token) => token + 1); setGitRefreshToken((token) => token + 1); setSshRefreshToken((token) => token + 1) } }, h(G.Icon, { name: 'refresh', size: 15 })),
10948
11047
  h(G.IconButton, {
10949
11048
  title: ui.chatOpen ? t('activity.collapseChat') : t('activity.expandChat'),
@@ -0,0 +1,394 @@
1
+ /**
2
+ * 古法编程 · 桌面悬浮层(P0,Objective-C 实现)
3
+ *
4
+ * 独立小窗口进程:加载 DSH Web GUI 的「古法编程」,做成半透明、无边框、永远置顶的悬浮窗。
5
+ * 由 dsh-gufa-code Host 半启动:
6
+ * gufa-float '<json>' json = {"authUrl":"http://127.0.0.1:PORT/?token=...","appUrl":"http://127.0.0.1:PORT/"}
7
+ *
8
+ * 交互:
9
+ * - 顶部 22px 拖动条移动窗口(窗口本身也可 resize);
10
+ * - 菜单栏「古法」图标:切换点击穿透 / 重置窗口 / 关闭。
11
+ */
12
+ #import <AppKit/AppKit.h>
13
+ #import <WebKit/WebKit.h>
14
+ #import <CoreGraphics/CoreGraphics.h>
15
+
16
+ @interface GufaDragStrip : NSView
17
+ @end
18
+
19
+ @implementation GufaDragStrip
20
+
21
+ - (BOOL)isOpaque { return NO; }
22
+
23
+ - (void)drawRect:(NSRect)dirtyRect {
24
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.22] setFill];
25
+ NSRectFill(dirtyRect);
26
+ NSDictionary *attrs = @{
27
+ NSFontAttributeName: [NSFont systemFontOfSize:10 weight:NSFontWeightMedium],
28
+ NSForegroundColorAttributeName: [NSColor colorWithCalibratedWhite:1.0 alpha:0.6],
29
+ };
30
+ NSString *label = @"古法编程 · 悬浮层(拖动这里移动窗口)";
31
+ NSSize size = [label sizeWithAttributes:attrs];
32
+ NSPoint origin = NSMakePoint(floor((self.bounds.size.width - size.width) / 2.0), floor((self.bounds.size.height - size.height) / 2.0));
33
+ [label drawAtPoint:origin withAttributes:attrs];
34
+ }
35
+
36
+ - (void)mouseDown:(NSEvent *)event {
37
+ [self.window performWindowDragWithEvent:event];
38
+ }
39
+
40
+ - (void)mouseDragged:(NSEvent *)event {
41
+ /* performDrag 已接管拖动 */
42
+ }
43
+
44
+ - (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
45
+
46
+ @end
47
+
48
+ @class GufaAppDelegate;
49
+
50
+ @interface GufaNavigationDelegate : NSObject <WKNavigationDelegate>
51
+ @property (nonatomic, weak) GufaAppDelegate *owner;
52
+ @property (nonatomic, copy) void (^pendingLoad)(void);
53
+ @end
54
+
55
+ @interface GufaAppDelegate : NSObject <NSApplicationDelegate>
56
+ @property (nonatomic, strong) NSWindow *window;
57
+ @property (nonatomic, strong) WKWebView *webView;
58
+ @property (nonatomic, strong) NSStatusItem *statusItem;
59
+ @property (nonatomic, assign) BOOL clickThrough;
60
+ @property (nonatomic, strong) NSString *frameKey;
61
+ @property (nonatomic, strong) GufaNavigationDelegate *navigation;
62
+ @property (nonatomic, strong) NSDictionary *options;
63
+ @property (nonatomic, assign) BOOL following;
64
+ @property (nonatomic, assign) int followWindowNumber;
65
+ @property (nonatomic, assign) pid_t followOwnerPID;
66
+ @property (nonatomic, strong) NSTimer *followTimer;
67
+ @property (nonatomic, strong) NSMutableArray<NSDictionary *> *windowCandidates;
68
+ - (void)loadWebContent;
69
+ - (void)toggleClickThrough:(id)sender;
70
+ - (void)resetFrame:(id)sender;
71
+ - (void)quitApp:(id)sender;
72
+ - (void)saveFrame;
73
+ @end
74
+
75
+ @implementation GufaNavigationDelegate
76
+ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
77
+ void (^next)(void) = self.pendingLoad;
78
+ if (next != nil) {
79
+ self.pendingLoad = nil;
80
+ next();
81
+ }
82
+ }
83
+ - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
84
+ NSLog(@"gufa-float navigation error: %@", error);
85
+ }
86
+ @end
87
+
88
+ @implementation GufaAppDelegate
89
+
90
+ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
91
+ self.frameKey = @"gufa-float-frame-v1";
92
+ self.clickThrough = NO;
93
+ [self parseOptions];
94
+ [self buildWindow];
95
+ [self buildStatusItem];
96
+ [self loadWebContent];
97
+ }
98
+
99
+ - (void)parseOptions {
100
+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;
101
+ if (args.count < 2) return;
102
+ NSData *data = [args[1] dataUsingEncoding:NSUTF8StringEncoding];
103
+ if (data == nil) return;
104
+ id parsed = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
105
+ if ([parsed isKindOfClass:[NSDictionary class]]) self.options = parsed;
106
+ }
107
+
108
+ - (void)buildWindow {
109
+ NSRect frame = NSMakeRect(0, 0, 1180, 820);
110
+ NSString *saved = [[NSUserDefaults standardUserDefaults] stringForKey:self.frameKey];
111
+ if (saved.length > 0) {
112
+ NSRect parsed = NSRectFromString(saved);
113
+ if (parsed.size.width > 320 && parsed.size.height > 240) frame = parsed;
114
+ } else if (NSScreen.mainScreen != nil) {
115
+ NSRect visible = NSScreen.mainScreen.visibleFrame;
116
+ NSString *menuSetting = [[NSUserDefaults standardUserDefaults] stringForKey:@"gufa-float-corner"];
117
+ if ([menuSetting isEqualToString:@"center"] || menuSetting == nil) {
118
+ CGFloat width = MIN(1180, visible.size.width * 0.86);
119
+ CGFloat height = MIN(820, visible.size.height * 0.86);
120
+ frame = NSMakeRect(visible.origin.x + (visible.size.width - width) / 2.0,
121
+ visible.origin.y + (visible.size.height - height) / 2.0,
122
+ width, height);
123
+ }
124
+ }
125
+
126
+ self.window = [[NSWindow alloc] initWithContentRect:frame
127
+ styleMask:(NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable)
128
+ backing:NSBackingStoreBuffered
129
+ defer:NO];
130
+ self.window.opaque = NO;
131
+ self.window.backgroundColor = NSColor.clearColor;
132
+ self.window.hasShadow = YES;
133
+ self.window.level = NSFloatingWindowLevel + 1;
134
+ self.window.collectionBehavior = (NSWindowCollectionBehaviorCanJoinAllSpaces
135
+ | NSWindowCollectionBehaviorFullScreenAuxiliary
136
+ | NSWindowCollectionBehaviorStationary);
137
+ self.window.minSize = NSMakeSize(520, 360);
138
+ self.window.title = @"古法编程悬浮层";
139
+
140
+ NSView *container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
141
+ container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
142
+ container.wantsLayer = YES;
143
+
144
+ WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
145
+ config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
146
+ /* URL query 可能被 DSH 的浏览器端路由吞掉,这里在文档开始前写一个标记,客户端据此进入悬浮模式 */
147
+ WKUserScript *floatMarker = [[WKUserScript alloc] initWithSource:@"try{localStorage.setItem('gufa-code:float','1')}catch(e){}"
148
+ injectionTime:WKUserScriptInjectionTimeAtDocumentStart
149
+ forMainFrameOnly:YES];
150
+ [config.userContentController addUserScript:floatMarker];
151
+ self.webView = [[WKWebView alloc] initWithFrame:container.bounds configuration:config];
152
+ self.webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
153
+ self.navigation = [[GufaNavigationDelegate alloc] init];
154
+ self.navigation.owner = self;
155
+ self.webView.navigationDelegate = self.navigation;
156
+ [self.webView setValue:@NO forKey:@"drawsBackground"];
157
+ [container addSubview:self.webView];
158
+
159
+ CGFloat stripHeight = 22.0;
160
+ GufaDragStrip *strip = [[GufaDragStrip alloc] initWithFrame:NSMakeRect(0, frame.size.height - stripHeight, frame.size.width, stripHeight)];
161
+ strip.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
162
+ [container addSubview:strip];
163
+
164
+ self.window.contentView = container;
165
+ [self.window makeKeyAndOrderFront:nil];
166
+ [NSApp activateIgnoringOtherApps:YES];
167
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidEndLiveResizeNotification object:self.window];
168
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidMoveNotification object:self.window];
169
+ }
170
+
171
+ - (void)buildStatusItem {
172
+ self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
173
+ self.statusItem.button.title = @"古法";
174
+ self.statusItem.button.toolTip = @"古法编程悬浮层";
175
+ NSMenu *menu = [[NSMenu alloc] init];
176
+ [menu addItemWithTitle:@"跟随 App 窗口…(需屏幕录制权限)" action:@selector(chooseFollowWindow:) keyEquivalent:@""].target = self;
177
+ [menu addItemWithTitle:@"停止跟随" action:@selector(stopFollow:) keyEquivalent:@""].target = self;
178
+ [menu addItem:[NSMenuItem separatorItem]];
179
+ [menu addItemWithTitle:@"切换点击穿透(穿透后鼠标可操作下层 App)" action:@selector(toggleClickThrough:) keyEquivalent:@""].target = self;
180
+ [menu addItemWithTitle:@"重置窗口位置和大小" action:@selector(resetFrame:) keyEquivalent:@""].target = self;
181
+ [menu addItem:[NSMenuItem separatorItem]];
182
+ [menu addItemWithTitle:@"关闭悬浮层" action:@selector(quitApp:) keyEquivalent:@""].target = self;
183
+ self.statusItem.menu = menu;
184
+ }
185
+
186
+ - (void)loadWebContent {
187
+ NSString *authUrl = self.options[@"authUrl"];
188
+ NSString *appUrl = self.options[@"appUrl"];
189
+ if (authUrl.length == 0 || appUrl.length == 0) {
190
+ NSAlert *alert = [[NSAlert alloc] init];
191
+ alert.messageText = @"古法编程悬浮层";
192
+ alert.informativeText = @"悬浮层启动参数缺失";
193
+ [alert runModal];
194
+ [NSApp terminate:nil];
195
+ return;
196
+ }
197
+ __weak typeof(self) weakSelf = self;
198
+ self.navigation.pendingLoad = ^{
199
+ __strong typeof(weakSelf) self = weakSelf;
200
+ if (self == nil) return;
201
+ NSURLComponents *components = [NSURLComponents componentsWithString:appUrl];
202
+ components.queryItems = @[[NSURLQueryItem queryItemWithName:@"gufa-float" value:@"1"]];
203
+ NSURL *clean = components.URL;
204
+ if (clean != nil && ![clean.absoluteString isEqualToString:self.webView.URL.absoluteString]) {
205
+ [self.webView loadRequest:[NSURLRequest requestWithURL:clean]];
206
+ }
207
+ };
208
+ [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:authUrl]]];
209
+ }
210
+
211
+ - (void)saveFrame {
212
+ if (self.window == nil) return;
213
+ [[NSUserDefaults standardUserDefaults] setObject:NSStringFromRect(self.window.frame) forKey:self.frameKey];
214
+ }
215
+
216
+ /* ── P1:跟随选中的 App 窗口 ───────────────────────────────────── */
217
+
218
+ /** 枚举屏幕上的普通窗口(需要屏幕录制权限才能看到别的 App)。 */
219
+ - (NSArray<NSDictionary *> *)visibleWindows {
220
+ NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
221
+ CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
222
+ if (list == NULL) return rows;
223
+ NSInteger count = CFArrayGetCount(list);
224
+ pid_t selfPid = NSProcessInfo.processInfo.processIdentifier;
225
+ for (NSInteger i = 0; i < count && rows.count < 60; i++) {
226
+ NSDictionary *info = (__bridge NSDictionary *)CFArrayGetValueAtIndex(list, i);
227
+ NSNumber *layer = info[(id)kCGWindowLayer];
228
+ if (![layer isKindOfClass:[NSNumber class]] || layer.intValue != 0) continue;
229
+ NSNumber *pid = info[(id)kCGWindowOwnerPID];
230
+ if (![pid isKindOfClass:[NSNumber class]] || pid.intValue == selfPid) continue;
231
+ NSNumber *number = info[(id)kCGWindowNumber];
232
+ NSDictionary *bounds = info[(id)kCGWindowBounds];
233
+ if (number == nil || bounds == nil) continue;
234
+ CGRect rect = CGRectZero;
235
+ if (!CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)bounds, &rect)) continue;
236
+ if (rect.size.width < 220 || rect.size.height < 160) continue;
237
+ NSString *owner = info[(id)kCGWindowOwnerName];
238
+ NSString *title = info[(id)kCGWindowName];
239
+ NSString *label = [NSString stringWithFormat:@"%@%@ · %.0f×%.0f",
240
+ owner != nil ? owner : @"?",
241
+ (title.length > 0 ? [NSString stringWithFormat:@" — %@", title] : @""),
242
+ rect.size.width, rect.size.height];
243
+ [rows addObject:@{
244
+ @"number": number,
245
+ @"pid": pid,
246
+ @"owner": owner != nil ? owner : @"?",
247
+ @"title": title != nil ? title : @"",
248
+ @"label": label,
249
+ @"rect": NSStringFromRect(NSRectFromCGRect(rect)),
250
+ }];
251
+ }
252
+ CFRelease(list);
253
+ return rows;
254
+ }
255
+
256
+ - (void)showPermissionGuide {
257
+ NSAlert *alert = [[NSAlert alloc] init];
258
+ alert.messageText = @"需要「屏幕录制」权限";
259
+ alert.informativeText = @"要跟随其他 App 的窗口大小,系统需要授予本悬浮层「屏幕录制」权限:\n\n系统设置 → 隐私与安全性 → 屏幕录制 → 勾选「古法编程悬浮层 / gufa-float」;授权后点「重试」。\n\n(只读取窗口尺寸,不录屏、不采集画面。)";
260
+ [alert addButtonWithTitle:@"打开系统设置"];
261
+ [alert addButtonWithTitle:@"取消"];
262
+ NSModalResponse response = [alert runModal];
263
+ if (response == NSAlertFirstButtonReturn) {
264
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"]];
265
+ }
266
+ }
267
+
268
+ - (void)chooseFollowWindow:(id)sender {
269
+ if (!CGPreflightScreenCaptureAccess()) {
270
+ CGRequestScreenCaptureAccess();
271
+ [self showPermissionGuide];
272
+ return;
273
+ }
274
+ NSArray<NSDictionary *> *rows = [self visibleWindows];
275
+ /* 只有一个窗口 = 权限没生效,仍是我们自己 */
276
+ if (rows.count == 0) {
277
+ [self showPermissionGuide];
278
+ return;
279
+ }
280
+ self.windowCandidates = [rows mutableCopy];
281
+
282
+ NSAlert *alert = [[NSAlert alloc] init];
283
+ alert.messageText = @"选择要跟随的 App 窗口";
284
+ alert.informativeText = @"悬浮层会保持与该窗口相同的位置和大小;窗口移动/缩放时自动跟随。";
285
+ NSPopUpButton *popup = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 420, 26) pullsDown:NO];
286
+ for (NSDictionary *row in self.windowCandidates) {
287
+ [popup addItemWithTitle:row[@"label"]];
288
+ }
289
+ alert.accessoryView = popup;
290
+ [alert addButtonWithTitle:@"开始跟随"];
291
+ [alert addButtonWithTitle:@"取消"];
292
+ if ([alert runModal] != NSAlertFirstButtonReturn) return;
293
+ NSInteger index = popup.indexOfSelectedItem;
294
+ if (index < 0 || index >= (NSInteger)self.windowCandidates.count) return;
295
+ NSDictionary *row = self.windowCandidates[(NSUInteger)index];
296
+ self.followWindowNumber = [row[@"number"] intValue];
297
+ self.followOwnerPID = (pid_t)[row[@"pid"] intValue];
298
+ self.following = YES;
299
+ [self startFollowTimer];
300
+ [self applyFollowFrame];
301
+ self.statusItem.button.title = @"古法·跟随";
302
+ }
303
+
304
+ - (void)stopFollow:(id)sender {
305
+ [self stopFollowTimer];
306
+ self.statusItem.button.title = self.clickThrough ? @"古法·穿透" : @"古法";
307
+ }
308
+
309
+ - (void)startFollowTimer {
310
+ [self stopFollowTimer];
311
+ __weak typeof(self) weakSelf = self;
312
+ self.followTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 repeats:YES block:^(NSTimer *timer) {
313
+ __strong typeof(weakSelf) self = weakSelf;
314
+ if (self == nil) return;
315
+ [self applyFollowFrame];
316
+ }];
317
+ }
318
+
319
+ - (void)stopFollowTimer {
320
+ if (self.followTimer != nil) {
321
+ [self.followTimer invalidate];
322
+ self.followTimer = nil;
323
+ }
324
+ self.following = NO;
325
+ }
326
+
327
+ /** 找到被跟随窗口当前 bounds,把悬浮窗贴上去(主屏坐标换算;多屏后续再完善)。 */
328
+ - (void)applyFollowFrame {
329
+ if (!self.following || self.followWindowNumber == 0) return;
330
+ CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
331
+ if (list == NULL) return;
332
+ CGRect target = CGRectZero;
333
+ BOOL found = NO;
334
+ NSInteger count = CFArrayGetCount(list);
335
+ for (NSInteger i = 0; i < count; i++) {
336
+ NSDictionary *info = (__bridge NSDictionary *)CFArrayGetValueAtIndex(list, i);
337
+ NSNumber *number = info[(id)kCGWindowNumber];
338
+ if (![number isKindOfClass:[NSNumber class]] || number.intValue != self.followWindowNumber) continue;
339
+ NSNumber *pid = info[(id)kCGWindowOwnerPID];
340
+ if (![pid isKindOfClass:[NSNumber class]] || pid.intValue != self.followOwnerPID) continue;
341
+ NSDictionary *bounds = info[(id)kCGWindowBounds];
342
+ if (bounds != nil && CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)bounds, &target)) found = YES;
343
+ break;
344
+ }
345
+ CFRelease(list);
346
+ if (!found) {
347
+ /* 目标窗口关闭:停止跟随,保持当前位置 */
348
+ [self stopFollowTimer];
349
+ self.statusItem.button.title = @"古法";
350
+ return;
351
+ }
352
+ CGFloat screenHeight = NSScreen.mainScreen.frame.size.height;
353
+ NSRect frame = NSMakeRect(target.origin.x, screenHeight - target.origin.y - target.size.height, target.size.width, target.size.height);
354
+ [self.window setFrame:frame display:YES animate:NO];
355
+ [self saveFrame];
356
+ }
357
+
358
+ - (void)toggleClickThrough:(id)sender {
359
+ self.clickThrough = !self.clickThrough;
360
+ self.window.ignoresMouseEvents = self.clickThrough;
361
+ self.statusItem.button.title = self.clickThrough ? @"古法·穿透" : @"古法";
362
+ }
363
+
364
+ - (void)resetFrame:(id)sender {
365
+ NSRect visible = NSScreen.mainScreen.visibleFrame;
366
+ CGFloat width = MIN(1180, visible.size.width * 0.86);
367
+ CGFloat height = MIN(820, visible.size.height * 0.86);
368
+ NSRect frame = NSMakeRect(visible.origin.x + (visible.size.width - width) / 2.0,
369
+ visible.origin.y + (visible.size.height - height) / 2.0,
370
+ width, height);
371
+ [self.window setFrame:frame display:YES];
372
+ [self saveFrame];
373
+ }
374
+
375
+ - (void)quitApp:(id)sender {
376
+ [self stopFollowTimer];
377
+ [self saveFrame];
378
+ [NSApp terminate:nil];
379
+ }
380
+
381
+ - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return YES; }
382
+
383
+ @end
384
+
385
+ int main(int argc, const char *argv[]) {
386
+ @autoreleasepool {
387
+ [NSApplication sharedApplication];
388
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
389
+ GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
390
+ NSApp.delegate = delegate;
391
+ [NSApp run];
392
+ }
393
+ return 0;
394
+ }
package/host/dev.js CHANGED
@@ -2,9 +2,31 @@
2
2
  * 开发/诊断信息:供客户端在启动时探测「Host 半是否为最新代码」。
3
3
  * 旧版本 Host(没有本方法)会让 api('dev.version') 返回 not-found,客户端据此提示重启 Harness。
4
4
  */
5
- import { appendFileSync } from 'node:fs'
5
+ import { appendFileSync, existsSync } from 'node:fs'
6
+ import { spawn } from 'node:child_process'
7
+ import { dirname, join } from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+ import { ApiError } from './context.js'
6
10
 
7
11
  const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
12
+ const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
13
+ /* 悬浮层子进程放在 globalThis:host 模块热重载后仍能持有同一个句柄 */
14
+ const floatState = globalThis.__gufaFloatState ?? (globalThis.__gufaFloatState = { child: null, startedAt: 0 })
15
+
16
+ /** 查找当前平台编译好的悬浮层 helper(P0 只支持 macOS)。 */
17
+ function floatBinaryPath() {
18
+ const arch = process.arch === 'arm64' ? 'arm64' : 'x64'
19
+ const candidates = [`gufa-float-macos-${arch}`, 'gufa-float-macos-arm64', 'gufa-float-macos-x64']
20
+ for (const name of candidates) {
21
+ const full = join(PLUGIN_ROOT, 'desktop', 'float', 'bin', name)
22
+ if (existsSync(full)) return full
23
+ }
24
+ return null
25
+ }
26
+
27
+ function floatRunning() {
28
+ return floatState.child !== null && floatState.child.exitCode === null && floatState.child.signalCode === null
29
+ }
8
30
 
9
31
  /** 追加一条客户端诊断日志(排查桌面壳/终端连接问题用)。 */
10
32
  export function debugLog(message) {
@@ -15,8 +37,64 @@ export function debugLog(message) {
15
37
  }
16
38
  }
17
39
 
18
- export function register(router) {
40
+ export function register(router, env) {
19
41
  const startedAt = new Date().toISOString()
42
+ const ctx = env?.ctx ?? router.ctx
43
+
44
+ /* ── 桌面悬浮层(P0,macOS) ─────────────────────────────────────── */
45
+ router.method('float.status', async () => ({
46
+ supported: process.platform === 'darwin' && floatBinaryPath() !== null,
47
+ platform: process.platform,
48
+ running: floatRunning(),
49
+ pid: floatRunning() ? floatState.child.pid : null,
50
+ binary: floatBinaryPath(),
51
+ }))
52
+
53
+ router.method('float.start', async () => {
54
+ if (process.platform !== 'darwin') throw new ApiError('unsupported', '桌面悬浮层目前只支持 macOS', 400)
55
+ const binary = floatBinaryPath()
56
+ if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建,请先运行 scripts/build-float-macos.sh', 500)
57
+ if (floatRunning()) return { running: true, pid: floatState.child.pid }
58
+ let webServer
59
+ let connection
60
+ try {
61
+ webServer = ctx.get('webServer')
62
+ connection = ctx.get('connection')
63
+ } catch {
64
+ /* ignore */
65
+ }
66
+ if (webServer === undefined || webServer === null || connection === undefined || connection === null || typeof connection.authenticatedUrl !== 'function') {
67
+ throw new ApiError('unavailable', '当前 Host 不提供 Web 服务地址,无法启动悬浮层', 500)
68
+ }
69
+ const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
70
+ const authUrl = connection.authenticatedUrl(`${base}/`)
71
+ const payload = JSON.stringify({ authUrl, appUrl: `${base}/` })
72
+ let child
73
+ try {
74
+ child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
75
+ } catch (error) {
76
+ throw new ApiError('spawn-failed', `悬浮层启动失败:${String(error && error.message || error)}`, 500)
77
+ }
78
+ child.unref()
79
+ floatState.child = child
80
+ floatState.startedAt = Date.now()
81
+ child.once('exit', () => {
82
+ if (floatState.child === child) floatState.child = null
83
+ })
84
+ return { running: true, pid: child.pid ?? null }
85
+ })
86
+
87
+ router.method('float.stop', async () => {
88
+ if (floatRunning()) {
89
+ try {
90
+ floatState.child.kill('SIGTERM')
91
+ } catch {
92
+ /* ignore */
93
+ }
94
+ }
95
+ floatState.child = null
96
+ return { running: false }
97
+ })
20
98
 
21
99
  router.method('dev.log', async (body) => {
22
100
  const message = body !== null && typeof body === 'object' && typeof body.message === 'string' ? body.message : ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -36,7 +36,8 @@
36
36
  "README.md",
37
37
  "LICENSE",
38
38
  "docs",
39
- "screenshots.json"
39
+ "screenshots.json",
40
+ "desktop"
40
41
  ],
41
42
  "dependencies": {
42
43
  "ws": "^8.22.0"
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+ # 构建 macOS 悬浮层 helper(P0):Objective-C + AppKit + WebKit,避免本机 Swift/SDK 版本不匹配问题。
3
+ set -euo pipefail
4
+ cd "$(dirname "$0")/.."
5
+ mkdir -p desktop/float/bin
6
+ ARCH="$(uname -m)"
7
+ OUT="desktop/float/bin/gufa-float-macos-${ARCH}"
8
+ clang -fobjc-arc -O2 -framework AppKit -framework WebKit -o "$OUT" desktop/float/GufaFloat.m
9
+ chmod +x "$OUT"
10
+ codesign --force --sign - "$OUT" >/dev/null 2>&1 || true
11
+ echo "built: $OUT"
@@ -1019,6 +1019,33 @@ G.errorText = (error) => {
1019
1019
  G.CSS = `
1020
1020
  .gufa-overlay-root{position:fixed;inset:0;z-index:1;display:flex;box-sizing:border-box;background:var(--gufa-solid-bg, var(--dsw-alias-bg-base));pointer-events:auto;overflow:hidden}
1021
1021
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1022
+ /* 桌面悬浮层模式:整窗半透明(0.55),顶部留出 22px 拖动条 */
1023
+ html[data-gufa-float] body{background:transparent!important}
1024
+ html[data-gufa-float] .gufa-overlay-root,
1025
+ html[data-gufa-float] .gufa-root{
1026
+ --gufa-solid-bg:rgba(13,15,19,0.55);--gufa-bg:rgba(13,15,19,0.55);
1027
+ --gufa-solid-layer:rgba(20,22,27,0.55);--gufa-layer:rgba(20,22,27,0.55);
1028
+ --gufa-solid-layer2:rgba(26,28,34,0.55);--gufa-layer2:rgba(26,28,34,0.55);
1029
+ --gufa-solid-overlay:rgba(30,33,40,0.72);
1030
+ }
1031
+ html[data-gufa-float] .gufa-overlay-root{background:transparent!important;padding-top:22px;box-sizing:border-box}
1032
+ html[data-gufa-float] .gufa-backdrop{opacity:0.5}
1033
+ /* 悬浮模式:右侧停靠的官方会话内部也半透明(DSH 主题变量在停靠根上覆盖) */
1034
+ html[data-gufa-float] [data-gufa-dock]{
1035
+ --dsw-alias-bg-base:rgba(13,15,19,0.55);
1036
+ --dsw-alias-bg-layer-1:rgba(20,22,27,0.55);
1037
+ --dsw-alias-bg-layer-2:rgba(26,28,34,0.55);
1038
+ --dsw-alias-bg-overlay:rgba(30,33,40,0.72);
1039
+ background:rgba(13,15,19,0.55)!important;
1040
+ }
1041
+ html[data-gufa-float] [data-gufa-dock] [data-conversation-scroll],
1042
+ html[data-gufa-float] [data-gufa-dock] [data-conversation-content]{background:transparent!important}
1043
+ /* 经典 DSH 界面在悬浮窗里整体隐藏(保留古法覆盖层与右侧停靠会话),否则半透明下会透出「另一个 DSH」 */
1044
+ html[data-gufa-float] #root{visibility:hidden!important}
1045
+ html[data-gufa-float] #root .gufa-overlay-root,
1046
+ html[data-gufa-float] #root [data-gufa-dock],
1047
+ html[data-gufa-float] #root .gufa-overlay-root *,
1048
+ html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1022
1049
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1023
1050
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1024
1051
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
@@ -14,6 +14,10 @@ const ICON_PATHS = {
14
14
  ['path', { d: 'M12 5v14' }],
15
15
  ['path', { d: 'M6 13l6 6 6-6' }],
16
16
  ],
17
+ monitor: [
18
+ ['rect', { x: 3, y: 4.5, width: 18, height: 12, rx: 2 }],
19
+ ['path', { d: 'M9 20h6M12 16.5V20' }],
20
+ ],
17
21
  graph: [
18
22
  ['circle', { cx: 6, cy: 6, r: 2.2 }],
19
23
  ['circle', { cx: 6, cy: 18, r: 2.2 }],
@@ -85,7 +85,10 @@ function gufaPlaceDockedConversation(root, host, options) {
85
85
  /* ignore */
86
86
  }
87
87
  const backdropMode = options !== null && options !== undefined && options.translucent === true
88
- if (backdropMode && dockBackground !== '') root.style.background = `color-mix(in srgb, ${dockBackground} 34%, transparent)`
88
+ let floatMode = false
89
+ try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
90
+ if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
91
+ else if (backdropMode && dockBackground !== '') root.style.background = `color-mix(in srgb, ${dockBackground} 34%, transparent)`
89
92
  else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
90
93
  root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
91
94
  root.style.boxSizing = 'border-box'
@@ -155,6 +155,8 @@ G.GufaApp = function GufaApp(props) {
155
155
  const sessionTitle = useSessions !== undefined ? useSessions(selectSessionTitle) : null
156
156
  const currentSessionId = useSessions !== undefined ? useSessions(selectMainSessionId) : null
157
157
  const [sessionsOpen, setSessionsOpen] = useState(false)
158
+ const [floatRunning, setFloatRunning] = useState(false)
159
+ const [floatBusy, setFloatBusy] = useState(false)
158
160
  /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
159
161
  const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
160
162
  const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
@@ -790,6 +792,63 @@ G.GufaApp = function GufaApp(props) {
790
792
  /* 会话弹窗里选了别的工作区的会话:右侧会话保持不动,不再自动把 IDE 项目切过去 */
791
793
  const sessionPinnedRef = useRef(false)
792
794
 
795
+ /* ── 桌面悬浮层:URL 带 ?gufa-float=1 时自动进入 IDE 并用半透明皮肤 ── */
796
+ const floatRequested = (() => {
797
+ try {
798
+ if (typeof location !== 'undefined' && /[?&]gufa-float=1/.test(location.search)) return true
799
+ return typeof localStorage !== 'undefined' && localStorage.getItem('gufa-code:float') === '1'
800
+ } catch {
801
+ return false
802
+ }
803
+ })()
804
+ useEffect(() => {
805
+ if (floatRequested !== true) return undefined
806
+ try { document.documentElement.setAttribute('data-gufa-float', '1') } catch { /* ignore */ }
807
+ const enter = (attempt) => {
808
+ try {
809
+ if (typeof G.mode?.get === 'function' && G.mode.get() !== true) G.mode.set(true)
810
+ } catch { /* ignore */ }
811
+ void G.api('dev.log', {
812
+ message: `float-mode enter attempt=${attempt} mode=${String(typeof G.mode?.get === 'function' ? G.mode.get() : 'n/a')} overlay=${document.querySelector('.gufa-overlay-root') !== null}`,
813
+ }).catch(() => {})
814
+ }
815
+ const first = window.setTimeout(() => enter(1), 400)
816
+ const second = window.setTimeout(() => enter(2), 2000)
817
+ return () => {
818
+ window.clearTimeout(first)
819
+ window.clearTimeout(second)
820
+ }
821
+ }, [floatRequested])
822
+
823
+ /* 悬浮层运行状态(主窗口里显示按钮状态用) */
824
+ useEffect(() => {
825
+ let cancelled = false
826
+ void G.api('float.status').then((value) => {
827
+ if (!cancelled) setFloatRunning(value?.running === true)
828
+ }).catch(() => { /* 旧 host 没有该方法 */ })
829
+ return () => { cancelled = true }
830
+ }, [])
831
+
832
+ const toggleFloatWindow = useCallback(async () => {
833
+ if (floatBusy) return
834
+ setFloatBusy(true)
835
+ try {
836
+ if (floatRunning) {
837
+ await G.api('float.stop')
838
+ setFloatRunning(false)
839
+ setBanner('悬浮层已关闭')
840
+ } else {
841
+ const value = await G.api('float.start')
842
+ setFloatRunning(value?.running === true)
843
+ setBanner('悬浮层已启动:屏幕上的半透明窗口,菜单栏「古法」可切换点击穿透')
844
+ }
845
+ } catch (error) {
846
+ setBanner(G.errorText(error))
847
+ } finally {
848
+ setFloatBusy(false)
849
+ }
850
+ }, [floatBusy, floatRunning])
851
+
793
852
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
794
853
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
795
854
  * (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
@@ -1699,6 +1758,12 @@ G.GufaApp = function GufaApp(props) {
1699
1758
  }),
1700
1759
  }, h(G.Icon, { name: 'image', size: 16 }))
1701
1760
  : null,
1761
+ h(G.IconButton, {
1762
+ title: floatRunning ? '关闭桌面悬浮层' : '打开桌面悬浮层(半透明置顶窗口)',
1763
+ 'data-active': floatRunning ? '' : undefined,
1764
+ disabled: floatBusy,
1765
+ onClick: () => void toggleFloatWindow(),
1766
+ }, h(G.Icon, { name: 'monitor', size: 15 })),
1702
1767
  h(G.IconButton, { title: t('app.refresh'), onClick: () => { setRefreshToken((token) => token + 1); setGitRefreshToken((token) => token + 1); setSshRefreshToken((token) => token + 1) } }, h(G.Icon, { name: 'refresh', size: 15 })),
1703
1768
  h(G.IconButton, {
1704
1769
  title: ui.chatOpen ? t('activity.collapseChat') : t('activity.expandChat'),