dsh-gufa-code 1.3.10 → 1.3.49
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 +19 -11
- package/client.js +670 -97
- package/desktop/float/GufaFloat.m +283 -29
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +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/Info.plist +2 -2
- 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/docs/KNOWN-PITFALLS.md +61 -0
- package/docs/MODES.md +42 -0
- package/host/dev.js +125 -6
- package/package.json +1 -1
- package/scripts/build-client.mjs +5 -1
- package/scripts/build-float-macos.sh +43 -14
- package/src/client/00-core.js +121 -12
- package/src/client/30-terminal.js +51 -8
- package/src/client/55-backdrop.js +28 -4
- package/src/client/85-shortcuts.js +22 -16
- package/src/client/90-app.js +320 -44
- package/src/client/99-main.js +128 -13
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
#import <AppKit/AppKit.h>
|
|
13
13
|
#import <WebKit/WebKit.h>
|
|
14
|
+
#include <dlfcn.h>
|
|
14
15
|
#import <CoreGraphics/CoreGraphics.h>
|
|
15
16
|
#import <ApplicationServices/ApplicationServices.h>
|
|
16
17
|
#import <Carbon/Carbon.h>
|
|
@@ -43,6 +44,11 @@ static NSArray<NSDictionary *> *GufaAXWindows(void);
|
|
|
43
44
|
static AXUIElementRef GufaCopyAXWindow(pid_t pid, NSString *title);
|
|
44
45
|
static BOOL GufaRectFromAX(AXUIElementRef element, NSRect *out);
|
|
45
46
|
static void GufaActivateBundle(NSString *bundleId);
|
|
47
|
+
static BOOL GufaAXWindowFullScreen(AXUIElementRef window);
|
|
48
|
+
static CGWindowID GufaAXWindowNumber(AXUIElementRef window);
|
|
49
|
+
static int GufaMoveWindowToTargetSpace(NSWindow *window, AXUIElementRef targetWindow);
|
|
50
|
+
static void GufaLogOwnWindowState(NSString *tag);
|
|
51
|
+
static void GufaSetMainAppHidden(BOOL hidden);
|
|
46
52
|
static NSArray<NSDictionary *> *GufaAXApps(void);
|
|
47
53
|
static AXUIElementRef GufaCopyAppWindow(pid_t pid);
|
|
48
54
|
|
|
@@ -107,6 +113,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
107
113
|
@property (nonatomic, strong) NSStatusItem *statusItem;
|
|
108
114
|
@property (nonatomic, strong) NSMenu *mainMenu;
|
|
109
115
|
@property (nonatomic, strong) GufaDragStrip *dragStrip;
|
|
116
|
+
@property (nonatomic, assign) BOOL cachesCleared;
|
|
117
|
+
@property (nonatomic, strong) NSString *controlPath;
|
|
118
|
+
@property (nonatomic, strong) NSTimer *controlTimer;
|
|
110
119
|
@property (nonatomic, assign) BOOL clickThrough;
|
|
111
120
|
@property (nonatomic, strong) NSString *frameKey;
|
|
112
121
|
@property (nonatomic, strong) GufaNavigationDelegate *navigation;
|
|
@@ -125,6 +134,12 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
125
134
|
- (void)findFollowWindowWithRetries:(NSInteger)attempt;
|
|
126
135
|
- (void)exitMoyu:(id)sender;
|
|
127
136
|
- (void)restoreMainWindow;
|
|
137
|
+
- (void)clearWebCachesThenLoad;
|
|
138
|
+
- (void)performInitialLoad;
|
|
139
|
+
- (void)applySpaceBehaviorFollowing:(BOOL)following;
|
|
140
|
+
- (void)attachToFollowedSpace;
|
|
141
|
+
- (void)watchControlFile;
|
|
142
|
+
- (void)gracefulExit;
|
|
128
143
|
- (void)toggleClickThrough:(id)sender;
|
|
129
144
|
- (void)resetFrame:(id)sender;
|
|
130
145
|
- (void)quitApp:(id)sender;
|
|
@@ -150,12 +165,27 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
150
165
|
self.frameKey = @"gufa-float-frame-v1";
|
|
151
166
|
self.clickThrough = NO;
|
|
152
167
|
[self parseOptions];
|
|
153
|
-
[self
|
|
154
|
-
[self
|
|
155
|
-
|
|
168
|
+
if ([self.options[@"controlPath"] isKindOfClass:[NSString class]]) self.controlPath = self.options[@"controlPath"];
|
|
169
|
+
[self watchControlFile];
|
|
170
|
+
/* 先激活目标 App:等它切到自己的 Space/全屏 Space 后再创建悬浮窗,
|
|
171
|
+
窗口就会直接创建在目标 Space 里(全屏 App 吸附的关键)。 */
|
|
172
|
+
BOOL hasFollow = [self.options[@"follow"] isKindOfClass:[NSDictionary class]];
|
|
156
173
|
[self activateTargetApp];
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
NSTimeInterval delay = hasFollow ? 0.9 : 0.0;
|
|
175
|
+
__weak typeof(self) weakSelf = self;
|
|
176
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
177
|
+
__strong typeof(weakSelf) self = weakSelf;
|
|
178
|
+
if (self == nil) return;
|
|
179
|
+
[self buildWindow];
|
|
180
|
+
[self buildStatusItem];
|
|
181
|
+
[self registerToggleHotKey];
|
|
182
|
+
/* 摸鱼:等目标 App 到前台后隐藏 DSH 主窗口(⌘H 效果) */
|
|
183
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.45 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
184
|
+
GufaSetMainAppHidden(YES);
|
|
185
|
+
});
|
|
186
|
+
[self beginningFollowFromOptions];
|
|
187
|
+
[self loadWebContent];
|
|
188
|
+
});
|
|
159
189
|
}
|
|
160
190
|
|
|
161
191
|
/** 吸附目标 App:把它切到前台(主窗口自然被盖住 + 切到它所在的 Space)。 */
|
|
@@ -176,9 +206,16 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
176
206
|
/** 启动就进入「吸附跟随」模式(摸鱼列表选好 App 后直接启动)。 */
|
|
177
207
|
- (void)beginningFollowFromOptions {
|
|
178
208
|
NSDictionary *follow = self.options[@"follow"];
|
|
179
|
-
if (![follow isKindOfClass:[NSDictionary class]])
|
|
209
|
+
if (![follow isKindOfClass:[NSDictionary class]]) {
|
|
210
|
+
/* 自由悬浮:没有吸附目标,允许出现在所有 Space */
|
|
211
|
+
[self applySpaceBehaviorFollowing:NO];
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
180
214
|
NSNumber *pid = follow[@"pid"];
|
|
181
|
-
if (![pid isKindOfClass:[NSNumber class]])
|
|
215
|
+
if (![pid isKindOfClass:[NSNumber class]]) {
|
|
216
|
+
[self applySpaceBehaviorFollowing:NO];
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
182
219
|
self.followPid = (pid_t)pid.intValue;
|
|
183
220
|
self.followTitle = [follow[@"title"] isKindOfClass:[NSString class]] ? follow[@"title"] : @"";
|
|
184
221
|
GufaLog(@"follow-start pid=%d bundle=%@ axTrusted=%d", self.followPid, follow[@"bundleId"] ?: @"", GufaTrustedForAX() ? 1 : 0);
|
|
@@ -201,15 +238,78 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
201
238
|
}
|
|
202
239
|
NSRect rect = NSZeroRect;
|
|
203
240
|
GufaRectFromAX(window, &rect);
|
|
204
|
-
|
|
241
|
+
BOOL fullScreen = GufaAXWindowFullScreen(window);
|
|
242
|
+
GufaLog(@"follow-window-found pid=%d rect=%.0f,%.0f %.0fx%.0f fullscreen=%d attempt=%ld", self.followPid, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, fullScreen ? 1 : 0, (long)attempt);
|
|
205
243
|
if (self.followWindowRef != NULL) CFRelease(self.followWindowRef);
|
|
206
244
|
self.followWindowRef = window;
|
|
207
245
|
self.following = YES;
|
|
246
|
+
/* 吸附模式:窗口只留在「被跟随 App 所在的 Space」,用户切屏不跟过去 */
|
|
247
|
+
[self applySpaceBehaviorFollowing:YES];
|
|
208
248
|
[self startFollowTimer];
|
|
209
249
|
[self applyFollowFrame];
|
|
250
|
+
[self attachToFollowedSpace];
|
|
210
251
|
self.statusItem.button.title = @"古法·摸鱼";
|
|
211
252
|
}
|
|
212
253
|
|
|
254
|
+
/* Host 的 float.stop 通过「控制文件」通知退出:写入文件 → helper 恢复主窗口后自行退出。
|
|
255
|
+
(SIGTERM 在该 AppKit 进程里不可靠,实测 dispatch signal source 不触发) */
|
|
256
|
+
- (void)watchControlFile {
|
|
257
|
+
if (self.controlPath.length == 0) return;
|
|
258
|
+
self.controlTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 repeats:YES block:^(NSTimer *timer) {
|
|
259
|
+
if (self.controlPath.length == 0) return;
|
|
260
|
+
if (![[NSFileManager defaultManager] fileExistsAtPath:self.controlPath]) return;
|
|
261
|
+
[timer invalidate];
|
|
262
|
+
self.controlTimer = nil;
|
|
263
|
+
[[NSFileManager defaultManager] removeItemAtPath:self.controlPath error:NULL];
|
|
264
|
+
[self gracefulExit];
|
|
265
|
+
}];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
- (void)gracefulExit {
|
|
269
|
+
GufaLog(@"graceful-exit path=%@", self.controlPath ?: @"");
|
|
270
|
+
[self restoreMainWindow];
|
|
271
|
+
[self stopFollowTimer];
|
|
272
|
+
[self saveFrame];
|
|
273
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
274
|
+
[NSApp terminate:nil];
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* 把悬浮窗挪到「被跟随 App 当前所在的 Space」:
|
|
279
|
+
先 MoveToActiveSpace 排序到前台(目标 App 已被激活,其全屏 Space 即当前活动 Space),
|
|
280
|
+
再恢复为固定 Space 行为,这样之后用户滑屏不会把它带走。 */
|
|
281
|
+
- (void)attachToFollowedSpace {
|
|
282
|
+
if (self.window == nil) return;
|
|
283
|
+
NSWindowCollectionBehavior base = (NSWindowCollectionBehaviorFullScreenAuxiliary
|
|
284
|
+
| NSWindowCollectionBehaviorIgnoresCycle);
|
|
285
|
+
/* 首选:SkyLight 直接把窗口放进目标 App 窗口所在的 Space(全屏/多屏最可靠) */
|
|
286
|
+
int moveErr = GufaMoveWindowToTargetSpace(self.window, self.followWindowRef);
|
|
287
|
+
(void)moveErr;
|
|
288
|
+
/* 兜底:MoveToActiveSpace 排序到前台 */
|
|
289
|
+
self.window.collectionBehavior = base | NSWindowCollectionBehaviorMoveToActiveSpace;
|
|
290
|
+
[self.window orderFrontRegardless];
|
|
291
|
+
[self.window makeKeyWindow];
|
|
292
|
+
GufaLog(@"space-jump moveToActiveSpace screen=%@", self.window.screen == nil ? @"nil" : NSStringFromRect(self.window.screen.frame));
|
|
293
|
+
__weak typeof(self) weakSelf = self;
|
|
294
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.9 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
295
|
+
__strong typeof(weakSelf) self = weakSelf;
|
|
296
|
+
if (self == nil || self.window == nil) return;
|
|
297
|
+
self.window.collectionBehavior = base;
|
|
298
|
+
GufaLog(@"space-attached screen=%@", self.window.screen == nil ? @"nil" : NSStringFromRect(self.window.screen.frame));
|
|
299
|
+
GufaLogOwnWindowState(@"space-attached");
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* Space 行为:跟随 App 时固定在其 Space;自由悬浮时允许出现在所有 Space。 */
|
|
304
|
+
- (void)applySpaceBehaviorFollowing:(BOOL)following {
|
|
305
|
+
if (self.window == nil) return;
|
|
306
|
+
NSWindowCollectionBehavior behavior = (NSWindowCollectionBehaviorFullScreenAuxiliary
|
|
307
|
+
| NSWindowCollectionBehaviorIgnoresCycle);
|
|
308
|
+
if (!following) behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
|
|
309
|
+
self.window.collectionBehavior = behavior;
|
|
310
|
+
GufaLog(@"space-behavior following=%d raw=%lu", following ? 1 : 0, (unsigned long)behavior);
|
|
311
|
+
}
|
|
312
|
+
|
|
213
313
|
- (void)parseOptions {
|
|
214
314
|
NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;
|
|
215
315
|
if (args.count < 2) return;
|
|
@@ -246,9 +346,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
246
346
|
self.window.hasShadow = YES;
|
|
247
347
|
/* 高于普通浮动窗口(歌词、置顶小工具等),确保真正盖住被跟随的 App */
|
|
248
348
|
self.window.level = NSStatusWindowLevel;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
349
|
+
/* 固定吸附:默认不加入所有 Space(否则用户滑动切屏时摸鱼窗会跟着跑到当前屏);
|
|
350
|
+
只有「自由悬浮」模式才允许出现在所有 Space。 */
|
|
351
|
+
self.window.collectionBehavior = (NSWindowCollectionBehaviorFullScreenAuxiliary
|
|
252
352
|
| NSWindowCollectionBehaviorIgnoresCycle);
|
|
253
353
|
self.window.minSize = NSMakeSize(520, 360);
|
|
254
354
|
self.window.title = @"古法编程悬浮层";
|
|
@@ -311,8 +411,17 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
311
411
|
self.dragStrip = strip;
|
|
312
412
|
|
|
313
413
|
self.window.contentView = container;
|
|
414
|
+
if (self.window.frame.size.width < 400 || self.window.frame.size.height < 300) {
|
|
415
|
+
NSRect visible = NSScreen.mainScreen.visibleFrame;
|
|
416
|
+
CGFloat width = MIN(1180, visible.size.width * 0.86);
|
|
417
|
+
CGFloat height = MIN(820, visible.size.height * 0.86);
|
|
418
|
+
[self.window setFrame:NSMakeRect(visible.origin.x + (visible.size.width - width) / 2.0,
|
|
419
|
+
visible.origin.y + (visible.size.height - height) / 2.0,
|
|
420
|
+
width, height) display:YES];
|
|
421
|
+
}
|
|
314
422
|
[self.window makeKeyAndOrderFront:nil];
|
|
315
423
|
[NSApp activateIgnoringOtherApps:YES];
|
|
424
|
+
GufaLog(@"window-frame %@ visible=%d level=%ld activeSpace=%d screen=%@ alpha=%.2f", NSStringFromRect(self.window.frame), self.window.isVisible ? 1 : 0, (long)self.window.level, self.window.isOnActiveSpace ? 1 : 0, self.window.screen == nil ? @"nil" : NSStringFromRect(self.window.screen.frame), self.window.alphaValue);
|
|
316
425
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidEndLiveResizeNotification object:self.window];
|
|
317
426
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidMoveNotification object:self.window];
|
|
318
427
|
}
|
|
@@ -370,6 +479,56 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
370
479
|
[js appendString:@"localStorage.setItem('gufa-code:float','1');location.href='/?gufa-float=1';}catch(e){}"];
|
|
371
480
|
[self.webView evaluateJavaScript:js completionHandler:nil];
|
|
372
481
|
};
|
|
482
|
+
[self clearWebCachesThenLoad];
|
|
483
|
+
|
|
484
|
+
/* 诊断:6 秒后记录页面地址/标题/正文摘要,便于定位空白窗口 */
|
|
485
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
486
|
+
NSString *probe = @"(function(){try{var o=document.querySelector('.gufa-overlay-root');var g=(window.__GUFA_CODE__&&window.__GUFA_CODE__.G)||null;return JSON.stringify({href:location.href,build:g?g.BUILD:null,overlay:!!o,vis:o?getComputedStyle(o).visibility:'',body:(document.body?document.body.innerText:'').slice(0,260),tabs:Array.prototype.map.call(document.querySelectorAll('.gufa-tab'),function(n){return (n.textContent||'').trim();}).slice(0,8)});}catch(e){return 'probe-error:'+e;}})()";
|
|
487
|
+
[self.webView evaluateJavaScript:probe completionHandler:^(id result, NSError *error) {
|
|
488
|
+
GufaLog(@"page-probe %@ err=%@", result ?: @"nil", error.localizedDescription ?: @"none");
|
|
489
|
+
}];
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
/* 内部 QA:payload.selftest 是一段 JS,页面打开后在悬浮窗里跑一遍并写回诊断日志(仅开发用,不影响 UI) */
|
|
493
|
+
NSString *selftest = [self.options[@"selftest"] isKindOfClass:[NSString class]] ? self.options[@"selftest"] : nil;
|
|
494
|
+
if (selftest.length > 0) {
|
|
495
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
496
|
+
[self.webView evaluateJavaScript:selftest completionHandler:^(id result, NSError *error) {
|
|
497
|
+
if (error != nil) GufaLog(@"selftest-script-error %@", error.localizedDescription ?: @"?");
|
|
498
|
+
}];
|
|
499
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
500
|
+
[self.webView evaluateJavaScript:@"JSON.stringify(window.__gufaSelftest||{step:'none'})" completionHandler:^(id result, NSError *error) {
|
|
501
|
+
GufaLog(@"selftest %@", result ?: @"nil");
|
|
502
|
+
}];
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/* 清 Web 缓存(保留 cookie/localStorage 不行——要清 localStorage 才能保证状态注入生效)。
|
|
510
|
+
完成后再真正加载页面。 */
|
|
511
|
+
- (void)clearWebCachesThenLoad {
|
|
512
|
+
if (self.cachesCleared) return;
|
|
513
|
+
self.cachesCleared = YES;
|
|
514
|
+
/* 版本变了才清全部 Web 数据(保证客户端代码最新);
|
|
515
|
+
同一版本重复打开摸鱼只清缓存(或干脆不清),避免每次重新编译整个前端(慢且耗内存) */
|
|
516
|
+
NSString *build = [self.options[@"build"] isKindOfClass:[NSString class]] ? self.options[@"build"] : @"";
|
|
517
|
+
NSString *lastBuild = [[NSUserDefaults standardUserDefaults] stringForKey:@"gufa-float-build"];
|
|
518
|
+
BOOL versionChanged = build.length == 0 || lastBuild == nil || ![lastBuild isEqualToString:build];
|
|
519
|
+
NSSet<NSString *> *types = versionChanged
|
|
520
|
+
? [WKWebsiteDataStore allWebsiteDataTypes]
|
|
521
|
+
: [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil];
|
|
522
|
+
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:types modifiedSince:[NSDate dateWithTimeIntervalSince1970:0] completionHandler:^{
|
|
523
|
+
if (build.length > 0) [[NSUserDefaults standardUserDefaults] setObject:build forKey:@"gufa-float-build"];
|
|
524
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
525
|
+
[self performInitialLoad];
|
|
526
|
+
});
|
|
527
|
+
}];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
- (void)performInitialLoad {
|
|
531
|
+
NSString *authUrl = self.options[@"authUrl"];
|
|
373
532
|
NSString *cookie = [self.options[@"cookie"] isKindOfClass:[NSString class]] ? self.options[@"cookie"] : nil;
|
|
374
533
|
if (cookie.length > 0) {
|
|
375
534
|
NSRange eq = [cookie rangeOfString:@"="];
|
|
@@ -391,26 +550,11 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
391
550
|
components.queryItems = @[[NSURLQueryItem queryItemWithName:@"gufa-float" value:@"1"]];
|
|
392
551
|
[self.webView loadRequest:[NSURLRequest requestWithURL:components.URL]];
|
|
393
552
|
}];
|
|
553
|
+
return;
|
|
394
554
|
}
|
|
395
555
|
}
|
|
396
|
-
} else {
|
|
397
|
-
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:authUrl]]];
|
|
398
|
-
}
|
|
399
|
-
/* 内部 QA:payload.selftest 是一段 JS,页面打开后在悬浮窗里跑一遍并写回诊断日志(仅开发用,不影响 UI) */
|
|
400
|
-
NSString *selftest = [self.options[@"selftest"] isKindOfClass:[NSString class]] ? self.options[@"selftest"] : nil;
|
|
401
|
-
if (selftest.length > 0) {
|
|
402
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
403
|
-
[self.webView evaluateJavaScript:selftest completionHandler:^(id result, NSError *error) {
|
|
404
|
-
if (error != nil) GufaLog(@"selftest-script-error %@", error.localizedDescription ?: @"?");
|
|
405
|
-
}];
|
|
406
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
407
|
-
[self.webView evaluateJavaScript:@"JSON.stringify(window.__gufaSelftest||{step:'none'})" completionHandler:^(id result, NSError *error) {
|
|
408
|
-
GufaLog(@"selftest %@", result ?: @"nil");
|
|
409
|
-
}];
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
556
|
}
|
|
413
|
-
|
|
557
|
+
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:authUrl ?: @""]]];
|
|
414
558
|
}
|
|
415
559
|
|
|
416
560
|
- (void)saveFrame {
|
|
@@ -418,6 +562,87 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
418
562
|
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromRect(self.window.frame) forKey:self.frameKey];
|
|
419
563
|
}
|
|
420
564
|
|
|
565
|
+
static CGWindowID GufaAXWindowNumber(AXUIElementRef window) {
|
|
566
|
+
if (window == NULL) return 0;
|
|
567
|
+
CFTypeRef value = NULL;
|
|
568
|
+
if (AXUIElementCopyAttributeValue(window, CFSTR("AXWindowNumber"), &value) != kAXErrorSuccess || value == NULL) return 0;
|
|
569
|
+
CGWindowID number = 0;
|
|
570
|
+
if (CFGetTypeID(value) == CFNumberGetTypeID()) CFNumberGetValue((CFNumberRef)value, kCFNumberSInt32Type, &number);
|
|
571
|
+
CFRelease(value);
|
|
572
|
+
return number;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/* 用 SkyLight 私有 API 把窗口移动/加入到目标窗口所在的 Space。
|
|
576
|
+
这比 collectionBehavior 的 MoveToActiveSpace 可靠(全屏 Space / 多屏下窗口不动的问题)。 */
|
|
577
|
+
static int GufaMoveWindowToTargetSpace(NSWindow *window, AXUIElementRef targetWindow) {
|
|
578
|
+
if (window == nil || targetWindow == NULL) return -1;
|
|
579
|
+
CGWindowID targetWid = GufaAXWindowNumber(targetWindow);
|
|
580
|
+
CGWindowID ownWid = (CGWindowID)window.windowNumber;
|
|
581
|
+
if (ownWid == 0) {
|
|
582
|
+
GufaLog(@"space-move skip ownWid=0");
|
|
583
|
+
return -2;
|
|
584
|
+
}
|
|
585
|
+
GufaLog(@"space-move start targetWid=%u ownWid=%u", targetWid, ownWid);
|
|
586
|
+
void *handle = dlopen("/System/Library/PrivateFrameworks/SkyLight.framework/SkyLight", RTLD_LAZY);
|
|
587
|
+
if (handle == NULL) {
|
|
588
|
+
GufaLog(@"space-move dlopen-failed %s", dlerror());
|
|
589
|
+
return -3;
|
|
590
|
+
}
|
|
591
|
+
typedef int (*MainConnectionFn)(void);
|
|
592
|
+
typedef uint64_t (*GetActiveSpaceFn)(int);
|
|
593
|
+
typedef int (*GetWindowWorkspaceFn)(int, CGWindowID, uint64_t *);
|
|
594
|
+
typedef int (*AddWindowsToSpacesFn)(int, CFArrayRef, CFArrayRef);
|
|
595
|
+
MainConnectionFn mainConn = (MainConnectionFn)dlsym(handle, "SLSMainConnectionID");
|
|
596
|
+
if (mainConn == NULL) mainConn = (MainConnectionFn)dlsym(handle, "CGSMainConnectionID");
|
|
597
|
+
GetWindowWorkspaceFn getWorkspace = (GetWindowWorkspaceFn)dlsym(handle, "SLSGetWindowWorkspace");
|
|
598
|
+
if (getWorkspace == NULL) getWorkspace = (GetWindowWorkspaceFn)dlsym(handle, "CGSGetWindowWorkspace");
|
|
599
|
+
GetActiveSpaceFn getActiveSpace = (GetActiveSpaceFn)dlsym(handle, "SLSGetActiveSpace");
|
|
600
|
+
if (getActiveSpace == NULL) getActiveSpace = (GetActiveSpaceFn)dlsym(handle, "CGSGetActiveSpace");
|
|
601
|
+
AddWindowsToSpacesFn addWindows = (AddWindowsToSpacesFn)dlsym(handle, "SLSAddWindowsToSpaces");
|
|
602
|
+
if (addWindows == NULL) addWindows = (AddWindowsToSpacesFn)dlsym(handle, "CGSAddWindowsToSpaces");
|
|
603
|
+
if (mainConn == NULL || getWorkspace == NULL || addWindows == NULL) {
|
|
604
|
+
GufaLog(@"space-move symbols missing main=%d get=%d add=%d", mainConn != NULL, getWorkspace != NULL, addWindows != NULL);
|
|
605
|
+
dlclose(handle);
|
|
606
|
+
return -4;
|
|
607
|
+
}
|
|
608
|
+
int cid = mainConn();
|
|
609
|
+
uint64_t targetSpace = 0;
|
|
610
|
+
if (targetWid != 0 && getWorkspace != NULL) {
|
|
611
|
+
int getErr = getWorkspace(cid, targetWid, &targetSpace);
|
|
612
|
+
if (getErr != 0) GufaLog(@"space-move target-workspace failed err=%d", getErr);
|
|
613
|
+
}
|
|
614
|
+
if (targetSpace == 0 && getActiveSpace != NULL) {
|
|
615
|
+
/* 拿不到目标窗口 id(AX 不暴露 AXWindowNumber)时,目标 App 已激活,
|
|
616
|
+
直接把我们的窗口加进当前活动 Space(= 目标 App 的 Space) */
|
|
617
|
+
targetSpace = getActiveSpace(cid);
|
|
618
|
+
GufaLog(@"space-move use-active-space=%llu", (unsigned long long)targetSpace);
|
|
619
|
+
}
|
|
620
|
+
if (targetSpace == 0) {
|
|
621
|
+
GufaLog(@"space-move no-target-space (targetWid=%u activeSpaceApi=%d)", targetWid, getActiveSpace != NULL);
|
|
622
|
+
dlclose(handle);
|
|
623
|
+
return -5;
|
|
624
|
+
}
|
|
625
|
+
CFArrayRef windows = (__bridge CFArrayRef)@[@(ownWid)];
|
|
626
|
+
CFArrayRef spaces = (__bridge CFArrayRef)@[@(targetSpace)];
|
|
627
|
+
int addErr = addWindows(cid, windows, spaces);
|
|
628
|
+
dlclose(handle);
|
|
629
|
+
GufaLog(@"space-move ownWid=%u targetWid=%u space=%llu err=%d", ownWid, targetWid, (unsigned long long)targetSpace, addErr);
|
|
630
|
+
return addErr;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/* 自身窗口在 WindowServer 里是否 onscreen / 在哪块屏幕(Space 占用排查用) */
|
|
634
|
+
static void GufaLogOwnWindowState(NSString *tag) {
|
|
635
|
+
NSArray<NSDictionary *> *windows = (__bridge_transfer NSArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID);
|
|
636
|
+
pid_t selfPid = NSProcessInfo.processInfo.processIdentifier;
|
|
637
|
+
for (NSDictionary *info in windows) {
|
|
638
|
+
NSNumber *owner = info[(__bridge NSString *)kCGWindowOwnerPID];
|
|
639
|
+
if (owner == nil || owner.intValue != selfPid) continue;
|
|
640
|
+
NSNumber *onscreen = info[(__bridge NSString *)kCGWindowIsOnscreen];
|
|
641
|
+
NSDictionary *bounds = info[(__bridge NSString *)kCGWindowBounds];
|
|
642
|
+
GufaLog(@"%@ own-window onscreen=%d bounds=%@ layer=%@", tag, onscreen == nil ? -1 : onscreen.intValue, bounds ?: @{}, info[(__bridge NSString *)kCGWindowLayer] ?: @"?");
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
421
646
|
/* ── 跟随选中的 App 窗口(Accessibility API) ─────────────────────── */
|
|
422
647
|
|
|
423
648
|
- (void)showPermissionGuide {
|
|
@@ -461,6 +686,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
461
686
|
self.followWindowRef = GufaCopyAppWindow(self.followPid);
|
|
462
687
|
if (self.followWindowRef == NULL) return;
|
|
463
688
|
self.following = YES;
|
|
689
|
+
[self applySpaceBehaviorFollowing:YES];
|
|
464
690
|
[self startFollowTimer];
|
|
465
691
|
[self applyFollowFrame];
|
|
466
692
|
self.statusItem.button.title = @"古法·摸鱼";
|
|
@@ -469,6 +695,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
469
695
|
|
|
470
696
|
- (void)stopFollow:(id)sender {
|
|
471
697
|
[self stopFollowTimer];
|
|
698
|
+
[self applySpaceBehaviorFollowing:NO];
|
|
472
699
|
self.statusItem.button.title = self.clickThrough ? @"古法·穿透" : @"古法";
|
|
473
700
|
}
|
|
474
701
|
|
|
@@ -564,9 +791,14 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
564
791
|
}
|
|
565
792
|
|
|
566
793
|
- (void)restoreMainWindow {
|
|
794
|
+
GufaSetMainAppHidden(NO);
|
|
567
795
|
GufaActivateBundle(@"com.deepseek.dsh");
|
|
568
796
|
}
|
|
569
797
|
|
|
798
|
+
- (void)applicationWillTerminate:(NSNotification *)notification {
|
|
799
|
+
GufaSetMainAppHidden(NO);
|
|
800
|
+
}
|
|
801
|
+
|
|
570
802
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return YES; }
|
|
571
803
|
|
|
572
804
|
@end
|
|
@@ -576,6 +808,7 @@ static void GufaInstallTermHandler(void) {
|
|
|
576
808
|
signal(SIGTERM, SIG_IGN);
|
|
577
809
|
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
|
|
578
810
|
dispatch_source_set_event_handler(source, ^{
|
|
811
|
+
GufaSetMainAppHidden(NO);
|
|
579
812
|
GufaActivateBundle(@"com.deepseek.dsh");
|
|
580
813
|
[NSApp terminate:nil];
|
|
581
814
|
});
|
|
@@ -772,6 +1005,17 @@ static int GufaListWindowsMode(void) {
|
|
|
772
1005
|
return 0;
|
|
773
1006
|
}
|
|
774
1007
|
|
|
1008
|
+
/** 隐藏/恢复 DSH 主窗口(AXHidden,等价 ⌘H)。 */
|
|
1009
|
+
static void GufaSetMainAppHidden(BOOL hidden) {
|
|
1010
|
+
NSRunningApplication *app = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.deepseek.dsh"].firstObject;
|
|
1011
|
+
if (app == nil) return;
|
|
1012
|
+
AXUIElementRef ax = AXUIElementCreateApplication(app.processIdentifier);
|
|
1013
|
+
if (ax == NULL) return;
|
|
1014
|
+
AXError error = AXUIElementSetAttributeValue(ax, (CFStringRef)CFSTR("AXHidden"), hidden ? kCFBooleanTrue : kCFBooleanFalse);
|
|
1015
|
+
GufaLog(@"main-window-hidden set=%d err=%d", hidden ? 1 : 0, (int)error);
|
|
1016
|
+
CFRelease(ax);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
775
1019
|
/** 激活目标 App(LaunchServices open -b,能切到它的 Space)。 */
|
|
776
1020
|
static void GufaActivateBundle(NSString *bundleId) {
|
|
777
1021
|
if (bundleId.length == 0) return;
|
|
@@ -785,6 +1029,16 @@ static void GufaActivateBundle(NSString *bundleId) {
|
|
|
785
1029
|
}
|
|
786
1030
|
}
|
|
787
1031
|
|
|
1032
|
+
static BOOL GufaAXWindowFullScreen(AXUIElementRef window) {
|
|
1033
|
+
if (window == NULL) return NO;
|
|
1034
|
+
CFTypeRef value = NULL;
|
|
1035
|
+
if (AXUIElementCopyAttributeValue(window, CFSTR("AXFullScreen"), &value) != kAXErrorSuccess || value == NULL) return NO;
|
|
1036
|
+
BOOL full = NO;
|
|
1037
|
+
if (CFGetTypeID(value) == CFBooleanGetTypeID()) full = CFBooleanGetValue((CFBooleanRef)value);
|
|
1038
|
+
CFRelease(value);
|
|
1039
|
+
return full;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
788
1042
|
/** 按 pid + title 查找对应 AX window(follow 用)。 */
|
|
789
1043
|
static AXUIElementRef GufaCopyAXWindow(pid_t pid, NSString *title) {
|
|
790
1044
|
AXUIElementRef appElement = AXUIElementCreateApplication(pid);
|
|
@@ -831,9 +1085,9 @@ int main(int argc, const char *argv[]) {
|
|
|
831
1085
|
}
|
|
832
1086
|
}
|
|
833
1087
|
@autoreleasepool {
|
|
834
|
-
GufaInstallTermHandler();
|
|
835
1088
|
[NSApplication sharedApplication];
|
|
836
1089
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
|
1090
|
+
GufaInstallTermHandler();
|
|
837
1091
|
GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
|
|
838
1092
|
NSApp.delegate = delegate;
|
|
839
1093
|
[NSApp run];
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
|
|
8
8
|
<key>CFBundleExecutable</key><string>gufa-float</string>
|
|
9
9
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
10
|
-
<key>CFBundleShortVersionString</key><string>1.3.
|
|
11
|
-
<key>CFBundleVersion</key><string>1.3.
|
|
10
|
+
<key>CFBundleShortVersionString</key><string>1.3.48</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.48</string>
|
|
12
12
|
<key>LSUIElement</key><true/>
|
|
13
13
|
<key>NSHighResolutionCapable</key><true/>
|
|
14
14
|
<key>NSPrincipalClass</key><string>NSApplication</string>
|
|
Binary file
|
package/docs/KNOWN-PITFALLS.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
> 这份清单记录已经犯过、并且容易再犯的错误。加新功能前先扫一遍。
|
|
4
4
|
|
|
5
|
+
## 0. 三种模式不要串味(见 docs/MODES.md)
|
|
6
|
+
|
|
7
|
+
- 经典 / 古法编程 / 摸鱼 三态,判断只认 `html[data-gufa-ide]` 与 `html[data-gufa-float]`;
|
|
8
|
+
- **不要用 localStorage / 全局状态判断摸鱼模式**(曾经因此让主窗口的「入口工作区」逻辑失效);
|
|
9
|
+
- 摸鱼相关逻辑一律包在 `G.isFloatMode()` 里;古法编程的功能锁见 `docs/MODES.md`。
|
|
10
|
+
|
|
5
11
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
6
12
|
|
|
7
13
|
**现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
|
|
@@ -44,6 +50,15 @@
|
|
|
44
50
|
2. `60-dock.js` 的 `applyPalette` 把 `--gufa-solid-*` 同步写入 portal host;
|
|
45
51
|
3. 新增/修改弹窗时,样式尽量只依赖这套变量,不要假设能继承 `.gufa-root` 的其它属性。
|
|
46
52
|
|
|
53
|
+
## 1.2 悬浮层退出:不要依赖 SIGTERM(实测不可靠)
|
|
54
|
+
|
|
55
|
+
- 现象:`kill -TERM` 后 helper 不退出、或退出后 DSH 主窗口仍是隐藏状态(`visible=false`)。
|
|
56
|
+
- 原因:AppKit 进程里 `DISPATCH_SOURCE_TYPE_SIGNAL` 的 SIGTERM 源实测不触发(即使 `signal(SIG_IGN)` + 主队列正确配置)。
|
|
57
|
+
- 定案:Host 的 `float.stop` 用**控制文件**退出——`float.start` 时生成唯一 `controlPath` 传给 helper,
|
|
58
|
+
helper 每 0.3s 轮询;Host 写文件 → helper 恢复主窗口(AXHidden=false + 激活 DSH)后自行退出。
|
|
59
|
+
兜底:若 helper 被强杀,Host 用 `osascript`(System Events)把 DSH 设为 visible,并 `open -b com.deepseek.dsh`。
|
|
60
|
+
- 主窗口「⌘H 效果」= helper 启动 0.45s 后对 DSH 应用 `AXHidden=true`;退出时改回 false。
|
|
61
|
+
|
|
47
62
|
## 2. macOS 屏幕录制权限 + 悬浮层 helper
|
|
48
63
|
|
|
49
64
|
- helper 每次重新编译(代码签名变化)后,TCC 里旧的「屏幕录制」授权可能失效;
|
|
@@ -59,3 +74,49 @@
|
|
|
59
74
|
- 原因:页面源是 `dsh-app://`,Monaco 默认 blob worker 里 `importScripts('/gufa-code/...')` 是非法 URL;
|
|
60
75
|
- 修法:worker 用同源 `vendor/monaco/vs/worker-bootstrap.js` 作为入口,里面只做
|
|
61
76
|
`MonacoEnvironment.baseUrl` + `importScripts(workerMain.js)`;**不要**先加载 AMD `loader.js`(模块系统冲突)。
|
|
77
|
+
|
|
78
|
+
## 4. 性能:摸鱼窗口启动/资源占用(实测与原则)
|
|
79
|
+
|
|
80
|
+
- **不要每次启动摸鱼都清空全部 Web 数据**:`WKWebsiteDataStore allWebsiteDataTypes` 会让整个 DSH 前端重新下载/编译,
|
|
81
|
+
实测启动到客户端 boot 由 **~14s 降到 ~1.1s**。正确做法:把插件版本随 payload 传入(`build`),
|
|
82
|
+
版本变化时清全部数据(保证客户端代码最新),同一版本只清 memory cache。
|
|
83
|
+
- 摸鱼窗口是一个完整的第二个 DSH Web 客户端:打开时 WebKit 内容进程 **~600–650MB**、加载后空转 CPU ≈0%(已优化);
|
|
84
|
+
关闭后进程与内存全部释放(实测 3 次开关无泄漏)。不要同时保留多个摸鱼窗口。
|
|
85
|
+
- 摸鱼窗口里不挂载背景粒子(`G.BackdropParticles` 直接返回 null),并关闭皮肤插件动画
|
|
86
|
+
(`data-liang-skin=off` + 移除 `.liang-skin-*` 节点),否则看不见也会跑 rAF。
|
|
87
|
+
- 主窗口背景粒子:30fps→24fps、dpr 上限 1.5→1.25、页面隐藏/窗口失焦时暂停。
|
|
88
|
+
- 快捷键集成不要留常驻重试环:累加上限 40 次 + 只在签名变化时写诊断日志(曾出现 2Hz 常驻循环)。
|
|
89
|
+
- 退出摸鱼状态轮询 5s 一次且页面不可见时跳过(原来 3s 且无条件请求 host)。
|
|
90
|
+
|
|
91
|
+
## 6. 摸鱼吸附全屏 App(QQ音乐等占满整屏的窗口)
|
|
92
|
+
|
|
93
|
+
- 现象:目标 App 窗口占满一整个屏(或原生全屏 Space)时,去掉 canJoinAllSpaces 后悬浮窗"没浮动过去"。
|
|
94
|
+
- 原因:悬浮窗创建在用户当前 Space,仅靠 setFrame 移动坐标不会把窗口带进目标 App 的 Space/全屏 Space。
|
|
95
|
+
- 定案:找到目标 AX 窗口并贴好 frame 后调用 `attachToFollowedSpace`:
|
|
96
|
+
1) collectionBehavior 临时加 `MoveToActiveSpace` 并 `orderFrontRegardless`(此时目标 App 已激活,其 Space 即活动 Space);
|
|
97
|
+
2) 0.9s 后恢复 `FullScreenAuxiliary | IgnoresCycle`,窗口稳定留在该 Space,后续用户滑屏不会跟随。
|
|
98
|
+
- 验证:QQ音乐占满主屏时,悬浮窗覆盖整屏且 `own-window onscreen=1`;退出后主窗口恢复。
|
|
99
|
+
- 补充(真机点击复现后的最终定案):
|
|
100
|
+
1. **必须先激活目标 App、等它切完 Space(~0.9s)再创建悬浮窗**,否则窗口创建在 DSH 原来的 Space 里,
|
|
101
|
+
后续 `MoveToActiveSpace` 也不生效(实测 onscreen=-1,用户看到"没浮动过去")。
|
|
102
|
+
2. QQ音乐的 AX window 不暴露 `AXWindowNumber`(返回 0),拿不到目标窗口 CGWindowID;
|
|
103
|
+
此时用 SkyLight 私有 API 兜底:`SLSGetActiveSpace`(目标 App 已激活 → 活动 Space 即其 Space)+
|
|
104
|
+
`SLSAddWindowsToSpaces` 把自己的窗口加进去(实测 `use-active-space=8234 err=0`)。
|
|
105
|
+
3. 私有 API 全部 dlsym,符号缺失时只记日志不影响主流程。
|
|
106
|
+
|
|
107
|
+
## 5.1 摸鱼会话框比编辑器黑:官方会话根节点自己又画了一层底
|
|
108
|
+
|
|
109
|
+
- 现象:摸鱼里编辑器/终端都统一了,右侧会话框看起来明显更黑更实。
|
|
110
|
+
- 实测(同屏同底层对比法):编辑器有效 alpha=0.570,会话框=0.878 → 会话框多叠了一层 ~0.72 的暗底。
|
|
111
|
+
- 根因:官方会话根节点(被 60-dock 停靠的 `div.kiGsTW_root`)带 `[data-gufa-dock]` 且自带 `background`(旧规则
|
|
112
|
+
`html[data-gufa-float] [data-gufa-dock]{background:rgba(13,15,19,var(--gufa-float-alpha))!important}` 在样式表**后面**,
|
|
113
|
+
覆盖了前面的 transparent 规则)。
|
|
114
|
+
- 定案:该规则改为 `background:transparent!important` + `--dsw-alias-bg-*` 全 transparent;
|
|
115
|
+
摸鱼整窗只允许 `.gufa-overlay-root` 一层底色。验证:`float-painters` 只剩 overlay-root 一个绘制者,实测会话框 alpha=0.570。
|
|
116
|
+
|
|
117
|
+
## 5. 摸鱼窗口的 Space 固定(不要用 canJoinAllSpaces)
|
|
118
|
+
|
|
119
|
+
- 现象:摸鱼窗吸附第二屏的 App,用户在主屏滑动切 Space 时,摸鱼窗也跟着出现在当前屏。
|
|
120
|
+
- 原因:`NSWindowCollectionBehaviorCanJoinAllSpaces` 会让窗口出现在所有 Space。
|
|
121
|
+
- 定案:吸附模式 collectionBehavior = `FullScreenAuxiliary | IgnoresCycle`(raw=320);
|
|
122
|
+
自由悬浮模式才追加 `CanJoinAllSpaces`(raw=321)。停止跟随/自由悬浮时恢复跨 Space。
|
package/docs/MODES.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# 三种模式的契约(改古法编程前必读)
|
|
2
|
+
|
|
3
|
+
古法编程只允许存在三种状态,判断**只认 DOM 标记**,不要用 localStorage / 内存状态对象:
|
|
4
|
+
|
|
5
|
+
| 模式 | 标记 | 说明 |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| 经典模式 | 无标记 | DSH 原生界面,古法插件只保留工作区菜单入口 |
|
|
8
|
+
| 古法编程 | `html[data-gufa-ide]` | IDE 覆盖层;工作区、会话、编辑器、Git、终端全部按下面「功能锁」工作 |
|
|
9
|
+
| 摸鱼模式 | `html[data-gufa-ide][data-gufa-float]` | 独立悬浮窗实例;由 helper 注入,**只影响悬浮窗,绝不反向影响主窗口** |
|
|
10
|
+
|
|
11
|
+
判断函数:`G.isFloatMode()`(唯一允许的摸鱼判断方式)。
|
|
12
|
+
|
|
13
|
+
## 功能锁(古法编程模式必须始终成立,改动后逐项自查)
|
|
14
|
+
|
|
15
|
+
1. 从哪个工作区的「…」菜单点「古法编程」,IDE 就打开哪个工作区(入口工作区优先,不先恢复上次项目)。
|
|
16
|
+
2. 若经典模式当前会话属于该工作区:不切换会话,只对齐项目根。
|
|
17
|
+
3. 若不属于:切到该工作区最近的会话,再打开项目根。
|
|
18
|
+
4. 进入 IDE 后:项目文件树、已打开标签、Git 状态、终端、右侧官方会话都可用。
|
|
19
|
+
5. 退出 IDE(返回经典模式)后:经典界面恢复原样,不残留 `data-gufa-*` 标记。
|
|
20
|
+
6. 摸鱼逻辑(状态注入、悬浮层、吸附、`G.floatState`、`G.isFloatMode()` 分支)**只能**在 `data-gufa-float` 下生效。
|
|
21
|
+
|
|
22
|
+
## 摸鱼模式交互(v1.3.11 起)
|
|
23
|
+
|
|
24
|
+
- IDE 标题栏「摸鱼」按钮(带框两字)→ 选择要吸附的 App → 悬浮窗出现并吸附该窗口,**DSH 主窗口被隐藏(⌘H 效果)**;
|
|
25
|
+
- 悬浮窗标题栏:透明度滑块(20%–100%,持久化)、**退出摸鱼**按钮(占原「返回经典模式」位置,摸鱼里不再显示返回经典模式);
|
|
26
|
+
- 摸鱼里不显示皮肤(梁圣)背景;
|
|
27
|
+
- **透明度一致性**:摸鱼窗口只保留「覆盖层根节点」一层半透明底(`rgba(13,15,19,var(--gufa-float-alpha))`),
|
|
28
|
+
编辑器、资源管理器、会话框、终端面板内部全部透明 → 所有区域看到的透明度完全一致,随滑块整体变化。
|
|
29
|
+
注意官方停靠会话的 `.gufa-dock-toolbar` / `.gufa-dock-host` 也自带底色,摸鱼里必须一并设为透明,
|
|
30
|
+
否则会话框会叠两层(看起来发灰/更实)。
|
|
31
|
+
- **固定吸附**:吸附模式下悬浮窗只留在「被跟随 App 所在的 Space/屏幕」,用户切换 Space/滑屏时不会跟着跑到当前屏;
|
|
32
|
+
只有「自由悬浮(不吸附)」模式才允许出现在所有 Space。
|
|
33
|
+
- 退出摸鱼:悬浮窗把「项目 / 打开的标签页 / UI 布局 / 当前会话」写回 Host,然后优雅退出并恢复显示主窗口;
|
|
34
|
+
主窗口重新获得焦点时自动取回并应用这些状态(项目 → 标签页 → 会话)。
|
|
35
|
+
|
|
36
|
+
## 摸鱼模式现行限制
|
|
37
|
+
|
|
38
|
+
- 只在独立悬浮窗实例里生效;主窗口永远走古法编程模式;
|
|
39
|
+
- **状态快照语义(定案)**:
|
|
40
|
+
- 点「摸鱼」= 对主窗口当前状态拍快照(工作区项目、打开的标签页、当前文件、视图/终端等面板状态、当前会话),摸鱼窗口按该快照原样展示;
|
|
41
|
+
- 点「退出摸鱼」= 对摸鱼窗口当前状态拍快照(同上),写回 Host,主窗口恢复显示时**按该快照原样恢复**(覆盖主窗口被隐藏前的状态);
|
|
42
|
+
- 两侧快照互不串扰:恢复时必须用「重渲染后的最新 openFile/applyProject」,不能用 await 之前的旧闭包(旧闭包里 project 可能还是 null,会导致文件打不开)。
|