dsh-gufa-code 1.3.5 → 1.3.6
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/client.js +38 -0
- package/desktop/float/GufaFloat.m +45 -9
- 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 +20 -9
- package/package.json +1 -1
- package/src/client/00-core.js +3 -0
- package/src/client/99-main.js +35 -0
package/client.js
CHANGED
|
@@ -1071,6 +1071,9 @@ html[data-gufa-float] [data-gufa-dock]{
|
|
|
1071
1071
|
}
|
|
1072
1072
|
html[data-gufa-float] [data-gufa-dock] [data-conversation-scroll],
|
|
1073
1073
|
html[data-gufa-float] [data-gufa-dock] [data-conversation-content]{background:transparent!important}
|
|
1074
|
+
/* 悬浮层启动瞬间:先隐藏经典界面,避免闪一下「另一个 DSH」 */
|
|
1075
|
+
html[data-gufa-booting] body{background:transparent!important}
|
|
1076
|
+
html[data-gufa-booting] #root{visibility:hidden!important}
|
|
1074
1077
|
/* 经典 DSH 界面在悬浮窗里整体隐藏(保留古法覆盖层与右侧停靠会话),否则半透明下会透出「另一个 DSH」 */
|
|
1075
1078
|
html[data-gufa-float] #root{visibility:hidden!important}
|
|
1076
1079
|
html[data-gufa-float] #root .gufa-overlay-root,
|
|
@@ -12220,6 +12223,41 @@ const GUFA_PLUGIN = {
|
|
|
12220
12223
|
apply(ctx) {
|
|
12221
12224
|
G.ctx = ctx
|
|
12222
12225
|
|
|
12226
|
+
/* ── 悬浮层模式(?gufa-float=1 或 helper 注入的 localStorage 标记)──
|
|
12227
|
+
* 尽早打标记并隐藏经典 DSH 界面,避免先闪出一个「另一个 DSH」;
|
|
12228
|
+
* 同时重试进入 IDE 模式,直到覆盖层挂载完成。 */
|
|
12229
|
+
try {
|
|
12230
|
+
let floatMode = false
|
|
12231
|
+
try {
|
|
12232
|
+
floatMode = /[?&]gufa-float=1/.test(String(location.search || '')) || localStorage.getItem('gufa-code:float') === '1'
|
|
12233
|
+
} catch {
|
|
12234
|
+
floatMode = false
|
|
12235
|
+
}
|
|
12236
|
+
if (floatMode) {
|
|
12237
|
+
document.documentElement.setAttribute('data-gufa-float', '1')
|
|
12238
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
12239
|
+
let attempts = 0
|
|
12240
|
+
const timer = window.setInterval(() => {
|
|
12241
|
+
attempts += 1
|
|
12242
|
+
try {
|
|
12243
|
+
if (typeof G.mode?.get === 'function' && G.mode.get() !== true) G.mode.set(true)
|
|
12244
|
+
} catch {
|
|
12245
|
+
/* ignore */
|
|
12246
|
+
}
|
|
12247
|
+
if (document.querySelector('.gufa-overlay-root') !== null || attempts > 40) {
|
|
12248
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
12249
|
+
window.clearInterval(timer)
|
|
12250
|
+
}
|
|
12251
|
+
}, 250)
|
|
12252
|
+
ctx.effect(() => () => {
|
|
12253
|
+
window.clearInterval(timer)
|
|
12254
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
12255
|
+
}, 'gufa-code: float boot')
|
|
12256
|
+
}
|
|
12257
|
+
} catch (error) {
|
|
12258
|
+
console.error('[gufa-code] 悬浮模式初始化失败', error)
|
|
12259
|
+
}
|
|
12260
|
+
|
|
12223
12261
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
12224
12262
|
try {
|
|
12225
12263
|
if (typeof G.mode?.get === 'function' && G.mode.get() === true) document.documentElement.setAttribute('data-gufa-ide', '')
|
|
@@ -20,6 +20,23 @@ static const EventHotKeyID GufaToggleHotKey = {'gufa', 1};
|
|
|
20
20
|
|
|
21
21
|
/* 前置声明(实现位于文件后半部分) */
|
|
22
22
|
static NSString *GufaOutputPath = nil;
|
|
23
|
+
/** 悬浮层诊断日志(/tmp/gufa-float-debug.log)。 */
|
|
24
|
+
static void GufaLog(NSString *format, ...) {
|
|
25
|
+
va_list args;
|
|
26
|
+
va_start(args, format);
|
|
27
|
+
NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
|
|
28
|
+
va_end(args);
|
|
29
|
+
NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
|
|
30
|
+
NSString *line = [NSString stringWithFormat:@"[%@] %@\n", [formatter stringFromDate:[NSDate date]], message];
|
|
31
|
+
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:@"/tmp/gufa-float-debug.log"];
|
|
32
|
+
if (handle == nil) {
|
|
33
|
+
[line writeToFile:@"/tmp/gufa-float-debug.log" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
|
|
34
|
+
} else {
|
|
35
|
+
[handle seekToEndOfFile];
|
|
36
|
+
[handle writeData:[line dataUsingEncoding:NSUTF8StringEncoding]];
|
|
37
|
+
[handle closeFile];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
23
40
|
static void GufaEmitJSON(NSDictionary *out);
|
|
24
41
|
static BOOL GufaTrustedForAX(void);
|
|
25
42
|
static NSArray<NSDictionary *> *GufaAXWindows(void);
|
|
@@ -105,6 +122,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
105
122
|
- (void)registerToggleHotKey;
|
|
106
123
|
- (void)activateTargetApp;
|
|
107
124
|
- (void)beginningFollowFromOptions;
|
|
125
|
+
- (void)findFollowWindowWithRetries:(NSInteger)attempt;
|
|
108
126
|
- (void)exitMoyu:(id)sender;
|
|
109
127
|
- (void)restoreMainWindow;
|
|
110
128
|
- (void)toggleClickThrough:(id)sender;
|
|
@@ -163,15 +181,33 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
163
181
|
if (![pid isKindOfClass:[NSNumber class]]) return;
|
|
164
182
|
self.followPid = (pid_t)pid.intValue;
|
|
165
183
|
self.followTitle = [follow[@"title"] isKindOfClass:[NSString class]] ? follow[@"title"] : @"";
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
184
|
+
GufaLog(@"follow-start pid=%d bundle=%@ axTrusted=%d", self.followPid, follow[@"bundleId"] ?: @"", GufaTrustedForAX() ? 1 : 0);
|
|
185
|
+
[self findFollowWindowWithRetries:0];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* 激活 App 后窗口可能还在切 Space,轮询最多 5 秒找它的窗口。 */
|
|
189
|
+
- (void)findFollowWindowWithRetries:(NSInteger)attempt {
|
|
190
|
+
AXUIElementRef window = GufaCopyAppWindow(self.followPid);
|
|
191
|
+
if (window == NULL) {
|
|
192
|
+
if (attempt >= 20) {
|
|
193
|
+
GufaLog(@"follow-window-not-found pid=%d attempts=%ld axTrusted=%d", self.followPid, (long)attempt, GufaTrustedForAX() ? 1 : 0);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
__weak typeof(self) weakSelf = self;
|
|
197
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
198
|
+
[weakSelf findFollowWindowWithRetries:attempt + 1];
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
NSRect rect = NSZeroRect;
|
|
203
|
+
GufaRectFromAX(window, &rect);
|
|
204
|
+
GufaLog(@"follow-window-found pid=%d rect=%.0f,%.0f %.0fx%.0f attempt=%ld", self.followPid, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, (long)attempt);
|
|
205
|
+
if (self.followWindowRef != NULL) CFRelease(self.followWindowRef);
|
|
206
|
+
self.followWindowRef = window;
|
|
207
|
+
self.following = YES;
|
|
208
|
+
[self startFollowTimer];
|
|
209
|
+
[self applyFollowFrame];
|
|
210
|
+
self.statusItem.button.title = @"古法·摸鱼";
|
|
175
211
|
}
|
|
176
212
|
|
|
177
213
|
- (void)parseOptions {
|
|
Binary file
|
|
Binary file
|
package/host/dev.js
CHANGED
|
@@ -59,15 +59,22 @@ export function register(router, env) {
|
|
|
59
59
|
}
|
|
60
60
|
return null
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const floatProcessPatterns = ['gufa-float-macos-', '古法编程悬浮层.app/Contents/MacOS/gufa-float']
|
|
63
63
|
|
|
64
64
|
const listFloatPids = async () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const pids = new Set()
|
|
66
|
+
for (const pattern of floatProcessPatterns) {
|
|
67
|
+
try {
|
|
68
|
+
const { stdout } = await runFile('pgrep', ['-f', pattern], { timeout: 3000 })
|
|
69
|
+
for (const line of String(stdout ?? '').split('\n')) {
|
|
70
|
+
const pid = Number(line.trim())
|
|
71
|
+
if (Number.isFinite(pid) && pid > 0) pids.add(pid)
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
/* 没匹配到 */
|
|
75
|
+
}
|
|
70
76
|
}
|
|
77
|
+
return [...pids]
|
|
71
78
|
}
|
|
72
79
|
const floatRunningAsync = async () => (await listFloatPids()).length > 0
|
|
73
80
|
|
|
@@ -206,11 +213,15 @@ export function register(router, env) {
|
|
|
206
213
|
const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
|
|
207
214
|
const authUrl = connection.authenticatedUrl(`${base}/`)
|
|
208
215
|
const payload = JSON.stringify({ authUrl, appUrl: `${base}/`, follow: follow !== null && follow.pid > 0 ? follow : undefined })
|
|
209
|
-
|
|
216
|
+
const binary = floatBinaryPath()
|
|
217
|
+
if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建', 500)
|
|
218
|
+
const child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
|
|
219
|
+
child.unref()
|
|
220
|
+
floatState.child = child
|
|
221
|
+
floatState.startedAt = Date.now()
|
|
210
222
|
await new Promise((resolve) => setTimeout(resolve, 300))
|
|
211
223
|
const pids = await listFloatPids()
|
|
212
|
-
|
|
213
|
-
return { running: pids.length > 0, pid: pids[0] ?? null }
|
|
224
|
+
return { running: pids.length > 0 || child.exitCode === null, pid: child.pid ?? pids[0] ?? null }
|
|
214
225
|
})
|
|
215
226
|
|
|
216
227
|
router.method('float.stop', async () => {
|
package/package.json
CHANGED
package/src/client/00-core.js
CHANGED
|
@@ -1063,6 +1063,9 @@ html[data-gufa-float] [data-gufa-dock]{
|
|
|
1063
1063
|
}
|
|
1064
1064
|
html[data-gufa-float] [data-gufa-dock] [data-conversation-scroll],
|
|
1065
1065
|
html[data-gufa-float] [data-gufa-dock] [data-conversation-content]{background:transparent!important}
|
|
1066
|
+
/* 悬浮层启动瞬间:先隐藏经典界面,避免闪一下「另一个 DSH」 */
|
|
1067
|
+
html[data-gufa-booting] body{background:transparent!important}
|
|
1068
|
+
html[data-gufa-booting] #root{visibility:hidden!important}
|
|
1066
1069
|
/* 经典 DSH 界面在悬浮窗里整体隐藏(保留古法覆盖层与右侧停靠会话),否则半透明下会透出「另一个 DSH」 */
|
|
1067
1070
|
html[data-gufa-float] #root{visibility:hidden!important}
|
|
1068
1071
|
html[data-gufa-float] #root .gufa-overlay-root,
|
package/src/client/99-main.js
CHANGED
|
@@ -218,6 +218,41 @@ const GUFA_PLUGIN = {
|
|
|
218
218
|
apply(ctx) {
|
|
219
219
|
G.ctx = ctx
|
|
220
220
|
|
|
221
|
+
/* ── 悬浮层模式(?gufa-float=1 或 helper 注入的 localStorage 标记)──
|
|
222
|
+
* 尽早打标记并隐藏经典 DSH 界面,避免先闪出一个「另一个 DSH」;
|
|
223
|
+
* 同时重试进入 IDE 模式,直到覆盖层挂载完成。 */
|
|
224
|
+
try {
|
|
225
|
+
let floatMode = false
|
|
226
|
+
try {
|
|
227
|
+
floatMode = /[?&]gufa-float=1/.test(String(location.search || '')) || localStorage.getItem('gufa-code:float') === '1'
|
|
228
|
+
} catch {
|
|
229
|
+
floatMode = false
|
|
230
|
+
}
|
|
231
|
+
if (floatMode) {
|
|
232
|
+
document.documentElement.setAttribute('data-gufa-float', '1')
|
|
233
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
234
|
+
let attempts = 0
|
|
235
|
+
const timer = window.setInterval(() => {
|
|
236
|
+
attempts += 1
|
|
237
|
+
try {
|
|
238
|
+
if (typeof G.mode?.get === 'function' && G.mode.get() !== true) G.mode.set(true)
|
|
239
|
+
} catch {
|
|
240
|
+
/* ignore */
|
|
241
|
+
}
|
|
242
|
+
if (document.querySelector('.gufa-overlay-root') !== null || attempts > 40) {
|
|
243
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
244
|
+
window.clearInterval(timer)
|
|
245
|
+
}
|
|
246
|
+
}, 250)
|
|
247
|
+
ctx.effect(() => () => {
|
|
248
|
+
window.clearInterval(timer)
|
|
249
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
250
|
+
}, 'gufa-code: float boot')
|
|
251
|
+
}
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.error('[gufa-code] 悬浮模式初始化失败', error)
|
|
254
|
+
}
|
|
255
|
+
|
|
221
256
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
222
257
|
try {
|
|
223
258
|
if (typeof G.mode?.get === 'function' && G.mode.get() === true) document.documentElement.setAttribute('data-gufa-ide', '')
|