dsh-gufa-code 1.3.97 → 1.3.101
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 +1 -1
- package/client.js +52 -4
- package/desktop/float/GufaFloat.m +47 -3
- 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 +3 -0
- package/host/app-window.js +2 -0
- package/package.json +1 -1
- package/src/client/90-app.js +13 -3
- package/src/client/99-main.js +38 -0
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ dsh plugin add dsh-gufa-code
|
|
|
44
44
|
- **Copilot 风格 Tab 行内补全**:光标停/打字后,基于 Harness 自己的 DeepSeek 模型(默认 `deepseek-flash`,不需要额外 Copilot 订阅)流式生成灰色 ghost text,Tab 接受、Esc 忽略;支持 JS/TS/Python/Java/Go/Rust/C++/C#/JSON/YAML/Shell 等常见语言;
|
|
45
45
|
- 保存走磁盘版本冲突检测 + 原子写;未保存标记;
|
|
46
46
|
- **⌘/Ctrl + 点击跳转定义 / 方法实现**:Python 走 **Pyright 语言服务(LSP)**,JS/TS 走 Monaco 内置 TypeScript 语言服务(点击前会按需把当前文件的 import 依赖加载进 Monaco,跨文件变量/函数由 TS 语言服务解析);其他语言暂用项目级定义搜索兜底;优先走 Monaco 语言服务;目标文件没在 Monaco 里打开、或语言没有内置语言服务时,自动用项目级定义搜索兜底(函数 / 类 / 方法 / const / type 等声明)。兜底会解析 import/require 直接定位来源文件,并跳过压缩产物/大文件;同一个文件里的声明、import 命中的定义、目录距离近的定义直接跳,只有多个真正同名的声明才弹「跳转到定义」列表,点同名属性/变量时不会拿远端无关的 const 来凑数;按住 ⌘/Ctrl 悬停时,可跳转的符号会显示下划线 + 手型光标;
|
|
47
|
-
- **⌘⇧N 新开实例窗口**:用古法编程自带原生 helper 打开一个普通 Harness 窗口(同一 Web GUI
|
|
47
|
+
- **⌘⇧N 新开实例窗口**:用古法编程自带原生 helper 打开一个普通 Harness 窗口(同一 Web GUI、共享登录态),新窗口**直接进入古法编程的空工作区**(提示新建或打开工作区,不继承当前项目/标签页),方便并行操作别的工作区;当前窗口全屏时新窗口也直接全屏;macOS 已支持,Windows/Linux 待 helper 实现 full 模式;
|
|
48
48
|
- **全局搜索 / 替换**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则、包含/排除文件(glob);结果按文件分组、高亮匹配,点击跳转行列;替换栏支持保留大小写(AB)、全部替换(需确认)、按文件替换(悬停文件头铅笔)、按单行匹配替换与忽略(悬停结果行);替换前会自动保存未落盘的编辑器内容;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;摸鱼悬浮窗里同样可用;
|
|
49
49
|
- 资源管理器文件/文件夹可直接**拖进右侧输入框**变成 @引用;
|
|
50
50
|
- 资源管理器右键:新建 / 重命名 / 删除 / 复制 / 粘贴 / 打开所在文件夹 / 两文件对比;
|
package/client.js
CHANGED
|
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
|
|
|
16
16
|
const G = {}
|
|
17
17
|
G.NS = GUFA_NS
|
|
18
18
|
/** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
|
|
19
|
-
G.BUILD = '1.3.
|
|
19
|
+
G.BUILD = '1.3.101'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -12195,6 +12195,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12195
12195
|
}
|
|
12196
12196
|
}
|
|
12197
12197
|
if (G.isFloatMode()) return
|
|
12198
|
+
/* 实例窗口不继承当前项目,等用户自己新建/打开工作区 */
|
|
12199
|
+
if (G.instanceBoot === true) return
|
|
12198
12200
|
if (typeof sessionCwd === 'string' && sessionCwd !== '') {
|
|
12199
12201
|
try {
|
|
12200
12202
|
const value = await G.api('project.open', { path: sessionCwd })
|
|
@@ -13949,9 +13951,17 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13949
13951
|
if (next !== undefined) setActivePath(next.path)
|
|
13950
13952
|
},
|
|
13951
13953
|
newWindow: () => {
|
|
13952
|
-
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI
|
|
13953
|
-
|
|
13954
|
-
|
|
13954
|
+
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI,
|
|
13955
|
+
并把当前项目/标签页状态与全屏状态带过去;失败才回退浏览器窗口。 */
|
|
13956
|
+
let fullscreen = false
|
|
13957
|
+
try {
|
|
13958
|
+
const coversScreen = window.innerWidth >= (screen.width - 2) && window.innerHeight >= (screen.height - 2)
|
|
13959
|
+
const coversWorkArea = window.innerWidth >= (screen.availWidth - 2) && window.innerHeight >= (screen.availHeight - 2)
|
|
13960
|
+
fullscreen = coversScreen || coversWorkArea
|
|
13961
|
+
} catch {
|
|
13962
|
+
fullscreen = false
|
|
13963
|
+
}
|
|
13964
|
+
void G.api('app.newWindow', { fullscreen }).catch((error) => {
|
|
13955
13965
|
let opened = null
|
|
13956
13966
|
try { opened = window.open(location.href, '_blank') } catch { opened = null }
|
|
13957
13967
|
if (opened !== null && opened !== undefined) {
|
|
@@ -15577,6 +15587,44 @@ const GUFA_PLUGIN = {
|
|
|
15577
15587
|
console.error('[gufa-code] 悬浮模式初始化失败', error)
|
|
15578
15588
|
}
|
|
15579
15589
|
|
|
15590
|
+
/* ── 实例窗口(⌘⇧N 打开的 helper full 窗口):直接进入古法编程 ──
|
|
15591
|
+
helper 已注入项目和编辑器状态;这里在客户端 boot 后反复调 G.enterGufa,
|
|
15592
|
+
直到 IDE 覆盖层真正挂载,避免和 slots 注册时序赛跑。 */
|
|
15593
|
+
try {
|
|
15594
|
+
const instanceMode = /[?&]gufa-instance=1/.test(String(location.search || ''))
|
|
15595
|
+
if (instanceMode && document.documentElement.hasAttribute('data-gufa-float') !== true) {
|
|
15596
|
+
G.instanceBoot = true
|
|
15597
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
15598
|
+
let attempts = 0
|
|
15599
|
+
let timer = 0
|
|
15600
|
+
const tryEnter = () => {
|
|
15601
|
+
try {
|
|
15602
|
+
if (document.querySelector('.gufa-overlay-root') !== null) {
|
|
15603
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15604
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
15605
|
+
return
|
|
15606
|
+
}
|
|
15607
|
+
if (typeof G.enterGufa === 'function') G.enterGufa()
|
|
15608
|
+
} catch {
|
|
15609
|
+
/* ignore */
|
|
15610
|
+
}
|
|
15611
|
+
attempts += 1
|
|
15612
|
+
if (attempts > 80 && timer !== 0) {
|
|
15613
|
+
window.clearInterval(timer)
|
|
15614
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15615
|
+
}
|
|
15616
|
+
}
|
|
15617
|
+
tryEnter()
|
|
15618
|
+
timer = window.setInterval(tryEnter, 200)
|
|
15619
|
+
ctx.effect(() => () => {
|
|
15620
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
15621
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15622
|
+
}, 'gufa-code: instance boot')
|
|
15623
|
+
}
|
|
15624
|
+
} catch (error) {
|
|
15625
|
+
console.error('[gufa-code] 实例窗口自动进入 IDE 失败', error)
|
|
15626
|
+
}
|
|
15627
|
+
|
|
15580
15628
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
15581
15629
|
try {
|
|
15582
15630
|
if (typeof G.mode?.get === 'function' && G.mode.get() === true) document.documentElement.setAttribute('data-gufa-ide', '')
|
|
@@ -38,6 +38,23 @@ static void GufaLog(NSString *format, ...) {
|
|
|
38
38
|
[handle closeFile];
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/* 把任意 JSON 值转成可安全嵌入 JS 的字面量(用于 document-start 注入 localStorage)。 */
|
|
43
|
+
static NSString *GufaJSONLiteralString(id object) {
|
|
44
|
+
if (object == nil || object == [NSNull null]) return @"null";
|
|
45
|
+
/* 顶层字符串/数字是 JSON fragment,必须显式允许,否则会退化成数组字面量。 */
|
|
46
|
+
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingFragmentsAllowed error:NULL];
|
|
47
|
+
if (data == nil) {
|
|
48
|
+
NSData *quoted = [NSJSONSerialization dataWithJSONObject:@[object] options:0 error:NULL];
|
|
49
|
+
data = quoted;
|
|
50
|
+
if (data != nil) {
|
|
51
|
+
NSString *arrayLiteral = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
52
|
+
if (arrayLiteral.length >= 2) return [arrayLiteral substringWithRange:NSMakeRange(1, arrayLiteral.length - 2)];
|
|
53
|
+
}
|
|
54
|
+
return @"null";
|
|
55
|
+
}
|
|
56
|
+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
57
|
+
}
|
|
41
58
|
static void GufaEmitJSON(NSDictionary *out);
|
|
42
59
|
|
|
43
60
|
#ifndef GUFA_FLOAT_VERSION
|
|
@@ -120,6 +137,16 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
120
137
|
@property (nonatomic, copy) void (^pendingLoad)(void);
|
|
121
138
|
@end
|
|
122
139
|
|
|
140
|
+
/* 实例窗口要带 ?gufa-instance=1,客户端 boot 据此自动进入古法编程。 */
|
|
141
|
+
static NSURL *GufaInstanceURL(NSString *appUrl) {
|
|
142
|
+
NSURLComponents *components = [NSURLComponents componentsWithString:appUrl ?: @""];
|
|
143
|
+
if (components == nil) return [NSURL URLWithString:appUrl ?: @""];
|
|
144
|
+
NSMutableArray<NSURLQueryItem *> *items = components.queryItems != nil ? [components.queryItems mutableCopy] : [NSMutableArray array];
|
|
145
|
+
[items addObject:[NSURLQueryItem queryItemWithName:@"gufa-instance" value:@"1"]];
|
|
146
|
+
components.queryItems = items;
|
|
147
|
+
return components.URL;
|
|
148
|
+
}
|
|
149
|
+
|
|
123
150
|
@interface GufaAppDelegate : NSObject <NSApplicationDelegate>
|
|
124
151
|
@property (nonatomic, strong) NSWindow *window;
|
|
125
152
|
@property (nonatomic, strong) WKWebView *webView;
|
|
@@ -413,7 +440,17 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
413
440
|
}
|
|
414
441
|
}
|
|
415
442
|
}
|
|
416
|
-
if (
|
|
443
|
+
if (self.fullMode) {
|
|
444
|
+
/* 实例窗口:不继承主窗口项目/标签页,保持干净的新工作区;
|
|
445
|
+
WKWebView data store 共享,先清掉上次摸鱼/实例残留的状态。 */
|
|
446
|
+
NSMutableString *js = [NSMutableString stringWithString:@"try{"];
|
|
447
|
+
for (NSString *key in @[@"gufa-code:float", @"gufa-code:float-state", @"gufa-code:project", @"gufa-code:ui:v1", @"gufa-code:tabs:v1", @"gufa-code:mode:v1"]) {
|
|
448
|
+
[js appendFormat:@"localStorage.removeItem('%@');", key];
|
|
449
|
+
}
|
|
450
|
+
[js appendString:@"}catch(e){}"];
|
|
451
|
+
WKUserScript *stateScript = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
|
|
452
|
+
[config.userContentController addUserScript:stateScript];
|
|
453
|
+
} else {
|
|
417
454
|
[bootstrap appendString:@"}catch(e){}"];
|
|
418
455
|
WKUserScript *floatMarker = [[WKUserScript alloc] initWithSource:bootstrap
|
|
419
456
|
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
|
|
@@ -448,6 +485,13 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
448
485
|
}
|
|
449
486
|
[self.window makeKeyAndOrderFront:nil];
|
|
450
487
|
[NSApp activateIgnoringOtherApps:YES];
|
|
488
|
+
if (self.fullMode && [self.options[@"fullscreen"] boolValue]) {
|
|
489
|
+
__weak typeof(self) weakSelf = self;
|
|
490
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
491
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
492
|
+
if (strongSelf != nil && strongSelf.window != nil && (strongSelf.window.styleMask & NSWindowStyleMaskFullScreen) == 0) [strongSelf.window toggleFullScreen:nil];
|
|
493
|
+
});
|
|
494
|
+
}
|
|
451
495
|
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);
|
|
452
496
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidEndLiveResizeNotification object:self.window];
|
|
453
497
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidMoveNotification object:self.window];
|
|
@@ -487,7 +531,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
487
531
|
__strong typeof(weakSelf) self = weakSelf;
|
|
488
532
|
if (self == nil) return;
|
|
489
533
|
if (self.fullMode) {
|
|
490
|
-
[self.webView loadRequest:[NSURLRequest requestWithURL:
|
|
534
|
+
[self.webView loadRequest:[NSURLRequest requestWithURL:GufaInstanceURL(appUrl)]];
|
|
491
535
|
return;
|
|
492
536
|
}
|
|
493
537
|
/* 鉴权 cookie 已在 token URL 重定向时写入;这里用 JS 写 localStorage(避开 URL 长度/转义问题),
|
|
@@ -578,7 +622,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
578
622
|
WKHTTPCookieStore *store = [WKWebsiteDataStore defaultDataStore].httpCookieStore;
|
|
579
623
|
[store setCookie:httpCookie completionHandler:^{
|
|
580
624
|
if (self.fullMode) {
|
|
581
|
-
[self.webView loadRequest:[NSURLRequest requestWithURL:
|
|
625
|
+
[self.webView loadRequest:[NSURLRequest requestWithURL:GufaInstanceURL(self.options[@"appUrl"])]];
|
|
582
626
|
return;
|
|
583
627
|
}
|
|
584
628
|
NSURLComponents *components = [NSURLComponents componentsWithString:self.options[@"appUrl"] ?: @""];
|
|
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.101</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.101</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
|
@@ -59,6 +59,9 @@
|
|
|
59
59
|
- 实现:复用插件自带的原生 helper(`desktop/float/GufaFloat.m`),payload 传 `{full:true, authUrl, appUrl}` —— helper 建普通标题栏窗口、Regular 激活策略、跳过摸鱼 localStorage/隐藏主窗/吸附,加载同一个 DSH Web GUI;鉴权复用它已有的 `connection.authenticatedUrl()` token 流程。
|
|
60
60
|
- 客户端 ⌘⇧N 必须先调 Host `app.newWindow`,失败才回退 `window.open`(Electron 的 setWindowOpenHandler 会 deny 并用外部浏览器打开 http(s),不是应用内窗口)。
|
|
61
61
|
- 新窗口与 Electron 主窗口共享的是 **同一个 Host/服务端**,但 UI 进程独立(WKWebView,不走 Electron preload);所以别让新窗口依赖 `window.dshDesktop` 之类的 Electron preload API。
|
|
62
|
+
- **实例窗口不继承主窗口项目**(用户明确要求新窗口用来操作别的工作区):helper full 模式只清空 localStorage 里的 `gufa-code:float/float-state/project/ui/tabs/mode`,URL 带 `?gufa-instance=1`;客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root` 挂载,并通过 `G.instanceBoot` 跳过 App 的 `sessionCwd` 自动打开项目分支,最终停在「尚打开项目 / 打开项目 / 新建项目」空状态。
|
|
63
|
+
- helper 的 WKWebView data store 与摸鱼悬浮层共享;full 模式必须清残留标记,否则新窗口会误进摸鱼 UI 或恢复上次项目。
|
|
64
|
+
- **全屏继承**:客户端用 `innerWidth/innerHeight` 对比 `screen.width/height` 和 `screen.availWidth/availHeight` 判断当前是否全屏,payload 传 `fullscreen:true`,helper 在窗口显示后 `toggleFullScreen`;不要依赖 Electron preload 或 AX 查询(Host 在 Node 模式进程里拿不到 Electron)。
|
|
62
65
|
|
|
63
66
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
64
67
|
|
package/host/app-window.js
CHANGED
|
@@ -47,8 +47,10 @@ export async function newWindow(body, env) {
|
|
|
47
47
|
}
|
|
48
48
|
const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
|
|
49
49
|
const authUrl = connection.authenticatedUrl(`${base}/`)
|
|
50
|
+
const fullscreen = body !== null && typeof body === 'object' && body.fullscreen === true
|
|
50
51
|
const payload = JSON.stringify({
|
|
51
52
|
full: true,
|
|
53
|
+
fullscreen,
|
|
52
54
|
authUrl,
|
|
53
55
|
appUrl: `${base}/`,
|
|
54
56
|
title: 'DeepSeek Harness',
|
package/package.json
CHANGED
package/src/client/90-app.js
CHANGED
|
@@ -354,6 +354,8 @@ G.GufaApp = function GufaApp(props) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
if (G.isFloatMode()) return
|
|
357
|
+
/* 实例窗口不继承当前项目,等用户自己新建/打开工作区 */
|
|
358
|
+
if (G.instanceBoot === true) return
|
|
357
359
|
if (typeof sessionCwd === 'string' && sessionCwd !== '') {
|
|
358
360
|
try {
|
|
359
361
|
const value = await G.api('project.open', { path: sessionCwd })
|
|
@@ -2108,9 +2110,17 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2108
2110
|
if (next !== undefined) setActivePath(next.path)
|
|
2109
2111
|
},
|
|
2110
2112
|
newWindow: () => {
|
|
2111
|
-
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI
|
|
2112
|
-
|
|
2113
|
-
|
|
2113
|
+
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI,
|
|
2114
|
+
并把当前项目/标签页状态与全屏状态带过去;失败才回退浏览器窗口。 */
|
|
2115
|
+
let fullscreen = false
|
|
2116
|
+
try {
|
|
2117
|
+
const coversScreen = window.innerWidth >= (screen.width - 2) && window.innerHeight >= (screen.height - 2)
|
|
2118
|
+
const coversWorkArea = window.innerWidth >= (screen.availWidth - 2) && window.innerHeight >= (screen.availHeight - 2)
|
|
2119
|
+
fullscreen = coversScreen || coversWorkArea
|
|
2120
|
+
} catch {
|
|
2121
|
+
fullscreen = false
|
|
2122
|
+
}
|
|
2123
|
+
void G.api('app.newWindow', { fullscreen }).catch((error) => {
|
|
2114
2124
|
let opened = null
|
|
2115
2125
|
try { opened = window.open(location.href, '_blank') } catch { opened = null }
|
|
2116
2126
|
if (opened !== null && opened !== undefined) {
|
package/src/client/99-main.js
CHANGED
|
@@ -429,6 +429,44 @@ const GUFA_PLUGIN = {
|
|
|
429
429
|
console.error('[gufa-code] 悬浮模式初始化失败', error)
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
+
/* ── 实例窗口(⌘⇧N 打开的 helper full 窗口):直接进入古法编程 ──
|
|
433
|
+
helper 已注入项目和编辑器状态;这里在客户端 boot 后反复调 G.enterGufa,
|
|
434
|
+
直到 IDE 覆盖层真正挂载,避免和 slots 注册时序赛跑。 */
|
|
435
|
+
try {
|
|
436
|
+
const instanceMode = /[?&]gufa-instance=1/.test(String(location.search || ''))
|
|
437
|
+
if (instanceMode && document.documentElement.hasAttribute('data-gufa-float') !== true) {
|
|
438
|
+
G.instanceBoot = true
|
|
439
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
440
|
+
let attempts = 0
|
|
441
|
+
let timer = 0
|
|
442
|
+
const tryEnter = () => {
|
|
443
|
+
try {
|
|
444
|
+
if (document.querySelector('.gufa-overlay-root') !== null) {
|
|
445
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
446
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
if (typeof G.enterGufa === 'function') G.enterGufa()
|
|
450
|
+
} catch {
|
|
451
|
+
/* ignore */
|
|
452
|
+
}
|
|
453
|
+
attempts += 1
|
|
454
|
+
if (attempts > 80 && timer !== 0) {
|
|
455
|
+
window.clearInterval(timer)
|
|
456
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
tryEnter()
|
|
460
|
+
timer = window.setInterval(tryEnter, 200)
|
|
461
|
+
ctx.effect(() => () => {
|
|
462
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
463
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
464
|
+
}, 'gufa-code: instance boot')
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.error('[gufa-code] 实例窗口自动进入 IDE 失败', error)
|
|
468
|
+
}
|
|
469
|
+
|
|
432
470
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
433
471
|
try {
|
|
434
472
|
if (typeof G.mode?.get === 'function' && G.mode.get() === true) document.documentElement.setAttribute('data-gufa-ide', '')
|