dsh-ide-window 0.3.3 → 0.3.4
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/AGENTS.md +24 -6
- package/CHANGELOG.md +15 -0
- package/README.md +6 -4
- package/client.js +174 -80
- package/index.js +16 -20
- package/locale/en.json +0 -2
- package/locale/zh.json +0 -2
- package/package.json +1 -1
- package/platform/contract.js +1 -0
- package/platform/macos.js +3 -1
- package/platform/windows.js +3 -2
package/AGENTS.md
CHANGED
|
@@ -68,7 +68,7 @@ locale/{zh,en}.json UI 文案(165 个键);插件管理器也从这里
|
|
|
68
68
|
| `66-callchain.js` | 调用链(Alt+单击):沿 `findReferences` 向上递归,思维导图式浮层 |
|
|
69
69
|
| `68-grep.js` | 工作区搜索 + jar 源码查询客户端 |
|
|
70
70
|
| `70-palette.js` | Search Everywhere(所有/类/符号/文件/文本/操作,默认所有) |
|
|
71
|
-
| `72-screenshot.js` |
|
|
71
|
+
| `72-screenshot.js` | **截图编辑器**:宿主按设备像素抓屏 → 铺满窗口显示 → 拖框选区(无预设)→ 选框下方浮动条(矩形/文字/撤销 | 截图/截图并跳转会话)→ 裁切导出(原始像素、≤1 MB);含 macOS 授权引导 |
|
|
72
72
|
| `90-apply.js` | 全部注册(槽位、快捷键、命令、设置项)+ `enter()/openPanel()` |
|
|
73
73
|
|
|
74
74
|
### 3.2 平台层(`platform/`,只支持 macOS + Windows)
|
|
@@ -217,21 +217,33 @@ tail -f /tmp/dsh-ide-test/logs/dsh-ide-window.log # 自测实例
|
|
|
217
217
|
### 4.2.1 截图编辑器
|
|
218
218
|
|
|
219
219
|
- 快捷键 `⌘⇧S`(Windows `Ctrl+Shift+S`),设置里可改;Search Everywhere 的「操作」里也有
|
|
220
|
-
-
|
|
220
|
+
- **桌面端与浏览器端同一套流程**:抓屏由**宿主**完成(宿主就跑在拥有屏幕的那台机器上),页面里的 `getDisplayMedia` 被 DSH 关掉不影响它。所以浏览器 tab 里按快捷键同样能截,不区分运行时
|
|
221
|
+
- **一次抓整屏,再在图上框选**:`screencapture -x` / Windows `CopyFromScreen` 抓完整屏 → 编辑器里拖出选框 → 只导出选框内那块(+ 标注)
|
|
222
|
+
- **按设备像素抓屏,不限 1080p**:`optimizeScreenshot(target, null)`(`IDE_SCREENSHOT_EDIT_EDGE = null`)——`sips` 不带 `-Z`、Windows 脚本不缩放,抓到多少像素就是多少像素。2560×1440 的屏就存 2560×1440 的 JPEG(q80 约 400 KB),原 PNG 用完即删
|
|
223
|
+
- **导出同样保原始像素**:不再强制 1920 长边,先按质量阶梯压到 ≤1 MB,只有实在压不下去才按 `1 → 1/1.25 → 1/1.5 → 1/2` 逐级缩小
|
|
224
|
+
- **为什么不在抓屏前用系统十字光标(`screencapture -i`)**:试过,跨平台不一致(Windows 没有等价 CLI),而且框选完就没有可标注的画布了。现在统一成「先截、后框、再标注」
|
|
221
225
|
- **交互**(客户端 Canvas,两个平台同一套代码):编辑器挂在 `shell.overlay` 上,覆盖整个窗口、不被面板 overflow 裁剪
|
|
226
|
+
- **画面按屏幕坐标 1:1 贴上去**:`scale = 1 / devicePixelRatio`,画布用 `position: absolute` + `left/top = -(window.screenX / window.screenY)`。截图是整屏,而浮层只盖住这个窗口——不减去窗口在屏幕上的偏移,画面就会在窗口里居中,于是**窗口自己的菜单栏/标题栏在画面里又出现一次**,看起来就是「重影/重叠」(用户实测截图里两条标题栏叠在一起)。减掉偏移后,冻结的画面正好落在原来屏幕的位置上,窗口外的部分被浮层裁掉
|
|
227
|
+
- **指针换算以画布为准**:`ideShotPoint(event, canvas, scale, bounds)` 用 `canvas.getBoundingClientRect()`,不要再按 stage 居中算(画布可能超出 stage)
|
|
228
|
+
- **不显示任何提示文案**:拖框去选范围这件事用的人一眼就懂,屏幕边缘那行字只会挡内容
|
|
222
229
|
- **没有预设选框**:打开时整屏压暗,用户按下左键并拖动 → 选框实时扩张 → 松开左键完成并固定
|
|
223
230
|
- **Esc 随时退出整个操作**:没开始拉框、正在拉框(拖到一半)、已经拉完 —— 三种状态下按 Esc 都直接关掉编辑器,并把拖动状态清空(随后那次 `pointerup` 不会再把它救回来)。监听挂在 **window 的捕获阶段**:浮层自己永远拿不到焦点,挂在浮层上的 `onKeyDown` 基本不会触发
|
|
224
|
-
- 操作条**只在松开左键之后出现**(`dragging` 为 true
|
|
231
|
+
- 操作条**只在松开左键之后出现**(`dragging` 为 true 时不渲染),拉框过程中界面上没有任何多余元素
|
|
225
232
|
- **先抓屏、再渲染**:抓屏期间界面上不能出现任何自己的元素(连「正在截图…」的字都会被截进图里)。`startScreenshot()` 里 `screenshotBusy` 守住不重复触发,等 Host 返回后才 `setScreenshot({phase:'editing'})`;编辑器的「加载中」卡片只会在图片已经拿到之后出现
|
|
226
233
|
- 选框下方 10px 弹出**浮动操作条**(底边放不下时浮到上方):`矩形 / 文字 / 撤销 | 截图 / 截图并跳转会话`;按钮 `flex: 0 0 auto` + `white-space: nowrap`,卡片宽 392px(否则中文按钮会折成三行)
|
|
227
234
|
- **外观跟随工作区**:编辑器在 `shell.overlay` 里,**不在 `.iw-root` 内**,所以必须自己 `h(IdeStyles)` 注入样式表、自己带 `data-dsh-theme`(工作区主题属性)与字体变量。漏掉前者 = 卡片掉回浏览器默认样式(白底白字按钮);漏掉后者 = 深色工作区上出现白色卡片
|
|
228
235
|
- 卡片按钮直接复用面板的 `.iw-btn`(含 `.on` / `.primary`),字号取用户在设置里配的字号(`treeFontSize`,默认 14.5px)
|
|
229
236
|
- 标注只提供**矩形**与**文字**:`select` 是范围工具,`rect`/`text` 是标记;椭圆/箭头/画笔/马赛克的绘制代码仍在 `ideShotDrawOp` 里,但**不进操作条**(保持卡片小),要放开只需往 `IDE_SHOT_TOOLS` 与按钮里加一项
|
|
230
|
-
- 文字用 DOM `<input>`
|
|
237
|
+
- 文字用 DOM `<input>` 收输入(中文输入法可用),回车落到画布:
|
|
238
|
+
- 输入框装在 `.iw-shot-frame`(与画布等宽的定位容器)里,`left/top` 直接用**点击点**的图像坐标 × 缩放——早先直接按 stage 定位,画布居中时输入框会飘出去很远
|
|
239
|
+
- 样式是**透明**的:无底色、只有 1px 虚线描边(当前标注色),文字带阴影保证在任意背景上可读;字号跟着缩放走,落笔的 `stroke` 存的是同一个尺寸(图像像素),所见即所画
|
|
240
|
+
- 打开时**在别处按下就取消**,但**按在输入框自己身上不算「别处」**:stage 的 `onPointerDown` 先看 `event.target.closest('.iw-shot-text')`,input 自己再 `stopPropagation()`。漏了这条,用户点一下刚出现的输入框想输入文字,输入框立刻被当成「点了别处」取消——永远打不进字(用户实测反馈)
|
|
241
|
+
- Esc 先取消输入框(浮层让给 input 自己处理),再按一次才退出编辑器
|
|
242
|
+
- 文字框打开期间不要用 window 捕获去抢 Esc 再自己关一次:一次按键只能做一件事,重复处理会把整个编辑器关掉
|
|
231
243
|
- 标注存为**操作列表**(`{tool, color, stroke, x, y, width, height, points}`),重绘 = 底图 + 操作,撤销是 `pop()`
|
|
232
244
|
- `stroke` 是笔宽,`width/height` 是图形本身——**两者绝不能共用一个字段**(踩过:共用后 lineWidth 变成矩形宽度,整屏红块)
|
|
233
245
|
- 拖出来太小(< 24px)视为误点,选框清空、回到「整屏压暗」状态
|
|
234
|
-
- **导出**:裁出选框 →
|
|
246
|
+
- **导出**:裁出选框 → 原始像素 → JPEG 质量阶梯 `0.8/0.7/0.6/0.5/0.4`,第一个 ≤1 MB 的用(仍不合规才降分辨率);客户端算好 data URL,两个出口:
|
|
235
247
|
- **截图并跳转会话**:合成 `ClipboardEvent('paste')` + `DataTransfer` + `File` 塞进 Lexical 输入框,草稿里的文字/引用/附件不动
|
|
236
248
|
- **截图**:`{copyDataUrl}` 回传宿主(宿主写临时文件再 `osascript`/`.NET` 写剪贴板)——该路由请求体上限单独放宽到 8 MB(默认 64 KB 是给命令用的)
|
|
237
249
|
- **macOS 屏幕录制权限**:没授权时 `screencapture` 报 `could not create image from display`,宿主归类 `403 no-screen-permission`,编辑器位置的卡片给系统化指引 + 「打开系统设置」(`x-apple.systempreferences:…Privacy_ScreenCapture`),授权后必须**完全退出应用重开**。Windows 无此权限
|
|
@@ -349,11 +361,17 @@ dsh plugin --profile desktop add link:~/dev/dsh-ide-window
|
|
|
349
361
|
| 切到浅色主题后代码看不清(深色语法色仍在用) | 语法高亮是写死的深色配色,没有跟着主题走 | 语法色走 `--iw-syn-*` 变量,每套主题各给一组并按对比度校验(正文类 ≥4.5:1,注释 ≥3.5:1);`test/theme.mjs` 断言每套主题都有这 8 个变量 |
|
|
350
362
|
| 截图点了没反应,或只给一句「失败」 | `screencapture` 在 macOS 未授权时报 `could not create image from display`;浏览器侧也拿不到屏幕(DSH 把 `setDisplayMediaRequestHandler` 设成 `callback({})` 直接拒绝) | 截图只能由宿主用系统工具做;失败按文案归类成 `no-screen-permission`,弹层给「打开系统设置」深链 + 系统化指引 |
|
|
351
363
|
| 截图编辑器画出巨大的实心色块 | 操作对象里 `width` 同时被当成"笔宽"和"矩形宽度",`lineWidth` 变成几百像素 | 笔宽叫 `stroke`、几何叫 `width/height`;`ideShotDrawOp` 只从 `stroke` 取线宽 |
|
|
364
|
+
| 截图里看到自己的窗口重影(两条标题栏) | 截图是整屏、浮层只盖住窗口,却把画面在窗口里居中显示:窗口自己的菜单栏/标题栏在画面里又出现一次 | 画布按 `1/dpr` 画在 `left/top = -(screenX/screenY)`,让冻结的画面与真实屏幕对齐;指针换算统一用画布的 `getBoundingClientRect()` |
|
|
365
|
+
| 文字框刚出现,一点它就消失,永远输不进字 | stage 的 `onPointerDown` 把「按下即取消输入框」写成了无差别判断,点在 input 上冒泡到 stage 也算「点了别处」 | 取消逻辑要放过落在输入框内的按压(`event.target.closest('.iw-shot-text')` 直接 return),input 自己再 `stopPropagation()` |
|
|
366
|
+
| 文字框离鼠标很远 / 是白底方块盖住图 | 输入框按 stage 定位(画布在 stage 里居中,偏移丢了);样式用了不透明底色 + 实线边框 | 画布与输入框放进同宽的 `.iw-shot-frame`,坐标直接用图像点 × 缩放;输入框透明 + 虚线描边 |
|
|
367
|
+
| 按 Esc 关不掉文字框 | 浮层窗口级的 Esc 处理器在 `textAt !== null` 时直接 return,把「取消输入框」寄托在 input 自己的 onKeyDown 上,而 DSH 可能先吞掉 keydown | 一次按键只做一件事:输入框打开时窗口处理器**不参与**,由 input 自己的 onKeyDown 取消;没有输入框时窗口处理器才退出编辑器 |
|
|
368
|
+
| 浏览器里按截图快捷键什么都不发生 | 浏览器侧本来就没有屏幕权限(DSH 的 `configureSession` 把 display-media 源给空),代码却照常发请求 | 先判运行环境:`runtime === 'web'` 直接给「请移步桌面端」的提示,别发请求;调试用 `localStorage['dsh-ide:screenshot-force']` 显式放开 |
|
|
352
369
|
| 截图里带上了自己的「正在截图…」字 | 抓屏前就把浮层渲染出来了:`screencapture` 会把当前屏幕原样拍下,包括刚画上去的浮层 | **先抓屏再渲染**:抓屏期间 DOM 里不许有任何自己的元素;需要反馈也只能在 Host 返回后显示 |
|
|
370
|
+
| 以为截图里带着「蓝色选框」 | 选框是编辑器画的,导出走的是「底图 + 标注」重绘,实测四边偏蓝像素为 1(画面内容本身);曾误判为要先框选再抓屏,`screencapture -i` 反而让 Windows 没有等价物、框完也没法标注 | 保持「先截整屏、再框选」,选框只存在于编辑器图层,绝不进入导出 |
|
|
353
371
|
| 浮层里按 Esc 没反应 | 编辑器挂在 `shell.overlay`,浮层从不获得焦点,`onKeyDown` 只在该元素内按键才触发 | Esc / ⌘Z 都挂到 `window` 捕获阶段(`globalThis.addEventListener('keydown', handler, true)`),别依赖焦点 |
|
|
354
372
|
| 截图画框后的操作条是白底白字、字体也不对 | 编辑器渲染在 `shell.overlay`,不在 `.iw-root` 里:① 面板组件才注入 `IdeStyles`,浮层没注入 → 全部 `.iw-*` 规则失效,掉回浏览器默认按钮;② `[data-dsh-theme]` 只在面板根节点上 → 浮层拿不到工作区调色板,用宿主 token | 浮层自己 `h(IdeStyles)` + 自带 `data-dsh-theme` 与字体变量;按钮复用 `.iw-btn` 而不是自造一套 |
|
|
355
373
|
| 编辑器里拖拽完全没反应(或选框永远是全屏) | ① `setPointerCapture` 对合成 pointerId 抛错,异常发生在设置拖动状态之前;② 预设了全屏选框,按下点永远"命中选框内部",只能移动不能重画 | ① `setPointerCapture` 包 try/catch,且放在状态设置之后;② **不预设选框**,第一下按下-拖动就是画框;① 的检查同理适用于所有合成指针测试 |
|
|
356
|
-
| 截图附件太大(1 MB 以上) | 直接塞原图:Retina 全屏 5120×2880、PNG 1.2 MB |
|
|
374
|
+
| 截图附件太大(1 MB 以上) | 直接塞原图:Retina 全屏 5120×2880、PNG 1.2 MB | 质量阶梯 80→40 直到 ≤1 MB;仍超标才降分辨率(1 → 1/1.25 → 1/1.5 → 1/2)。**不预设 1080p**:抓屏与导出都保持设备像素 |
|
|
357
375
|
| 想只加一张图却把草稿弄乱 | 直接改输入框内容会动到用户已有的文字/引用/附件 | 合成 `ClipboardEvent('paste')` + `DataTransfer` + `File` 派发给 Lexical 输入框,让 DSH 自己处理粘贴;**不要**写 editor 的 `innerHTML`/`textContent`(`test/screenshot.mjs` 会断言这一点) |
|
|
358
376
|
| 两个插件(代码工作区 + git 窗口)配色不一致 | 各自注入 CSS、各自用 DSH token,主题是本插件私有的 | 把主题做成跨插件约定:`localStorage['dsh-theme']` + `dsh-theme` 事件 + `[data-dsh-theme]` 选择器;对方只读这三样。只在 `.iw-root` 上作用域的选择器无法共享,必须用通用属性 |
|
|
359
377
|
|
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,21 @@
|
|
|
6
6
|
升级方式:DSH →「插件」→ 打开插件的「版本」区 →「检查更新」,或直接卸载后重新安装。
|
|
7
7
|
(`link:` 本地安装不参与版本检查,拉取仓库即可。)
|
|
8
8
|
|
|
9
|
+
## [0.3.4] — 2026-11-19
|
|
10
|
+
|
|
11
|
+
### 修复
|
|
12
|
+
|
|
13
|
+
- **文字框点不进去**:刚放下的文字框,一点它准备输入就会被当成「点了别处」取消,导致永远打不进字。现在按在输入框内的按压不再触发取消。
|
|
14
|
+
- **截图与真实屏幕错位(重影)**:截图是整屏、浮层只盖住窗口,画面原来在窗口里居中显示,于是窗口自己的菜单栏/标题栏在画面里又出现一次、叠成两条。现在按屏幕坐标 1:1 贴回去(`left/top = -(screenX/screenY)`),画面与屏幕逐像素对齐。
|
|
15
|
+
- 文字框的指针坐标改按画布自身的矩形换算,尺寸跟随缩放、落笔与预览一致。
|
|
16
|
+
|
|
17
|
+
### 改动
|
|
18
|
+
|
|
19
|
+
- **按设备像素截屏**:不再压到 1080p / 2560;抓到多少像素就存多少(2K 屏就是 2560×1440)。
|
|
20
|
+
- **导出保原始像素**:先按质量阶梯压到 ≤1 MB,实在压不下去才逐级降分辨率。
|
|
21
|
+
- **浏览器端与桌面端同一套流程**:抓屏由插件宿主完成,浏览器里按快捷键同样能截,去掉「请移步桌面端」的限制。
|
|
22
|
+
- **去掉屏幕上的提示文案**:按快捷键后不再有「按住鼠标左键拖动…」那一行。
|
|
23
|
+
|
|
9
24
|
## [0.3.3] — 2026-11-19
|
|
10
25
|
|
|
11
26
|
### 新增
|
package/README.md
CHANGED
|
@@ -238,11 +238,13 @@ dsh plugin --profile desktop add "git+https://github.com/simons-jiang/dsh-ide-wi
|
|
|
238
238
|
|
|
239
239
|
### 截图
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
桌面端和浏览器端都能用(抓屏由插件在本机完成,不依赖网页的屏幕权限)。
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
按 `⌘⇧S`(Windows `Ctrl+Shift+S`,可在设置里改):
|
|
244
|
+
|
|
245
|
+
1. **先截图**:整屏抓成一张静态图,之后屏幕怎么变都不影响这一张
|
|
246
|
+
2. **再框选**:按住左键拖出要的范围,松开固定;选框下方出现操作条:**矩形 / 文字 / 撤销 | 截图 / 截图并跳转会话**
|
|
247
|
+
- 需要的话还能在框内再裁剪;点「矩形」拖动画框;点「文字」点一下就能用输入法打字(回车落字)
|
|
246
248
|
- **截图**:成品复制到系统剪贴板
|
|
247
249
|
- **截图并跳转会话**:回到对话,只把这一张图贴进输入框,草稿里已有的文字、引用、附件一个都不动
|
|
248
250
|
3. **任何时候按 Esc 都直接退出**(还没框、正拉着框、框完了都算);`⌘Z` 或「撤销」回退最后一笔
|
package/client.js
CHANGED
|
@@ -248,8 +248,6 @@ window.__ModuleLoader__.load({
|
|
|
248
248
|
"shotNoEditor": "Composer not found: the screenshot is on the clipboard, press ⌘V",
|
|
249
249
|
"shotOpenFailed": "Could not open System Settings. Open it manually: Privacy & Security → Screen Recording",
|
|
250
250
|
"paletteActionScreenshot": "Take a screenshot",
|
|
251
|
-
"shotSelectHint": "Press the left button and drag to frame the area; release to finish, Esc cancels.",
|
|
252
|
-
"shotMarkHint": "Drag inside the frame to draw a box, or pick Text and click to type. ⌘Z undoes, Esc closes.",
|
|
253
251
|
"shotTool_rect": "Box",
|
|
254
252
|
"shotTool_text": "Text",
|
|
255
253
|
"shotUndo": "Undo",
|
|
@@ -497,8 +495,6 @@ window.__ModuleLoader__.load({
|
|
|
497
495
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
498
496
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
499
497
|
"paletteActionScreenshot": "截图",
|
|
500
|
-
"shotSelectHint": "按住鼠标左键拖动,框出要截的范围;松开后完成选框,Esc 取消",
|
|
501
|
-
"shotMarkHint": "在选框内拖动可画矩形,选「文字」后点一下输入;⌘Z 撤销,Esc 关闭",
|
|
502
498
|
"shotTool_rect": "矩形",
|
|
503
499
|
"shotTool_text": "文字",
|
|
504
500
|
"shotUndo": "撤销",
|
|
@@ -2002,11 +1998,12 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2002
1998
|
}
|
|
2003
1999
|
.iw-shot-veil--editor {
|
|
2004
2000
|
flex-direction: column;
|
|
2005
|
-
gap:
|
|
2006
|
-
padding:
|
|
2001
|
+
gap: 0;
|
|
2002
|
+
padding: 0;
|
|
2007
2003
|
box-sizing: border-box;
|
|
2008
|
-
background:
|
|
2004
|
+
background: #000;
|
|
2009
2005
|
outline: none;
|
|
2006
|
+
overflow: hidden;
|
|
2010
2007
|
}
|
|
2011
2008
|
.iw-shot {
|
|
2012
2009
|
width: 420px;
|
|
@@ -2117,23 +2114,42 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2117
2114
|
touch-action: none;
|
|
2118
2115
|
cursor: crosshair;
|
|
2119
2116
|
}
|
|
2117
|
+
.iw-shot-frame {
|
|
2118
|
+
position: relative;
|
|
2119
|
+
display: block;
|
|
2120
|
+
flex: 0 0 auto;
|
|
2121
|
+
}
|
|
2120
2122
|
.iw-shot-canvas {
|
|
2121
2123
|
display: block;
|
|
2124
|
+
width: 100%;
|
|
2125
|
+
height: 100%;
|
|
2122
2126
|
border-radius: 4px;
|
|
2123
2127
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
|
|
2124
2128
|
}
|
|
2129
|
+
/* The text box has to sit *on* the picture without covering it: no fill, no
|
|
2130
|
+
chrome, just a hairline so the caret has somewhere to live. Its colour is the
|
|
2131
|
+
annotation colour, so what you type looks like the mark you will get. */
|
|
2125
2132
|
.iw-shot-text {
|
|
2126
2133
|
position: absolute;
|
|
2127
|
-
min-width:
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
border
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
font-
|
|
2134
|
+
min-width: 0;
|
|
2135
|
+
margin: 0;
|
|
2136
|
+
padding: 1px 2px;
|
|
2137
|
+
border: 1px dashed color-mix(in srgb, currentColor 55%, transparent);
|
|
2138
|
+
border-radius: 3px;
|
|
2139
|
+
background: transparent;
|
|
2140
|
+
color: currentColor;
|
|
2141
|
+
font-family: -apple-system, "Segoe UI", "PingFang SC", sans-serif;
|
|
2142
|
+
font-weight: 600;
|
|
2143
|
+
line-height: 1.25;
|
|
2144
|
+
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
|
|
2145
|
+
caret-color: currentColor;
|
|
2135
2146
|
outline: none;
|
|
2136
2147
|
}
|
|
2148
|
+
.iw-shot-text::placeholder {
|
|
2149
|
+
color: currentColor;
|
|
2150
|
+
opacity: 0.45;
|
|
2151
|
+
font-weight: 400;
|
|
2152
|
+
}
|
|
2137
2153
|
|
|
2138
2154
|
`
|
|
2139
2155
|
|
|
@@ -10453,11 +10469,12 @@ const IDE_SHOT_ROUTE = '/dsh-ide/screenshot'
|
|
|
10453
10469
|
const IDE_SHOT_PERMISSION_ROUTE = '/dsh-ide/screen-permission'
|
|
10454
10470
|
|
|
10455
10471
|
/** Long edge of the export; 1920 keeps a 16:9 crop at 1080p. */
|
|
10456
|
-
const IDE_SHOT_EXPORT_EDGE = 1920
|
|
10457
10472
|
/** The export must not exceed this when it becomes a chat attachment. */
|
|
10458
10473
|
const IDE_SHOT_BUDGET = 1024 * 1024
|
|
10459
10474
|
/** JPEG qualities tried in order until the budget is met. */
|
|
10460
10475
|
const IDE_SHOT_QUALITIES = [0.8, 0.7, 0.6, 0.5, 0.4]
|
|
10476
|
+
/** Extra passes that only run when the JPEG still exceeds the budget. */
|
|
10477
|
+
const IDE_SHOT_SHRINK_STEPS = [1, 1.25, 1.5, 2]
|
|
10461
10478
|
|
|
10462
10479
|
/**
|
|
10463
10480
|
* Tools the popup card offers.
|
|
@@ -10559,6 +10576,21 @@ function ideShotFitScale(width, height, boxWidth, boxHeight) {
|
|
|
10559
10576
|
return Math.min(boxWidth / width, boxHeight / height, 1)
|
|
10560
10577
|
}
|
|
10561
10578
|
|
|
10579
|
+
/**
|
|
10580
|
+
* How big to draw the capture.
|
|
10581
|
+
*
|
|
10582
|
+
* The whole picture has to stay visible — cropping it would put the screen's
|
|
10583
|
+
* edges out of reach, and a selection there would silently lose content. So it
|
|
10584
|
+
* is drawn at life size (a Retina capture is 2× the CSS pixels, hence `1/ratio`)
|
|
10585
|
+
* and only scaled down when the window cannot hold it. On a window that is
|
|
10586
|
+
* nearly the screen this fills it edge to edge.
|
|
10587
|
+
*/
|
|
10588
|
+
function ideShotDisplayScale(imageWidth, imageHeight, boxWidth, boxHeight, ratio) {
|
|
10589
|
+
if (!(imageWidth > 0) || !(imageHeight > 0) || !(boxWidth > 0) || !(boxHeight > 0)) return 1
|
|
10590
|
+
const life = 1 / (ratio > 0 ? ratio : 1)
|
|
10591
|
+
return Math.min(life, boxWidth / imageWidth, boxHeight / imageHeight)
|
|
10592
|
+
}
|
|
10593
|
+
|
|
10562
10594
|
/** Keep a rectangle inside `bounds` without changing its size (unless it must shrink). */
|
|
10563
10595
|
function ideShotClampSelection(rect, bounds) {
|
|
10564
10596
|
const width = Math.min(rect.width, bounds.width)
|
|
@@ -10626,12 +10658,10 @@ function ideShotResize(rect, handle, point, bounds) {
|
|
|
10626
10658
|
* within the stage is half of the leftover space; `bounds` is the image size
|
|
10627
10659
|
* (the stage element itself has no width/height of its own).
|
|
10628
10660
|
*/
|
|
10629
|
-
function ideShotPoint(event,
|
|
10630
|
-
const box =
|
|
10631
|
-
const
|
|
10632
|
-
const
|
|
10633
|
-
const x = (event.clientX - box.left - (box.width - drawnWidth) / 2) / scale
|
|
10634
|
-
const y = (event.clientY - box.top - (box.height - drawnHeight) / 2) / scale
|
|
10661
|
+
function ideShotPoint(event, canvas, scale, bounds) {
|
|
10662
|
+
const box = canvas.getBoundingClientRect()
|
|
10663
|
+
const x = (event.clientX - box.left) / scale
|
|
10664
|
+
const y = (event.clientY - box.top) / scale
|
|
10635
10665
|
return {
|
|
10636
10666
|
x: Math.max(0, Math.min(Number.isFinite(x) ? x : 0, bounds.width)),
|
|
10637
10667
|
y: Math.max(0, Math.min(Number.isFinite(y) ? y : 0, bounds.height)),
|
|
@@ -10683,7 +10713,7 @@ function ideShotDrawOp(ctx, op, image) {
|
|
|
10683
10713
|
ctx.stroke()
|
|
10684
10714
|
}
|
|
10685
10715
|
} else if (op.tool === 'text') {
|
|
10686
|
-
ctx.font = `${Math.max(12, stroke
|
|
10716
|
+
ctx.font = `${Math.max(12, Math.round(stroke))}px -apple-system, "Segoe UI", "PingFang SC", sans-serif`
|
|
10687
10717
|
ctx.textBaseline = 'top'
|
|
10688
10718
|
// A dark halo keeps the label readable on light and dark captures alike.
|
|
10689
10719
|
ctx.lineWidth = Math.max(2, stroke / 2)
|
|
@@ -10762,23 +10792,32 @@ function ideShotExport(image, ops, selection) {
|
|
|
10762
10792
|
const sourceY = Math.max(0, Math.round(selection.y))
|
|
10763
10793
|
const sourceWidth = Math.max(1, Math.round(Math.min(selection.width, image.width - sourceX)))
|
|
10764
10794
|
const sourceHeight = Math.max(1, Math.round(Math.min(selection.height, image.height - sourceY)))
|
|
10765
|
-
const
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
|
|
10781
|
-
|
|
10795
|
+
const render = (scale) => {
|
|
10796
|
+
const canvas = document.createElement('canvas')
|
|
10797
|
+
canvas.width = Math.max(1, Math.round(sourceWidth * scale))
|
|
10798
|
+
canvas.height = Math.max(1, Math.round(sourceHeight * scale))
|
|
10799
|
+
const ctx = canvas.getContext('2d')
|
|
10800
|
+
if (ctx === null) return null
|
|
10801
|
+
ctx.drawImage(image, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, canvas.width, canvas.height)
|
|
10802
|
+
ctx.save()
|
|
10803
|
+
ctx.scale(scale, scale)
|
|
10804
|
+
ctx.translate(-sourceX, -sourceY)
|
|
10805
|
+
for (const op of ops) ideShotDrawOp(ctx, op, image)
|
|
10806
|
+
ctx.restore()
|
|
10807
|
+
return canvas
|
|
10808
|
+
}
|
|
10809
|
+
// The crop keeps the screen's own pixels (no forced 1920 edge). Quality is
|
|
10810
|
+
// spent first; the picture is only ever shrunk if it still cannot fit the
|
|
10811
|
+
// attachment budget.
|
|
10812
|
+
let smallest = ''
|
|
10813
|
+
for (const step of IDE_SHOT_SHRINK_STEPS) {
|
|
10814
|
+
const canvas = render(Math.min(1, 1 / step))
|
|
10815
|
+
if (canvas === null) return ''
|
|
10816
|
+
for (const quality of IDE_SHOT_QUALITIES) {
|
|
10817
|
+
const url = canvas.toDataURL('image/jpeg', quality)
|
|
10818
|
+
if (url.length * 0.75 <= IDE_SHOT_BUDGET) return url
|
|
10819
|
+
if (smallest === '' || url.length < smallest.length) smallest = url
|
|
10820
|
+
}
|
|
10782
10821
|
}
|
|
10783
10822
|
return smallest
|
|
10784
10823
|
}
|
|
@@ -10817,7 +10856,14 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
10817
10856
|
const [textAt, setTextAt] = useState(null)
|
|
10818
10857
|
const [textValue, setTextValue] = useState('')
|
|
10819
10858
|
const [scale, setScale] = useState(1)
|
|
10859
|
+
/**
|
|
10860
|
+
* On-screen size of a text mark. The operation stores the same size in image
|
|
10861
|
+
* pixels (divided by the zoom), so what you type is exactly what gets drawn.
|
|
10862
|
+
*/
|
|
10863
|
+
const textFont = Math.max(12, Math.round(width * 2.4 * scale))
|
|
10820
10864
|
const [stageRect, setStageRect] = useState(null)
|
|
10865
|
+
/** Where image pixel (0,0) goes, in viewport coordinates. */
|
|
10866
|
+
const [origin, setOrigin] = useState({ left: 0, top: 0 })
|
|
10821
10867
|
const canvasRef = useRef(null)
|
|
10822
10868
|
const frameRef = useRef(null)
|
|
10823
10869
|
const dragRef = useRef(null)
|
|
@@ -10839,16 +10885,22 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
10839
10885
|
element.src = shot.dataUrl
|
|
10840
10886
|
}, [editing, shot?.dataUrl])
|
|
10841
10887
|
|
|
10842
|
-
|
|
10888
|
+
/**
|
|
10889
|
+
* Put the frozen picture exactly where the screen was.
|
|
10890
|
+
*
|
|
10891
|
+
* The capture is the whole screen in device pixels, and the overlay only
|
|
10892
|
+
* covers this window — so it is drawn 1:1 (`1 / devicePixelRatio`) and moved
|
|
10893
|
+
* up/left by the window's own screen offset. Without that offset the picture
|
|
10894
|
+
* is centred inside the window: its menu bar and title bar land *inside* the
|
|
10895
|
+
* window too, and you see everything doubled.
|
|
10896
|
+
*/
|
|
10843
10897
|
useEffect(() => {
|
|
10844
10898
|
if (image === null) return
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
globalThis.addEventListener?.('resize', fit)
|
|
10851
|
-
return () => globalThis.removeEventListener?.('resize', fit)
|
|
10899
|
+
setScale(1 / (globalThis.devicePixelRatio || 1))
|
|
10900
|
+
setOrigin({
|
|
10901
|
+
left: -(globalThis.screenX ?? globalThis.screenLeft ?? 0),
|
|
10902
|
+
top: -(globalThis.screenY ?? globalThis.screenTop ?? 0),
|
|
10903
|
+
})
|
|
10852
10904
|
}, [image])
|
|
10853
10905
|
|
|
10854
10906
|
// Repaint whenever anything visible changed.
|
|
@@ -10904,10 +10956,18 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
10904
10956
|
* the active tool decides (range adjust, rectangle, or text).
|
|
10905
10957
|
*/
|
|
10906
10958
|
const onPointerDown = (event) => {
|
|
10959
|
+
// Pressing the box itself has to place the caret, not cancel it: the event
|
|
10960
|
+
// bubbles from the <input> up to this stage handler.
|
|
10961
|
+
if (event.target?.closest?.('.iw-shot-text')) return
|
|
10962
|
+
if (textAt !== null) {
|
|
10963
|
+
setTextAt(null)
|
|
10964
|
+
setTextValue('')
|
|
10965
|
+
return
|
|
10966
|
+
}
|
|
10907
10967
|
if (image === null) return
|
|
10908
10968
|
const frame = frameRef.current
|
|
10909
10969
|
if (frame === null) return
|
|
10910
|
-
const point = ideShotPoint(event, frame, scale, bounds)
|
|
10970
|
+
const point = ideShotPoint(event, canvasRef.current ?? frame, scale, bounds)
|
|
10911
10971
|
try {
|
|
10912
10972
|
frame.setPointerCapture?.(event.pointerId)
|
|
10913
10973
|
} catch {
|
|
@@ -10942,7 +11002,7 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
10942
11002
|
const drag = dragRef.current
|
|
10943
11003
|
const frame = frameRef.current
|
|
10944
11004
|
if (frame === null) return
|
|
10945
|
-
const point = ideShotPoint(event, frame, scale, bounds)
|
|
11005
|
+
const point = ideShotPoint(event, canvasRef.current ?? frame, scale, bounds)
|
|
10946
11006
|
if (drag !== null) {
|
|
10947
11007
|
if (drag.mode === 'move') {
|
|
10948
11008
|
const dx = point.x - drag.origin.x
|
|
@@ -11006,7 +11066,9 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
11006
11066
|
setTextAt(null)
|
|
11007
11067
|
return
|
|
11008
11068
|
}
|
|
11009
|
-
|
|
11069
|
+
// `stroke` doubles as the font size for text marks, in image pixels; the
|
|
11070
|
+
// preview is that number times the zoom, so the two agree.
|
|
11071
|
+
setOps((list) => [...list, { tool: 'text', x: textAt.x, y: textAt.y, text: textValue.trim(), color, stroke: Math.max(12, Math.round(textFont / scale)) }])
|
|
11010
11072
|
setTextAt(null)
|
|
11011
11073
|
setTextValue('')
|
|
11012
11074
|
}
|
|
@@ -11024,8 +11086,13 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
11024
11086
|
*/
|
|
11025
11087
|
useEffect(() => {
|
|
11026
11088
|
if (!editing) return undefined
|
|
11089
|
+
/**
|
|
11090
|
+
* Esc leaves the editor — except while a text box is open: then the box
|
|
11091
|
+
* owns the key and closes itself (its own `onKeyDown`), so one press never
|
|
11092
|
+
* does two things. Nothing here stops propagation for that case.
|
|
11093
|
+
*/
|
|
11027
11094
|
const onKey = (event) => {
|
|
11028
|
-
if (event.key !== 'Escape') return
|
|
11095
|
+
if (event.key !== 'Escape' || event.defaultPrevented === true) return
|
|
11029
11096
|
if (textAt !== null) return
|
|
11030
11097
|
event.preventDefault()
|
|
11031
11098
|
event.stopPropagation()
|
|
@@ -11149,7 +11216,6 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
11149
11216
|
}
|
|
11150
11217
|
},
|
|
11151
11218
|
}, [
|
|
11152
|
-
h('div', { key: 'hint', className: 'iw-shot-hint iw-shot-hint--top' }, selection === null || dragging ? tr('shotSelectHint') : tr('shotMarkHint')),
|
|
11153
11219
|
h('div', {
|
|
11154
11220
|
key: 'stage',
|
|
11155
11221
|
ref: frameRef,
|
|
@@ -11159,35 +11225,57 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
|
|
|
11159
11225
|
onPointerUp: onPointerUp,
|
|
11160
11226
|
onPointerCancel: onPointerUp,
|
|
11161
11227
|
}, [
|
|
11162
|
-
h('
|
|
11163
|
-
key: '
|
|
11164
|
-
|
|
11165
|
-
className: 'iw-shot-canvas',
|
|
11228
|
+
h('div', {
|
|
11229
|
+
key: 'frame',
|
|
11230
|
+
className: 'iw-shot-frame',
|
|
11166
11231
|
style: {
|
|
11232
|
+
position: 'absolute',
|
|
11233
|
+
left: `${origin.left}px`,
|
|
11234
|
+
top: `${origin.top}px`,
|
|
11167
11235
|
width: `${Math.round(image.naturalWidth * scale)}px`,
|
|
11168
11236
|
height: `${Math.round(image.naturalHeight * scale)}px`,
|
|
11169
11237
|
},
|
|
11170
|
-
}
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11238
|
+
}, [
|
|
11239
|
+
h('canvas', {
|
|
11240
|
+
key: 'canvas',
|
|
11241
|
+
ref: canvasRef,
|
|
11242
|
+
className: 'iw-shot-canvas',
|
|
11243
|
+
}),
|
|
11244
|
+
textAt === null ? null : h('input', {
|
|
11245
|
+
key: 'text',
|
|
11246
|
+
className: 'iw-shot-text',
|
|
11247
|
+
autoFocus: true,
|
|
11248
|
+
// The stage cancels an open box on pointerdown; a click in the box
|
|
11249
|
+
// itself must not bubble up to it.
|
|
11250
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
11251
|
+
value: textValue,
|
|
11252
|
+
placeholder: tr('shotTextPlaceholder'),
|
|
11253
|
+
style: {
|
|
11254
|
+
left: `${Math.round(textAt.x * scale)}px`,
|
|
11255
|
+
top: `${Math.round(textAt.y * scale) - textFont}px`,
|
|
11256
|
+
color,
|
|
11257
|
+
fontSize: `${textFont}px`,
|
|
11258
|
+
width: `${Math.max(96, Math.round((textValue.length + 1) * textFont * 0.62))}px`,
|
|
11259
|
+
},
|
|
11260
|
+
onChange: (event) => setTextValue(event.target.value),
|
|
11261
|
+
onKeyDown: (event) => {
|
|
11262
|
+
if (event.key === 'Enter') {
|
|
11263
|
+
event.preventDefault()
|
|
11264
|
+
event.stopPropagation()
|
|
11265
|
+
commitText()
|
|
11266
|
+
return
|
|
11267
|
+
}
|
|
11268
|
+
if (event.key === 'Escape') {
|
|
11269
|
+
event.preventDefault()
|
|
11270
|
+
event.stopPropagation()
|
|
11271
|
+
setTextAt(null)
|
|
11272
|
+
setTextValue('')
|
|
11273
|
+
return
|
|
11274
|
+
}
|
|
11275
|
+
event.stopPropagation()
|
|
11276
|
+
},
|
|
11277
|
+
}),
|
|
11278
|
+
]),
|
|
11191
11279
|
]),
|
|
11192
11280
|
card,
|
|
11193
11281
|
]))
|
|
@@ -11509,9 +11597,13 @@ function apply(ctx) {
|
|
|
11509
11597
|
* guard keeps a double press from firing two captures.
|
|
11510
11598
|
*/
|
|
11511
11599
|
let screenshotBusy = false
|
|
11600
|
+
/**
|
|
11601
|
+
* Same flow on the desktop window and in a browser tab: the Host (which runs
|
|
11602
|
+
* on the machine that owns the screen) grabs the picture, the editor frames
|
|
11603
|
+
* it. Nothing here depends on the shell's own screen-capture permission.
|
|
11604
|
+
*/
|
|
11512
11605
|
async function startScreenshot() {
|
|
11513
11606
|
if (screenshotBusy) return
|
|
11514
|
-
if (store.getState().screenshot !== null) return
|
|
11515
11607
|
screenshotBusy = true
|
|
11516
11608
|
try {
|
|
11517
11609
|
const result = await ideShotRequest({})
|
|
@@ -11519,7 +11611,7 @@ function apply(ctx) {
|
|
|
11519
11611
|
store.setScreenshot({ phase: 'error', code: result.code, message: result.message })
|
|
11520
11612
|
return
|
|
11521
11613
|
}
|
|
11522
|
-
// The editor owns the capture from here:
|
|
11614
|
+
// The editor owns the capture from here: frame, marks, export.
|
|
11523
11615
|
store.setScreenshot({ phase: 'editing', ...result.value })
|
|
11524
11616
|
} finally {
|
|
11525
11617
|
screenshotBusy = false
|
|
@@ -11622,6 +11714,8 @@ function apply(ctx) {
|
|
|
11622
11714
|
{ id: 'jump', labelKey: 'paletteActionJump', run: () => store.setJumpEnabled(!store.getState().jumpEnabled) },
|
|
11623
11715
|
{ id: 'closeTabs', labelKey: 'paletteActionCloseTabs', run: () => store.closeAllTabs() },
|
|
11624
11716
|
{ id: 'back', labelKey: 'paletteActionBack', run: () => backToChat() },
|
|
11717
|
+
// Kept in the list on every runtime: in a browser the entry explains why the
|
|
11718
|
+
// feature needs the desktop app instead of silently doing nothing.
|
|
11625
11719
|
{ id: 'screenshot', labelKey: 'paletteActionScreenshot', run: () => { void startScreenshot() } },
|
|
11626
11720
|
{ id: 'licenseRelogin', labelKey: 'paletteActionLicenseRelogin', run: () => { void reloginLicense() } },
|
|
11627
11721
|
{ id: 'diagnostics', labelKey: 'paletteActionDiagnostics', run: () => { void exportDiagnostics() } },
|
package/index.js
CHANGED
|
@@ -866,7 +866,8 @@ const IDE_SCREENSHOT_MAX_BYTES = 1024 * 1024
|
|
|
866
866
|
* Bigger than the final 1080p export: the user crops a region, and cropping a
|
|
867
867
|
* 1080p capture would leave a blurry result.
|
|
868
868
|
*/
|
|
869
|
-
|
|
869
|
+
/** `null`: keep the capture at the screen's real pixel size. */
|
|
870
|
+
const IDE_SCREENSHOT_EDIT_EDGE = null
|
|
870
871
|
/** JPEG quality ladder: the first result under the budget wins. */
|
|
871
872
|
const IDE_SCREENSHOT_QUALITIES = [80, 70, 60, 50]
|
|
872
873
|
|
|
@@ -926,22 +927,20 @@ export async function captureScreen(payload) {
|
|
|
926
927
|
}
|
|
927
928
|
return { path: existing, copied: true, bytes: 0, dataUrl: '' }
|
|
928
929
|
}
|
|
930
|
+
|
|
931
|
+
// One capture path for both runtimes: grab the whole screen, then let the
|
|
932
|
+
// editor frame it. The Host runs on the machine that owns the screen, so this
|
|
933
|
+
// works from a browser tab as well as from the desktop window.
|
|
929
934
|
const target = join(tmpdir(), `dsh-ide-shot-${Date.now()}.png`)
|
|
930
935
|
const { command, args } = platform.screenshotCommand(target)
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
bytes = statSync(target).size
|
|
936
|
-
} catch {
|
|
937
|
-
bytes = 0
|
|
938
|
-
}
|
|
939
|
-
if (code !== 0 || bytes === 0) {
|
|
940
|
-
if (screenshotLooksPermissionDenied(output)) {
|
|
941
|
-
throw new RouteError(403, 'no-screen-permission', output.trim() || 'screen recording is not permitted')
|
|
936
|
+
const attempt = await runProcess(command, args, 20000)
|
|
937
|
+
if (attempt.code !== 0) {
|
|
938
|
+
if (screenshotLooksPermissionDenied(attempt.output)) {
|
|
939
|
+
throw new RouteError(403, 'no-screen-permission', attempt.output.trim() || 'screen recording is not permitted')
|
|
942
940
|
}
|
|
943
|
-
throw new RouteError(500, 'capture-failed', output.trim() || `screenshot exited ${code}`)
|
|
941
|
+
throw new RouteError(500, 'capture-failed', attempt.output.trim() || `screenshot exited ${attempt.code}`)
|
|
944
942
|
}
|
|
943
|
+
|
|
945
944
|
if (payload?.copy === true) {
|
|
946
945
|
const clipboard = platform.clipboardImageCommand(target)
|
|
947
946
|
const copied = await runProcess(clipboard.command, clipboard.args, 20000)
|
|
@@ -951,7 +950,8 @@ export async function captureScreen(payload) {
|
|
|
951
950
|
}
|
|
952
951
|
// A raw screen is far too big for a chat attachment: shrink it before it is
|
|
953
952
|
// ever shown or pasted, and keep only the small file on disk.
|
|
954
|
-
|
|
953
|
+
// Native device pixels: the editor displays 1:1 and the crop keeps its detail.
|
|
954
|
+
const optimized = await optimizeScreenshot(target, null)
|
|
955
955
|
try {
|
|
956
956
|
rmSync(target, { force: true })
|
|
957
957
|
} catch {
|
|
@@ -962,12 +962,8 @@ export async function captureScreen(payload) {
|
|
|
962
962
|
}
|
|
963
963
|
const mime = /\.jpe?g$/i.test(optimized.path) ? 'image/jpeg' : 'image/png'
|
|
964
964
|
const dataUrl = `data:${mime};base64,${readFileSync(optimized.path).toString('base64')}`
|
|
965
|
-
logEvent('info', 'screenshot', 'captured', {
|
|
966
|
-
|
|
967
|
-
quality: optimized.quality,
|
|
968
|
-
path: optimized.path,
|
|
969
|
-
})
|
|
970
|
-
// The temp file stays for "只截图" (the notice shows the path).
|
|
965
|
+
logEvent('info', 'screenshot', 'captured', { bytes: optimized.bytes, quality: optimized.quality, path: optimized.path })
|
|
966
|
+
// Two facts the editor needs: the file to keep for "只截图", and the picture.
|
|
971
967
|
return { path: optimized.path, bytes: optimized.bytes, quality: optimized.quality, dataUrl }
|
|
972
968
|
}
|
|
973
969
|
|
package/locale/en.json
CHANGED
|
@@ -242,8 +242,6 @@
|
|
|
242
242
|
"shotNoEditor": "Composer not found: the screenshot is on the clipboard, press ⌘V",
|
|
243
243
|
"shotOpenFailed": "Could not open System Settings. Open it manually: Privacy & Security → Screen Recording",
|
|
244
244
|
"paletteActionScreenshot": "Take a screenshot",
|
|
245
|
-
"shotSelectHint": "Press the left button and drag to frame the area; release to finish, Esc cancels.",
|
|
246
|
-
"shotMarkHint": "Drag inside the frame to draw a box, or pick Text and click to type. ⌘Z undoes, Esc closes.",
|
|
247
245
|
"shotTool_rect": "Box",
|
|
248
246
|
"shotTool_text": "Text",
|
|
249
247
|
"shotUndo": "Undo",
|
package/locale/zh.json
CHANGED
|
@@ -242,8 +242,6 @@
|
|
|
242
242
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
243
243
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
244
244
|
"paletteActionScreenshot": "截图",
|
|
245
|
-
"shotSelectHint": "按住鼠标左键拖动,框出要截的范围;松开后完成选框,Esc 取消",
|
|
246
|
-
"shotMarkHint": "在选框内拖动可画矩形,选「文字」后点一下输入;⌘Z 撤销,Esc 关闭",
|
|
247
245
|
"shotTool_rect": "矩形",
|
|
248
246
|
"shotTool_text": "文字",
|
|
249
247
|
"shotUndo": "撤销",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ide-window",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "IDEA-style code workspace for DeepSeek Harness: a centre panel with a workspace file tree, editor tabs and live-updating source, while the left navigation column hides.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"icon": "icon.svg",
|
package/platform/contract.js
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* @property {(path: string) => boolean} needsShell `spawn` needs `shell: true`
|
|
31
31
|
* @property {(path: string) => {command: string, args: string[]}} screenshotCommand
|
|
32
32
|
* Capture the whole screen into that PNG with an OS built-in tool.
|
|
33
|
+
|
|
33
34
|
* @property {(input: string, output: string, quality: number, longEdge: number) => {command: string, args: string[]}} imageOptimizeCommand
|
|
34
35
|
* Shrink that PNG to a JPEG whose long edge is `longEdge` (1920 = 1080p on a
|
|
35
36
|
* 16:9 screen; the editor keeps a larger capture to crop from), at `quality`.
|
package/platform/macos.js
CHANGED
|
@@ -32,10 +32,12 @@ export const macPlatform = {
|
|
|
32
32
|
screenshotCommand: (path) => ({ command: 'screencapture', args: ['-x', '-t', 'png', String(path ?? '')] }),
|
|
33
33
|
// `sips` ships with macOS: `-Z` fits the long edge and `-s formatOptions` is
|
|
34
34
|
// the JPEG quality. A Retina capture is 5120×2880; 1080p is plenty for chat.
|
|
35
|
+
// No `-Z` when the caller wants the capture at its native device pixels: the
|
|
36
|
+
// editor shows it 1:1 and the crop is exported as-is.
|
|
35
37
|
imageOptimizeCommand: (input, output, quality, longEdge) => ({
|
|
36
38
|
command: 'sips',
|
|
37
39
|
args: [
|
|
38
|
-
'-Z', String(longEdge
|
|
40
|
+
...(longEdge > 0 ? ['-Z', String(longEdge)] : []),
|
|
39
41
|
'-s', 'format', 'jpeg',
|
|
40
42
|
'-s', 'formatOptions', String(quality),
|
|
41
43
|
String(input ?? ''),
|
package/platform/windows.js
CHANGED
|
@@ -74,12 +74,13 @@ function windowsOptimizeScript(input, output, quality, longEdge) {
|
|
|
74
74
|
const source = String(input ?? '').replace(/'/g, "''")
|
|
75
75
|
const target = String(output ?? '').replace(/'/g, "''")
|
|
76
76
|
const level = Math.min(100, Math.max(10, Number.isFinite(quality) ? quality : 80))
|
|
77
|
-
|
|
77
|
+
// `null` / 0 = keep the capture at its native size (no resize step).
|
|
78
|
+
const edge = Number.isFinite(longEdge) && longEdge > 0 ? Math.round(longEdge) : 0
|
|
78
79
|
return [
|
|
79
80
|
'Add-Type -AssemblyName System.Drawing',
|
|
80
81
|
`$source = [System.Drawing.Image]::FromFile('${source}')`,
|
|
81
82
|
'$long = [Math]::Max($source.Width, $source.Height)',
|
|
82
|
-
`$scale = [Math]::Min(1.0, ${edge} / $long)`,
|
|
83
|
+
`$scale = ${edge > 0 ? `[Math]::Min(1.0, ${edge} / $long)` : '1.0'}`,
|
|
83
84
|
'$width = [int][Math]::Round($source.Width * $scale)',
|
|
84
85
|
'$height = [int][Math]::Round($source.Height * $scale)',
|
|
85
86
|
'$bitmap = New-Object System.Drawing.Bitmap $width, $height',
|