dsh-gufa-code 1.3.95 → 1.3.100
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 -0
- package/client.js +70 -2
- package/desktop/float/GufaFloat.m +124 -31
- 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 +10 -0
- package/host/app-window.js +79 -0
- package/host/fs.js +13 -0
- package/package.json +1 -1
- package/src/client/00-core.js +2 -0
- package/src/client/85-shortcuts.js +2 -0
- package/src/client/90-app.js +28 -1
- package/src/client/99-main.js +37 -0
package/README.md
CHANGED
|
@@ -44,6 +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、共享登录态),新窗口会**直接进入古法编程**并恢复当前项目/标签页/布局;当前窗口全屏时新窗口也直接全屏;macOS 已支持,Windows/Linux 待 helper 实现 full 模式;
|
|
47
48
|
- **全局搜索 / 替换**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则、包含/排除文件(glob);结果按文件分组、高亮匹配,点击跳转行列;替换栏支持保留大小写(AB)、全部替换(需确认)、按文件替换(悬停文件头铅笔)、按单行匹配替换与忽略(悬停结果行);替换前会自动保存未落盘的编辑器内容;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;摸鱼悬浮窗里同样可用;
|
|
48
49
|
- 资源管理器文件/文件夹可直接**拖进右侧输入框**变成 @引用;
|
|
49
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.100'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -119,6 +119,7 @@ const DICT_ZH = {
|
|
|
119
119
|
'shortcuts.toggleTerminal': '显示 / 隐藏终端',
|
|
120
120
|
'shortcuts.toggleSidebar': '显示 / 隐藏左侧栏',
|
|
121
121
|
'shortcuts.closeTab': '关闭当前标签页',
|
|
122
|
+
'shortcuts.newWindow': '新建一个实例窗口',
|
|
122
123
|
'shortcuts.explorer': '聚焦资源管理器',
|
|
123
124
|
'shortcuts.search': '聚焦全局搜索',
|
|
124
125
|
'shortcuts.git': '聚焦源代码管理',
|
|
@@ -376,6 +377,7 @@ const DICT_EN = {
|
|
|
376
377
|
'shortcuts.toggleTerminal': 'Toggle terminal panel',
|
|
377
378
|
'shortcuts.toggleSidebar': 'Toggle sidebar',
|
|
378
379
|
'shortcuts.closeTab': 'Close current tab',
|
|
380
|
+
'shortcuts.newWindow': 'New window',
|
|
379
381
|
'shortcuts.explorer': 'Focus explorer',
|
|
380
382
|
'shortcuts.search': 'Focus search',
|
|
381
383
|
'shortcuts.git': 'Focus source control',
|
|
@@ -11360,6 +11362,7 @@ G.shortcutAction = function shortcutAction(event) {
|
|
|
11360
11362
|
if (key === 'h' || key === 'u') return 'panelSsh'
|
|
11361
11363
|
if (key === 'b') return 'toggleSidebar'
|
|
11362
11364
|
if (key === 'w') return 'closeTab'
|
|
11365
|
+
if (key === 'n') return 'newWindow'
|
|
11363
11366
|
if (isBackquote) return 'newTerminal'
|
|
11364
11367
|
if (key === '/' || key === '?') return 'shortcuts'
|
|
11365
11368
|
if (key === 'enter' || code === 'Enter' || code === 'NumpadEnter') return 'commit'
|
|
@@ -11790,6 +11793,7 @@ G.SHORTCUTS = [
|
|
|
11790
11793
|
{ action: 'toggleTerminal', labelKey: 'shortcuts.toggleTerminal', keys: ['J'], shift: false, macText: '⌘J / ⌃`', otherText: 'Ctrl+J / Ctrl+`' },
|
|
11791
11794
|
{ action: 'toggleSidebar', labelKey: 'shortcuts.toggleSidebar', keys: ['B'], shift: false },
|
|
11792
11795
|
{ action: 'closeTab', labelKey: 'shortcuts.closeTab', keys: ['W'], shift: false },
|
|
11796
|
+
{ action: 'newWindow', labelKey: 'shortcuts.newWindow', keys: ['N'], shift: true },
|
|
11793
11797
|
{ action: 'panelExplorer', labelKey: 'shortcuts.explorer', keys: ['E'], shift: true },
|
|
11794
11798
|
{ action: 'panelSearch', labelKey: 'shortcuts.search', keys: ['F'], shift: true },
|
|
11795
11799
|
{ action: 'panelGit', labelKey: 'shortcuts.git', keys: ['G'], shift: true },
|
|
@@ -13944,6 +13948,33 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13944
13948
|
const next = tabs[(index - 1 + tabs.length) % tabs.length]
|
|
13945
13949
|
if (next !== undefined) setActivePath(next.path)
|
|
13946
13950
|
},
|
|
13951
|
+
newWindow: () => {
|
|
13952
|
+
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI,
|
|
13953
|
+
并把当前项目/标签页状态与全屏状态带过去;失败才回退浏览器窗口。 */
|
|
13954
|
+
let fullscreen = false
|
|
13955
|
+
try {
|
|
13956
|
+
const coversScreen = window.innerWidth >= (screen.width - 2) && window.innerHeight >= (screen.height - 2)
|
|
13957
|
+
const coversWorkArea = window.innerWidth >= (screen.availWidth - 2) && window.innerHeight >= (screen.availHeight - 2)
|
|
13958
|
+
fullscreen = coversScreen || coversWorkArea
|
|
13959
|
+
} catch {
|
|
13960
|
+
fullscreen = false
|
|
13961
|
+
}
|
|
13962
|
+
let state
|
|
13963
|
+
try {
|
|
13964
|
+
state = buildFloatSnapshot()
|
|
13965
|
+
} catch {
|
|
13966
|
+
state = undefined
|
|
13967
|
+
}
|
|
13968
|
+
void G.api('app.newWindow', { state, fullscreen }).catch((error) => {
|
|
13969
|
+
let opened = null
|
|
13970
|
+
try { opened = window.open(location.href, '_blank') } catch { opened = null }
|
|
13971
|
+
if (opened !== null && opened !== undefined) {
|
|
13972
|
+
try { opened.focus() } catch { /* ignore */ }
|
|
13973
|
+
return
|
|
13974
|
+
}
|
|
13975
|
+
try { G.refToast(`打开新窗口失败:${G.errorText(error)}`, 'err') } catch { /* ignore */ }
|
|
13976
|
+
})
|
|
13977
|
+
},
|
|
13947
13978
|
shortcutsDialog: () => setShortcutsOpen((open) => open === false),
|
|
13948
13979
|
shortcuts: () => {
|
|
13949
13980
|
// 编辑器内 ⌘/ 是「切换行注释」(VS Code 一致),其他位置才打开快捷键列表
|
|
@@ -13976,7 +14007,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13976
14007
|
}
|
|
13977
14008
|
setShortcutsOpen((open) => open === false)
|
|
13978
14009
|
},
|
|
13979
|
-
}), [activePath, tabs, ui.terminalOpen, ui.sidebarOpen, saveFile, saveCompareTab, patchUi, closeTabWithConfirm])
|
|
14010
|
+
}), [activePath, tabs, ui.terminalOpen, ui.sidebarOpen, saveFile, saveCompareTab, patchUi, closeTabWithConfirm, buildFloatSnapshot])
|
|
13980
14011
|
G.useIdeShortcuts(ideShortcutHandlers)
|
|
13981
14012
|
|
|
13982
14013
|
/* 原生快捷键服务派发到当前 App 的动作表(IDE 模式内有效)。 */
|
|
@@ -15560,6 +15591,43 @@ const GUFA_PLUGIN = {
|
|
|
15560
15591
|
console.error('[gufa-code] 悬浮模式初始化失败', error)
|
|
15561
15592
|
}
|
|
15562
15593
|
|
|
15594
|
+
/* ── 实例窗口(⌘⇧N 打开的 helper full 窗口):直接进入古法编程 ──
|
|
15595
|
+
helper 已注入项目和编辑器状态;这里在客户端 boot 后反复调 G.enterGufa,
|
|
15596
|
+
直到 IDE 覆盖层真正挂载,避免和 slots 注册时序赛跑。 */
|
|
15597
|
+
try {
|
|
15598
|
+
const instanceMode = /[?&]gufa-instance=1/.test(String(location.search || ''))
|
|
15599
|
+
if (instanceMode && document.documentElement.hasAttribute('data-gufa-float') !== true) {
|
|
15600
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
15601
|
+
let attempts = 0
|
|
15602
|
+
let timer = 0
|
|
15603
|
+
const tryEnter = () => {
|
|
15604
|
+
try {
|
|
15605
|
+
if (document.querySelector('.gufa-overlay-root') !== null) {
|
|
15606
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15607
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
15608
|
+
return
|
|
15609
|
+
}
|
|
15610
|
+
if (typeof G.enterGufa === 'function') G.enterGufa()
|
|
15611
|
+
} catch {
|
|
15612
|
+
/* ignore */
|
|
15613
|
+
}
|
|
15614
|
+
attempts += 1
|
|
15615
|
+
if (attempts > 80 && timer !== 0) {
|
|
15616
|
+
window.clearInterval(timer)
|
|
15617
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15618
|
+
}
|
|
15619
|
+
}
|
|
15620
|
+
tryEnter()
|
|
15621
|
+
timer = window.setInterval(tryEnter, 200)
|
|
15622
|
+
ctx.effect(() => () => {
|
|
15623
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
15624
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
15625
|
+
}, 'gufa-code: instance boot')
|
|
15626
|
+
}
|
|
15627
|
+
} catch (error) {
|
|
15628
|
+
console.error('[gufa-code] 实例窗口自动进入 IDE 失败', error)
|
|
15629
|
+
}
|
|
15630
|
+
|
|
15563
15631
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
15564
15632
|
try {
|
|
15565
15633
|
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;
|
|
@@ -135,6 +162,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
135
162
|
@property (nonatomic, strong) NSDictionary *options;
|
|
136
163
|
@property (nonatomic, assign) EventHotKeyRef hotKeyRef;
|
|
137
164
|
@property (nonatomic, assign) BOOL following;
|
|
165
|
+
@property (nonatomic, assign) BOOL fullMode;
|
|
138
166
|
@property (nonatomic, assign) pid_t followPid;
|
|
139
167
|
@property (nonatomic, copy) NSString *followTitle;
|
|
140
168
|
@property (nonatomic, assign) AXUIElementRef followWindowRef;
|
|
@@ -178,6 +206,11 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
178
206
|
self.frameKey = @"gufa-float-frame-v1";
|
|
179
207
|
self.clickThrough = NO;
|
|
180
208
|
[self parseOptions];
|
|
209
|
+
self.fullMode = [self.options[@"full"] boolValue];
|
|
210
|
+
if (self.fullMode) {
|
|
211
|
+
self.frameKey = @"gufa-instance-frame-v1";
|
|
212
|
+
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
213
|
+
}
|
|
181
214
|
if ([self.options[@"controlPath"] isKindOfClass:[NSString class]]) self.controlPath = self.options[@"controlPath"];
|
|
182
215
|
[self watchControlFile];
|
|
183
216
|
/* 先激活目标 App:等它切到自己的 Space/全屏 Space 后再创建悬浮窗,
|
|
@@ -190,13 +223,15 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
190
223
|
__strong typeof(weakSelf) self = weakSelf;
|
|
191
224
|
if (self == nil) return;
|
|
192
225
|
[self buildWindow];
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
226
|
+
if (!self.fullMode) {
|
|
227
|
+
[self buildStatusItem];
|
|
228
|
+
[self registerToggleHotKey];
|
|
229
|
+
/* 摸鱼:等目标 App 到前台后隐藏 DSH 主窗口(⌘H 效果) */
|
|
230
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.45 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
231
|
+
GufaSetMainAppHidden(YES);
|
|
232
|
+
});
|
|
233
|
+
[self beginningFollowFromOptions];
|
|
234
|
+
}
|
|
200
235
|
[self loadWebContent];
|
|
201
236
|
});
|
|
202
237
|
}
|
|
@@ -350,21 +385,23 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
350
385
|
}
|
|
351
386
|
}
|
|
352
387
|
|
|
388
|
+
NSWindowStyleMask styleMask = self.fullMode
|
|
389
|
+
? (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable)
|
|
390
|
+
: (NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable);
|
|
353
391
|
self.window = [[GufaFloatWindow alloc] initWithContentRect:frame
|
|
354
|
-
styleMask:
|
|
392
|
+
styleMask:styleMask
|
|
355
393
|
backing:NSBackingStoreBuffered
|
|
356
394
|
defer:NO];
|
|
357
|
-
self.window.opaque = NO;
|
|
358
|
-
self.window.backgroundColor = NSColor.clearColor;
|
|
395
|
+
self.window.opaque = self.fullMode ? YES : NO;
|
|
396
|
+
self.window.backgroundColor = self.fullMode ? [NSColor colorWithCalibratedRed:0.07 green:0.07 blue:0.08 alpha:1.0] : NSColor.clearColor;
|
|
359
397
|
self.window.hasShadow = YES;
|
|
360
|
-
|
|
361
|
-
self.window.level = NSStatusWindowLevel;
|
|
398
|
+
self.window.level = self.fullMode ? NSNormalWindowLevel : NSStatusWindowLevel;
|
|
362
399
|
/* 固定吸附:默认不加入所有 Space(否则用户滑动切屏时摸鱼窗会跟着跑到当前屏);
|
|
363
400
|
只有「自由悬浮」模式才允许出现在所有 Space。 */
|
|
364
|
-
self.window.collectionBehavior =
|
|
365
|
-
| NSWindowCollectionBehaviorIgnoresCycle);
|
|
401
|
+
self.window.collectionBehavior = self.fullMode ? NSWindowCollectionBehaviorDefault
|
|
402
|
+
: (NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorIgnoresCycle);
|
|
366
403
|
self.window.minSize = NSMakeSize(520, 360);
|
|
367
|
-
self.window.title = @"古法编程悬浮层";
|
|
404
|
+
self.window.title = self.fullMode ? @"DeepSeek Harness" : @"古法编程悬浮层";
|
|
368
405
|
|
|
369
406
|
NSView *container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
|
|
370
407
|
container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
@@ -374,7 +411,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
374
411
|
config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
|
|
375
412
|
/* 文档开始前注入:悬浮模式标记 + 主窗口状态(项目/UI 布局/打开的标签页/会话),
|
|
376
413
|
让悬浮窗里的古法编程「接着主窗口继续干活」,而不是一个空白的新实例。 */
|
|
377
|
-
NSMutableString *bootstrap = [NSMutableString stringWithString:@"try{localStorage.setItem('gufa-code:float','1');"];
|
|
414
|
+
NSMutableString *bootstrap = self.fullMode ? [NSMutableString string] : [NSMutableString stringWithString:@"try{localStorage.setItem('gufa-code:float','1');"];
|
|
378
415
|
NSDictionary *state = [self.options[@"state"] isKindOfClass:[NSDictionary class]] ? self.options[@"state"] : nil;
|
|
379
416
|
if (state != nil) {
|
|
380
417
|
NSData *stateJson = [NSJSONSerialization dataWithJSONObject:state options:0 error:NULL];
|
|
@@ -403,11 +440,44 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
403
440
|
}
|
|
404
441
|
}
|
|
405
442
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
443
|
+
if (self.fullMode) {
|
|
444
|
+
/* 实例窗口:只注入主窗口的编辑器状态(项目/标签页/UI),让新窗口直接进古法编程并恢复现场。 */
|
|
445
|
+
NSDictionary *fullState = [self.options[@"state"] isKindOfClass:[NSDictionary class]] ? self.options[@"state"] : nil;
|
|
446
|
+
NSMutableString *js = [NSMutableString stringWithString:@"try{"];
|
|
447
|
+
/* 同一个 WKWebView data store 可能还留着上次摸鱼的标记,实例窗口必须先清掉 */
|
|
448
|
+
[js appendString:@"localStorage.removeItem('gufa-code:float');"];
|
|
449
|
+
if (fullState != nil) {
|
|
450
|
+
NSString *projectRoot = [fullState[@"projectRoot"] isKindOfClass:[NSString class]] ? fullState[@"projectRoot"] : @"";
|
|
451
|
+
if (projectRoot.length > 0) {
|
|
452
|
+
/* 客户端用 JSON.parse 读 project,本地存的是 JSON 字符串(带引号),这里用 JSON.stringify 生成 */
|
|
453
|
+
[js appendFormat:@"localStorage.setItem('gufa-code:project', JSON.stringify(%@));", GufaJSONLiteralString(projectRoot)];
|
|
454
|
+
}
|
|
455
|
+
NSString *stateText = GufaJSONLiteralString(fullState);
|
|
456
|
+
if (stateText.length > 0) {
|
|
457
|
+
NSString *escapedState = [stateText stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
|
|
458
|
+
escapedState = [escapedState stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
|
|
459
|
+
escapedState = [escapedState stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
|
|
460
|
+
escapedState = [escapedState stringByReplacingOccurrencesOfString:@"\r" withString:@""];
|
|
461
|
+
[js appendFormat:@"localStorage.setItem('gufa-code:float-state','%@');", escapedState];
|
|
462
|
+
}
|
|
463
|
+
NSDictionary *fullUi = [fullState[@"ui"] isKindOfClass:[NSDictionary class]] ? fullState[@"ui"] : nil;
|
|
464
|
+
if (fullUi != nil) {
|
|
465
|
+
NSString *uiText = GufaJSONLiteralString(fullUi);
|
|
466
|
+
NSString *escapedUi = [uiText stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
|
|
467
|
+
escapedUi = [escapedUi stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
|
|
468
|
+
[js appendFormat:@"localStorage.setItem('gufa-code:ui:v1','%@');", escapedUi];
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
[js appendString:@"}catch(e){}"];
|
|
472
|
+
WKUserScript *stateScript = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
|
|
473
|
+
[config.userContentController addUserScript:stateScript];
|
|
474
|
+
} else {
|
|
475
|
+
[bootstrap appendString:@"}catch(e){}"];
|
|
476
|
+
WKUserScript *floatMarker = [[WKUserScript alloc] initWithSource:bootstrap
|
|
477
|
+
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
|
|
478
|
+
forMainFrameOnly:YES];
|
|
479
|
+
[config.userContentController addUserScript:floatMarker];
|
|
480
|
+
}
|
|
411
481
|
self.webView = [[WKWebView alloc] initWithFrame:container.bounds configuration:config];
|
|
412
482
|
self.webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
413
483
|
self.navigation = [[GufaNavigationDelegate alloc] init];
|
|
@@ -416,12 +486,14 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
416
486
|
[self.webView setValue:@NO forKey:@"drawsBackground"];
|
|
417
487
|
[container addSubview:self.webView];
|
|
418
488
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
489
|
+
if (!self.fullMode) {
|
|
490
|
+
CGFloat stripHeight = 22.0;
|
|
491
|
+
GufaDragStrip *strip = [[GufaDragStrip alloc] initWithFrame:NSMakeRect(0, frame.size.height - stripHeight, frame.size.width, stripHeight)];
|
|
492
|
+
strip.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
|
|
493
|
+
strip.menu = self.mainMenu;
|
|
494
|
+
[container addSubview:strip];
|
|
495
|
+
self.dragStrip = strip;
|
|
496
|
+
}
|
|
425
497
|
|
|
426
498
|
self.window.contentView = container;
|
|
427
499
|
if (self.window.frame.size.width < 400 || self.window.frame.size.height < 300) {
|
|
@@ -434,6 +506,13 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
434
506
|
}
|
|
435
507
|
[self.window makeKeyAndOrderFront:nil];
|
|
436
508
|
[NSApp activateIgnoringOtherApps:YES];
|
|
509
|
+
if (self.fullMode && [self.options[@"fullscreen"] boolValue]) {
|
|
510
|
+
__weak typeof(self) weakSelf = self;
|
|
511
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
512
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
513
|
+
if (strongSelf != nil && strongSelf.window != nil && (strongSelf.window.styleMask & NSWindowStyleMaskFullScreen) == 0) [strongSelf.window toggleFullScreen:nil];
|
|
514
|
+
});
|
|
515
|
+
}
|
|
437
516
|
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);
|
|
438
517
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidEndLiveResizeNotification object:self.window];
|
|
439
518
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveFrame) name:NSWindowDidMoveNotification object:self.window];
|
|
@@ -472,6 +551,10 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
472
551
|
self.navigation.pendingLoad = ^{
|
|
473
552
|
__strong typeof(weakSelf) self = weakSelf;
|
|
474
553
|
if (self == nil) return;
|
|
554
|
+
if (self.fullMode) {
|
|
555
|
+
[self.webView loadRequest:[NSURLRequest requestWithURL:GufaInstanceURL(appUrl)]];
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
475
558
|
/* 鉴权 cookie 已在 token URL 重定向时写入;这里用 JS 写 localStorage(避开 URL 长度/转义问题),
|
|
476
559
|
再跳到带 gufa-float 标记的干净地址,客户端据此自动进入摸鱼模式并恢复状态。 */
|
|
477
560
|
NSMutableString *js = [NSMutableString stringWithString:@"try{"];
|
|
@@ -529,9 +612,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
529
612
|
NSString *build = [self.options[@"build"] isKindOfClass:[NSString class]] ? self.options[@"build"] : @"";
|
|
530
613
|
NSString *lastBuild = [[NSUserDefaults standardUserDefaults] stringForKey:@"gufa-float-build"];
|
|
531
614
|
BOOL versionChanged = build.length == 0 || lastBuild == nil || ![lastBuild isEqualToString:build];
|
|
532
|
-
NSSet<NSString *> *types =
|
|
533
|
-
? [
|
|
534
|
-
: [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil];
|
|
615
|
+
NSSet<NSString *> *types = self.fullMode
|
|
616
|
+
? [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil]
|
|
617
|
+
: (versionChanged ? [WKWebsiteDataStore allWebsiteDataTypes] : [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil]);
|
|
535
618
|
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:types modifiedSince:[NSDate dateWithTimeIntervalSince1970:0] completionHandler:^{
|
|
536
619
|
if (build.length > 0) [[NSUserDefaults standardUserDefaults] setObject:build forKey:@"gufa-float-build"];
|
|
537
620
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -559,6 +642,10 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
|
|
|
559
642
|
if (httpCookie != nil) {
|
|
560
643
|
WKHTTPCookieStore *store = [WKWebsiteDataStore defaultDataStore].httpCookieStore;
|
|
561
644
|
[store setCookie:httpCookie completionHandler:^{
|
|
645
|
+
if (self.fullMode) {
|
|
646
|
+
[self.webView loadRequest:[NSURLRequest requestWithURL:GufaInstanceURL(self.options[@"appUrl"])]];
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
562
649
|
NSURLComponents *components = [NSURLComponents componentsWithString:self.options[@"appUrl"] ?: @""];
|
|
563
650
|
components.queryItems = @[[NSURLQueryItem queryItemWithName:@"gufa-float" value:@"1"]];
|
|
564
651
|
[self.webView loadRequest:[NSURLRequest requestWithURL:components.URL]];
|
|
@@ -1129,8 +1216,14 @@ int main(int argc, const char *argv[]) {
|
|
|
1129
1216
|
}
|
|
1130
1217
|
}
|
|
1131
1218
|
@autoreleasepool {
|
|
1219
|
+
BOOL fullWindow = NO;
|
|
1220
|
+
if (argc > 1 && argc < 3) {
|
|
1221
|
+
NSData *payloadData = [[NSString stringWithUTF8String:argv[1]] dataUsingEncoding:NSUTF8StringEncoding];
|
|
1222
|
+
id parsed = payloadData != nil ? [NSJSONSerialization JSONObjectWithData:payloadData options:0 error:NULL] : nil;
|
|
1223
|
+
if ([parsed isKindOfClass:[NSDictionary class]]) fullWindow = [parsed[@"full"] boolValue];
|
|
1224
|
+
}
|
|
1132
1225
|
[NSApplication sharedApplication];
|
|
1133
|
-
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
|
1226
|
+
[NSApp setActivationPolicy:fullWindow ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory];
|
|
1134
1227
|
GufaInstallEditMenu();
|
|
1135
1228
|
GufaInstallTermHandler();
|
|
1136
1229
|
GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
|
|
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.100</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.100</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
|
@@ -53,6 +53,16 @@
|
|
|
53
53
|
- 有多个语言共享扩展名(`.p` Pascal、`.m` Objective-C、`.v` Verilog、`.cls` Apex、`.pp` Ruby/Pascal、`.s` MIPS、`.config` XML 等)时,按 Monaco 默认取一个;用户项目里如果扩展名含义不同,改 `LANG_BY_EXT` 一行即可。
|
|
54
54
|
- 点开头文件(`.babelrc/.eslintrc/.jshintrc/.jscsrc/.bowerrc` → json、`.gitconfig` → ini、`.rprofile` → r)要在 `languageOf` 的 `lastIndexOf('.')` 之前特判,否则会被当成 plaintext。
|
|
55
55
|
|
|
56
|
+
## 0.11 ⌘⇧N 新实例窗口(1.3.97)
|
|
57
|
+
|
|
58
|
+
- Electron 桌面壳是单实例应用(`requestSingleInstanceLock`),且只有 Electron main 能 `new BrowserWindow`;插件 Host 跑在独立的 Node 模式进程里,**没有 electron 模块**(`import('electron')` 会解析到 npm 包而不是内建模块),不能在 Host 里开原生 BrowserWindow。
|
|
59
|
+
- 实现:复用插件自带的原生 helper(`desktop/float/GufaFloat.m`),payload 传 `{full:true, authUrl, appUrl}` —— helper 建普通标题栏窗口、Regular 激活策略、跳过摸鱼 localStorage/隐藏主窗/吸附,加载同一个 DSH Web GUI;鉴权复用它已有的 `connection.authenticatedUrl()` token 流程。
|
|
60
|
+
- 客户端 ⌘⇧N 必须先调 Host `app.newWindow`,失败才回退 `window.open`(Electron 的 setWindowOpenHandler 会 deny 并用外部浏览器打开 http(s),不是应用内窗口)。
|
|
61
|
+
- 新窗口与 Electron 主窗口共享的是 **同一个 Host/服务端**,但 UI 进程独立(WKWebView,不走 Electron preload);所以别让新窗口依赖 `window.dshDesktop` 之类的 Electron preload API。
|
|
62
|
+
- **自动进入古法编程**:helper full 模式在 document-start 注入 `gufa-code:project` / `gufa-code:float-state` / `gufa-code:ui:v1`;URL 带 `?gufa-instance=1`,客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root` 挂载。注意 `gufa-code:project` 客户端用 `JSON.parse` 读,注入时必须写 **JSON 字符串**(`JSON.stringify(...)` 生成带引号的值),直接写裸路径会读成 null。
|
|
63
|
+
- helper 的 WKWebView data store 与摸鱼悬浮层共享;full 模式必须 `localStorage.removeItem('gufa-code:float')`,否则新窗口会误进摸鱼 UI。
|
|
64
|
+
- **全屏继承**:客户端用 `innerWidth/innerHeight` 对比 `screen.width/height` 和 `screen.availWidth/availHeight` 判断当前是否全屏,payload 传 `fullscreen:true`,helper 在窗口显示后 `toggleFullScreen`;不要依赖 Electron preload 或 AX 查询(Host 在 Node 模式进程里拿不到 Electron)。
|
|
65
|
+
|
|
56
66
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
57
67
|
|
|
58
68
|
**现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⌘⇧N:新开一个 Harness 实例窗口。
|
|
3
|
+
*
|
|
4
|
+
* 桌面壳是 Electron 单实例应用,且主窗口只有 dsh-desktop-host 的 Node 进程可以管理;
|
|
5
|
+
* 插件 Host 运行在独立 Node 进程里,没法直接 new BrowserWindow。这里复用古法编程
|
|
6
|
+
* 自带的原生 helper(desktop/float,跨平台 WKWebView/WebView2/WebKit2GTK),给它传
|
|
7
|
+
* `{ full: true }` 就打开一个普通窗口,加载同一个 DSH Web GUI(用 connection 签发的
|
|
8
|
+
* 一次性鉴权 URL,和摸鱼悬浮层同一套登录逻辑)。
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
12
|
+
import { dirname, join } from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
|
|
15
|
+
import { ApiError } from './context.js'
|
|
16
|
+
import { floatBinaryCandidates } from './float-platform.js'
|
|
17
|
+
|
|
18
|
+
const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
19
|
+
|
|
20
|
+
const PLUGIN_VERSION = (() => {
|
|
21
|
+
try {
|
|
22
|
+
const pkg = JSON.parse(readFileSync(join(PLUGIN_ROOT, 'package.json'), 'utf8'))
|
|
23
|
+
return typeof pkg.version === 'string' ? pkg.version : 'dev'
|
|
24
|
+
} catch {
|
|
25
|
+
return 'dev'
|
|
26
|
+
}
|
|
27
|
+
})()
|
|
28
|
+
|
|
29
|
+
function floatBinaryPath() {
|
|
30
|
+
const root = join(PLUGIN_ROOT, 'desktop', 'float', 'bin')
|
|
31
|
+
for (const full of floatBinaryCandidates(process.platform, process.arch, root)) {
|
|
32
|
+
if (existsSync(full)) return full
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function newWindow(body, env) {
|
|
38
|
+
if (process.platform !== 'darwin') {
|
|
39
|
+
throw new ApiError('unsupported-platform', '实例窗口目前只支持 macOS(Windows/Linux helper 尚未实现 full 模式)', 501)
|
|
40
|
+
}
|
|
41
|
+
const binary = floatBinaryPath()
|
|
42
|
+
if (binary === null) throw new ApiError('missing-helper', '实例窗口 helper 未构建(desktop/float/bin)', 500)
|
|
43
|
+
const webServer = env.ctx.get('webServer')
|
|
44
|
+
const connection = env.ctx.get('connection')
|
|
45
|
+
if (webServer === undefined || webServer === null || connection === undefined || connection === null || typeof connection.authenticatedUrl !== 'function') {
|
|
46
|
+
throw new ApiError('unavailable', '当前 Host 不提供 Web 服务地址,无法打开实例窗口', 500)
|
|
47
|
+
}
|
|
48
|
+
const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
|
|
49
|
+
const authUrl = connection.authenticatedUrl(`${base}/`)
|
|
50
|
+
const state = body !== null && typeof body === 'object' && body.state !== null && typeof body.state === 'object' ? body.state : undefined
|
|
51
|
+
const fullscreen = body !== null && typeof body === 'object' && body.fullscreen === true
|
|
52
|
+
const payload = JSON.stringify({
|
|
53
|
+
full: true,
|
|
54
|
+
fullscreen,
|
|
55
|
+
state,
|
|
56
|
+
authUrl,
|
|
57
|
+
appUrl: `${base}/`,
|
|
58
|
+
title: 'DeepSeek Harness',
|
|
59
|
+
build: PLUGIN_VERSION,
|
|
60
|
+
ownerPid: process.ppid,
|
|
61
|
+
})
|
|
62
|
+
try {
|
|
63
|
+
const child = spawn(binary, [payload], {
|
|
64
|
+
detached: true,
|
|
65
|
+
stdio: 'ignore',
|
|
66
|
+
windowsHide: false,
|
|
67
|
+
env: { ...process.env, GUFA_FLOAT_PAYLOAD: payload },
|
|
68
|
+
})
|
|
69
|
+
child.unref()
|
|
70
|
+
void body
|
|
71
|
+
return { ok: true, pid: child.pid ?? null }
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new ApiError('new-window-failed', `打开实例窗口失败:${String(error?.message ?? error)}`, 500)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function registerAppWindow(router, env) {
|
|
78
|
+
router.method('app.newWindow', (body) => newWindow(body, env))
|
|
79
|
+
}
|
package/host/fs.js
CHANGED
|
@@ -289,6 +289,19 @@ export function register(router, env) {
|
|
|
289
289
|
/* Tab 行内补全:借用 Harness 自己的模型服务 */
|
|
290
290
|
registerCompletion(router, env)
|
|
291
291
|
|
|
292
|
+
/* ⌘⇧N:打开新的 Harness 实例窗口(Electron 单实例下新建 BrowserWindow)。
|
|
293
|
+
app-window.js 用带 mtime 的动态 import,改它不必重启 Host。 */
|
|
294
|
+
router.method('app.newWindow', async (body) => {
|
|
295
|
+
let stamp = '0'
|
|
296
|
+
try {
|
|
297
|
+
stamp = String(statSync(new URL('./app-window.js', import.meta.url)).mtimeMs)
|
|
298
|
+
} catch {
|
|
299
|
+
stamp = '0'
|
|
300
|
+
}
|
|
301
|
+
const module = await import(new URL(`./app-window.js?gufa-app-window=${stamp}`, import.meta.url).href)
|
|
302
|
+
return module.newWindow(body, env)
|
|
303
|
+
})
|
|
304
|
+
|
|
292
305
|
/* 代码导航(Cmd+点击跳定义):实现放在 code.js,但 Host 热重载只按 host/*.js 的 mtime
|
|
293
306
|
触发,因此这里用带 mtime 的 query 动态 import,code.js 改动后下一次请求就能热生效。 */
|
|
294
307
|
router.method('code.definition', async (body) => {
|
package/package.json
CHANGED
package/src/client/00-core.js
CHANGED
|
@@ -111,6 +111,7 @@ const DICT_ZH = {
|
|
|
111
111
|
'shortcuts.toggleTerminal': '显示 / 隐藏终端',
|
|
112
112
|
'shortcuts.toggleSidebar': '显示 / 隐藏左侧栏',
|
|
113
113
|
'shortcuts.closeTab': '关闭当前标签页',
|
|
114
|
+
'shortcuts.newWindow': '新建一个实例窗口',
|
|
114
115
|
'shortcuts.explorer': '聚焦资源管理器',
|
|
115
116
|
'shortcuts.search': '聚焦全局搜索',
|
|
116
117
|
'shortcuts.git': '聚焦源代码管理',
|
|
@@ -368,6 +369,7 @@ const DICT_EN = {
|
|
|
368
369
|
'shortcuts.toggleTerminal': 'Toggle terminal panel',
|
|
369
370
|
'shortcuts.toggleSidebar': 'Toggle sidebar',
|
|
370
371
|
'shortcuts.closeTab': 'Close current tab',
|
|
372
|
+
'shortcuts.newWindow': 'New window',
|
|
371
373
|
'shortcuts.explorer': 'Focus explorer',
|
|
372
374
|
'shortcuts.search': 'Focus search',
|
|
373
375
|
'shortcuts.git': 'Focus source control',
|
|
@@ -51,6 +51,7 @@ G.shortcutAction = function shortcutAction(event) {
|
|
|
51
51
|
if (key === 'h' || key === 'u') return 'panelSsh'
|
|
52
52
|
if (key === 'b') return 'toggleSidebar'
|
|
53
53
|
if (key === 'w') return 'closeTab'
|
|
54
|
+
if (key === 'n') return 'newWindow'
|
|
54
55
|
if (isBackquote) return 'newTerminal'
|
|
55
56
|
if (key === '/' || key === '?') return 'shortcuts'
|
|
56
57
|
if (key === 'enter' || code === 'Enter' || code === 'NumpadEnter') return 'commit'
|
|
@@ -481,6 +482,7 @@ G.SHORTCUTS = [
|
|
|
481
482
|
{ action: 'toggleTerminal', labelKey: 'shortcuts.toggleTerminal', keys: ['J'], shift: false, macText: '⌘J / ⌃`', otherText: 'Ctrl+J / Ctrl+`' },
|
|
482
483
|
{ action: 'toggleSidebar', labelKey: 'shortcuts.toggleSidebar', keys: ['B'], shift: false },
|
|
483
484
|
{ action: 'closeTab', labelKey: 'shortcuts.closeTab', keys: ['W'], shift: false },
|
|
485
|
+
{ action: 'newWindow', labelKey: 'shortcuts.newWindow', keys: ['N'], shift: true },
|
|
484
486
|
{ action: 'panelExplorer', labelKey: 'shortcuts.explorer', keys: ['E'], shift: true },
|
|
485
487
|
{ action: 'panelSearch', labelKey: 'shortcuts.search', keys: ['F'], shift: true },
|
|
486
488
|
{ action: 'panelGit', labelKey: 'shortcuts.git', keys: ['G'], shift: true },
|
package/src/client/90-app.js
CHANGED
|
@@ -2107,6 +2107,33 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2107
2107
|
const next = tabs[(index - 1 + tabs.length) % tabs.length]
|
|
2108
2108
|
if (next !== undefined) setActivePath(next.path)
|
|
2109
2109
|
},
|
|
2110
|
+
newWindow: () => {
|
|
2111
|
+
/* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI,
|
|
2112
|
+
并把当前项目/标签页状态与全屏状态带过去;失败才回退浏览器窗口。 */
|
|
2113
|
+
let fullscreen = false
|
|
2114
|
+
try {
|
|
2115
|
+
const coversScreen = window.innerWidth >= (screen.width - 2) && window.innerHeight >= (screen.height - 2)
|
|
2116
|
+
const coversWorkArea = window.innerWidth >= (screen.availWidth - 2) && window.innerHeight >= (screen.availHeight - 2)
|
|
2117
|
+
fullscreen = coversScreen || coversWorkArea
|
|
2118
|
+
} catch {
|
|
2119
|
+
fullscreen = false
|
|
2120
|
+
}
|
|
2121
|
+
let state
|
|
2122
|
+
try {
|
|
2123
|
+
state = buildFloatSnapshot()
|
|
2124
|
+
} catch {
|
|
2125
|
+
state = undefined
|
|
2126
|
+
}
|
|
2127
|
+
void G.api('app.newWindow', { state, fullscreen }).catch((error) => {
|
|
2128
|
+
let opened = null
|
|
2129
|
+
try { opened = window.open(location.href, '_blank') } catch { opened = null }
|
|
2130
|
+
if (opened !== null && opened !== undefined) {
|
|
2131
|
+
try { opened.focus() } catch { /* ignore */ }
|
|
2132
|
+
return
|
|
2133
|
+
}
|
|
2134
|
+
try { G.refToast(`打开新窗口失败:${G.errorText(error)}`, 'err') } catch { /* ignore */ }
|
|
2135
|
+
})
|
|
2136
|
+
},
|
|
2110
2137
|
shortcutsDialog: () => setShortcutsOpen((open) => open === false),
|
|
2111
2138
|
shortcuts: () => {
|
|
2112
2139
|
// 编辑器内 ⌘/ 是「切换行注释」(VS Code 一致),其他位置才打开快捷键列表
|
|
@@ -2139,7 +2166,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2139
2166
|
}
|
|
2140
2167
|
setShortcutsOpen((open) => open === false)
|
|
2141
2168
|
},
|
|
2142
|
-
}), [activePath, tabs, ui.terminalOpen, ui.sidebarOpen, saveFile, saveCompareTab, patchUi, closeTabWithConfirm])
|
|
2169
|
+
}), [activePath, tabs, ui.terminalOpen, ui.sidebarOpen, saveFile, saveCompareTab, patchUi, closeTabWithConfirm, buildFloatSnapshot])
|
|
2143
2170
|
G.useIdeShortcuts(ideShortcutHandlers)
|
|
2144
2171
|
|
|
2145
2172
|
/* 原生快捷键服务派发到当前 App 的动作表(IDE 模式内有效)。 */
|
package/src/client/99-main.js
CHANGED
|
@@ -429,6 +429,43 @@ 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
|
+
document.documentElement.setAttribute('data-gufa-booting', '1')
|
|
439
|
+
let attempts = 0
|
|
440
|
+
let timer = 0
|
|
441
|
+
const tryEnter = () => {
|
|
442
|
+
try {
|
|
443
|
+
if (document.querySelector('.gufa-overlay-root') !== null) {
|
|
444
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
445
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
if (typeof G.enterGufa === 'function') G.enterGufa()
|
|
449
|
+
} catch {
|
|
450
|
+
/* ignore */
|
|
451
|
+
}
|
|
452
|
+
attempts += 1
|
|
453
|
+
if (attempts > 80 && timer !== 0) {
|
|
454
|
+
window.clearInterval(timer)
|
|
455
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
tryEnter()
|
|
459
|
+
timer = window.setInterval(tryEnter, 200)
|
|
460
|
+
ctx.effect(() => () => {
|
|
461
|
+
if (timer !== 0) window.clearInterval(timer)
|
|
462
|
+
document.documentElement.removeAttribute('data-gufa-booting')
|
|
463
|
+
}, 'gufa-code: instance boot')
|
|
464
|
+
}
|
|
465
|
+
} catch (error) {
|
|
466
|
+
console.error('[gufa-code] 实例窗口自动进入 IDE 失败', error)
|
|
467
|
+
}
|
|
468
|
+
|
|
432
469
|
/* HMR 重载时如果仍处于 IDE 模式,重新打上标记(卸载清理会移除它) */
|
|
433
470
|
try {
|
|
434
471
|
if (typeof G.mode?.get === 'function' && G.mode.get() === true) document.documentElement.setAttribute('data-gufa-ide', '')
|