dsh-ris-ide 1.7.0 → 1.7.1
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 +3 -3
- package/lib/client.js +729 -77
- package/lib/index.js +1091 -49
- package/lib/standalone/window.html +89 -14
- package/package.json +1 -1
- package/skills/dsh-ris-ide-debug/SKILL.md +2 -2
- package/test/client-viewer.test.mjs +297 -29
- package/test/clipboard.test.mjs +254 -0
- package/test/host-tail.test.mjs +136 -21
- package/test/windows.test.mjs +198 -0
package/lib/client.js
CHANGED
|
@@ -269,6 +269,35 @@ window.__ModuleLoader__.load({
|
|
|
269
269
|
var retryTimer = null
|
|
270
270
|
var retryDelay = 3000
|
|
271
271
|
var failures = 0
|
|
272
|
+
/**
|
|
273
|
+
* True once a stream broke. A `dsh web` restart closes every EventSource, so
|
|
274
|
+
* the panes paint their retrying banners; the next successful open means the
|
|
275
|
+
* host is back and those banners are stale.
|
|
276
|
+
*/
|
|
277
|
+
var hadFailure = false
|
|
278
|
+
/** Panes that want to know when the host came back after an outage. */
|
|
279
|
+
var recoveryHandlers = new Set()
|
|
280
|
+
/**
|
|
281
|
+
* Tell every pane the host is reachable again so it can drop its error banner
|
|
282
|
+
* and re-read. Without this a successful background refresh could still leave
|
|
283
|
+
* the red retrying line on screen forever.
|
|
284
|
+
*/
|
|
285
|
+
function announceRecovery() {
|
|
286
|
+
recoveryHandlers.forEach(function (handler) {
|
|
287
|
+
try {
|
|
288
|
+
handler()
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error('[dsh-ris-ide] recovery handler failed', error)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
try {
|
|
294
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
|
|
295
|
+
window.dispatchEvent(new CustomEvent('dsh-ris-ide:host-recovered'))
|
|
296
|
+
}
|
|
297
|
+
} catch {
|
|
298
|
+
// No DOM (tests/SSR): the handler set is the whole contract.
|
|
299
|
+
}
|
|
300
|
+
}
|
|
272
301
|
function closeSource() {
|
|
273
302
|
if (source === null) return
|
|
274
303
|
try { source.close() } catch { /* already closed */ }
|
|
@@ -315,17 +344,30 @@ window.__ModuleLoader__.load({
|
|
|
315
344
|
if (tail !== undefined) url.searchParams.set('tail', tail)
|
|
316
345
|
if (tailBytes !== undefined) url.searchParams.set('bytes', String(tailBytes))
|
|
317
346
|
if (debugPath !== undefined) url.searchParams.set('path', debugPath)
|
|
347
|
+
// The standalone window's stream is also its REGISTRATION (`/windows`): the
|
|
348
|
+
// page never stops being a window, and after a `dsh web` restart it
|
|
349
|
+
// reconnects and re-registers by itself.
|
|
350
|
+
if (typeof window !== 'undefined' && window.__dshRisIdeWindow === true) {
|
|
351
|
+
url.searchParams.set('window', '1')
|
|
352
|
+
if (typeof window.__dshRisIdeWindowName === 'string' && window.__dshRisIdeWindowName !== '') {
|
|
353
|
+
url.searchParams.set('wname', window.__dshRisIdeWindowName)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
318
356
|
source = new EventSource(url.href)
|
|
319
357
|
source.addEventListener('open', function () {
|
|
358
|
+
var recovered = hadFailure === true
|
|
359
|
+
hadFailure = false
|
|
320
360
|
failures = 0
|
|
321
361
|
retryDelay = 3000
|
|
322
362
|
notifyOpen()
|
|
363
|
+
if (recovered === true) announceRecovery()
|
|
323
364
|
})
|
|
324
365
|
source.onerror = function () {
|
|
325
366
|
// EventSource retries by itself; tell subscribers so a panel that needs a
|
|
326
367
|
// fallback can start its own poll after repeated failures. A HARD failure
|
|
327
368
|
// (400/404, readyState 2) never heals: stop reconnecting so a stale
|
|
328
369
|
// session cannot keep hammering the host forever.
|
|
370
|
+
hadFailure = true
|
|
329
371
|
failures += 1
|
|
330
372
|
var readyState = source !== null ? source.readyState : 2
|
|
331
373
|
// Only a HARD failure (400/404, readyState 2) needs our own retry: the
|
|
@@ -413,6 +455,18 @@ window.__ModuleLoader__.load({
|
|
|
413
455
|
* @param {{topics: string[], sessionId?: string, cwd?: string, handlers: object, onOpen?: Function}} sub - the subscription.
|
|
414
456
|
* @returns {Function} unsubscribe.
|
|
415
457
|
*/
|
|
458
|
+
/**
|
|
459
|
+
* Run `handler` whenever the stream comes back after an outage (that is:
|
|
460
|
+
* `dsh web` restarted, or the network blinked). Panes use this to clear the
|
|
461
|
+
* error banner they painted while the host was gone and re-read their data.
|
|
462
|
+
* @param {function(): void} handler - called once per recovery.
|
|
463
|
+
* @returns {function(): void} unsubscribe.
|
|
464
|
+
*/
|
|
465
|
+
hostRecovered: function (handler) {
|
|
466
|
+
if (typeof handler !== 'function') return function () {}
|
|
467
|
+
recoveryHandlers.add(handler)
|
|
468
|
+
return function () { recoveryHandlers.delete(handler) }
|
|
469
|
+
},
|
|
416
470
|
subscribe: function (sub) {
|
|
417
471
|
subscribers.add(sub)
|
|
418
472
|
schedule()
|
|
@@ -1869,6 +1923,25 @@ window.__ModuleLoader__.load({
|
|
|
1869
1923
|
return out
|
|
1870
1924
|
}
|
|
1871
1925
|
|
|
1926
|
+
/**
|
|
1927
|
+
* Run `callback` every time the host becomes reachable again after an outage.
|
|
1928
|
+
*
|
|
1929
|
+
* The callback is kept in a ref, so a component can pass a fresh closure on
|
|
1930
|
+
* every render without resubscribing. `dsh web` restarting is the case this
|
|
1931
|
+
* exists for: the panes keep their last error banner, and nothing else tells
|
|
1932
|
+
* them the host is back.
|
|
1933
|
+
* @param {function(): void} callback - re-read whatever the pane shows.
|
|
1934
|
+
*/
|
|
1935
|
+
function useHostRecovery(callback) {
|
|
1936
|
+
var ref = useRef(callback)
|
|
1937
|
+
ref.current = callback
|
|
1938
|
+
useEffect(function () {
|
|
1939
|
+
var hub = risStreamHub()
|
|
1940
|
+
var off = hub.hostRecovered(function () { ref.current() })
|
|
1941
|
+
return function () { off() }
|
|
1942
|
+
}, [])
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1872
1945
|
function LogTail(props) {
|
|
1873
1946
|
// Inside the IDE this follows the A−/A+ ratio for its chrome; the sidebar's
|
|
1874
1947
|
// own `.log` viewer passes nothing and stays at the default set.
|
|
@@ -1948,6 +2021,9 @@ window.__ModuleLoader__.load({
|
|
|
1948
2021
|
busyRef.current = false
|
|
1949
2022
|
}
|
|
1950
2023
|
}, [path, sessionId, cwd])
|
|
2024
|
+
// The host going away used to leave the tail's error line up forever: after a
|
|
2025
|
+
// `dsh web` restart the pane is still mounted and nothing asks it to retry.
|
|
2026
|
+
useHostRecovery(function () { void refresh() })
|
|
1951
2027
|
|
|
1952
2028
|
// Tail only while this viewer is actually on screen. The sidebar keeps every
|
|
1953
2029
|
// open tab mounted, so without this guard each hidden `.log` viewer kept
|
|
@@ -2840,7 +2916,7 @@ window.__ModuleLoader__.load({
|
|
|
2840
2916
|
}
|
|
2841
2917
|
|
|
2842
2918
|
/** Deleted entries park here so Ctrl+Z can bring them back. */
|
|
2843
|
-
var TREE_TRASH_DIR = '.dsh-ris-ide
|
|
2919
|
+
var TREE_TRASH_DIR = '.dsh-ris-ide/trash'
|
|
2844
2920
|
|
|
2845
2921
|
/** The workspace's undo trash directory (created on first delete). */
|
|
2846
2922
|
function trashDirFor(root) {
|
|
@@ -3015,8 +3091,8 @@ window.__ModuleLoader__.load({
|
|
|
3015
3091
|
{
|
|
3016
3092
|
title: '配置',
|
|
3017
3093
|
rows: [
|
|
3018
|
-
{ keys: '📄 / ⚙', desc: '在控制台标题栏:📄 打开 .dsh-ris-ide.json,⚙ 按当前扫描结果生成/更新(你改过的字段与自定义程序保留)' },
|
|
3019
|
-
{ keys: '.dsh-ris-ide.json', desc: '在工作区根,是隐藏文件——文件树和检索里都看不到,用 📄 打开;defaults.jvmArgs 与每个程序的 jvmArgs / startCommand 都写这里' },
|
|
3094
|
+
{ keys: '📄 / ⚙', desc: '在控制台标题栏:📄 打开 .dsh-ris-ide/config.json,⚙ 按当前扫描结果生成/更新(你改过的字段与自定义程序保留)' },
|
|
3095
|
+
{ keys: '.dsh-ris-ide/config.json', desc: '在工作区根,是隐藏文件——文件树和检索里都看不到,用 📄 打开;defaults.jvmArgs 与每个程序的 jvmArgs / startCommand 都写这里' },
|
|
3020
3096
|
{ keys: '生效时间', desc: '保存后约 3 秒被读取;jvmArgs 改动要重启该程序才生效' },
|
|
3021
3097
|
],
|
|
3022
3098
|
},
|
|
@@ -3076,6 +3152,22 @@ window.__ModuleLoader__.load({
|
|
|
3076
3152
|
return cut === -1 ? value : value.slice(cut + 1)
|
|
3077
3153
|
}
|
|
3078
3154
|
|
|
3155
|
+
/**
|
|
3156
|
+
* Whether a DOM node is a text field that owns the paste gesture.
|
|
3157
|
+
*
|
|
3158
|
+
* The tree's Ctrl+V used to preventDefault() for EVERY paste while its own
|
|
3159
|
+
* clipboard was non-empty, which stole the keystroke from the editor and from
|
|
3160
|
+
* the OS clipboard. Text entries keep their native paste instead.
|
|
3161
|
+
* @param {EventTarget|null|undefined} node - the keydown/paste target.
|
|
3162
|
+
* @returns {boolean} true for input/textarea/select/contenteditable.
|
|
3163
|
+
*/
|
|
3164
|
+
function isTextEntry(node) {
|
|
3165
|
+
if (node === null || node === undefined || node.nodeType !== 1) return false
|
|
3166
|
+
var tag = String(node.tagName || '').toUpperCase()
|
|
3167
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true
|
|
3168
|
+
return node.isContentEditable === true
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3079
3171
|
/**
|
|
3080
3172
|
* Name of a duplicated copy, keeping the extension: `A.java` → `A - 副本.java`,
|
|
3081
3173
|
* `Makefile` → `Makefile - 副本`, a folder `pkg` → `pkg - 副本`.
|
|
@@ -3471,7 +3563,7 @@ window.__ModuleLoader__.load({
|
|
|
3471
3563
|
function heapHint(program) {
|
|
3472
3564
|
var args = program !== null && program !== undefined && Array.isArray(program.jvmArgs) ? program.jvmArgs : []
|
|
3473
3565
|
if (args.length > 0) return ''
|
|
3474
|
-
return ' · 未配置 jvmArgs:JVM 最大堆默认≈内存/4,多开时建议在 .dsh-ris-ide.json 设 defaults.jvmArgs(如 ["-Xmx768m"])'
|
|
3566
|
+
return ' · 未配置 jvmArgs:JVM 最大堆默认≈内存/4,多开时建议在 .dsh-ris-ide/config.json 设 defaults.jvmArgs(如 ["-Xmx768m"])'
|
|
3475
3567
|
}
|
|
3476
3568
|
|
|
3477
3569
|
/**
|
|
@@ -3781,11 +3873,13 @@ window.__ModuleLoader__.load({
|
|
|
3781
3873
|
// A poll whose signature changed can still describe the SAME rows
|
|
3782
3874
|
// (gitignored churn, file content). Keep the old array, skip the render.
|
|
3783
3875
|
if (sameTreeEntries(levelsRef.current[path], listing.entries)) {
|
|
3784
|
-
|
|
3876
|
+
// A successful read proves the banner is stale, background or not:
|
|
3877
|
+
// keeping it up after `dsh web` came back was the bug.
|
|
3878
|
+
setError(undefined)
|
|
3785
3879
|
return true
|
|
3786
3880
|
}
|
|
3787
3881
|
setLevels(function (prev) { var next = Object.assign({}, prev); next[path] = listing.entries; return next })
|
|
3788
|
-
|
|
3882
|
+
setError(undefined)
|
|
3789
3883
|
if (listing.degraded === true) setDegraded(true)
|
|
3790
3884
|
return true
|
|
3791
3885
|
} catch (problem) {
|
|
@@ -4050,6 +4144,10 @@ window.__ModuleLoader__.load({
|
|
|
4050
4144
|
var treeRefreshTimersRef = useRef({})
|
|
4051
4145
|
/** A tree frame arrived while the page was hidden: reload once on return. */
|
|
4052
4146
|
var treeDirtyRef = useRef(false)
|
|
4147
|
+
/** When the last `paste` event reached the tree (ms). The Ctrl+V keydown
|
|
4148
|
+
* cannot see the OS clipboard, so it waits one beat for this and only falls
|
|
4149
|
+
* back to the tree's own clipboard when no paste event arrived at all. */
|
|
4150
|
+
var pasteAtRef = useRef(0)
|
|
4053
4151
|
|
|
4054
4152
|
/** The parent folder of a path (the tree only needs string maths). */
|
|
4055
4153
|
function parentOf(path) {
|
|
@@ -4220,6 +4318,10 @@ window.__ModuleLoader__.load({
|
|
|
4220
4318
|
var paths = [activeRoot].concat(Object.keys(expanded).filter(function (path) { return expanded[path] === true }))
|
|
4221
4319
|
for (var index = 0; index < paths.length; index += 1) await loadLevel(paths[index], true)
|
|
4222
4320
|
}
|
|
4321
|
+
// `dsh web` restarting breaks the SSE stream and leaves the red retrying
|
|
4322
|
+
// banner up. The host is back when the stream reopens: clear the banner and
|
|
4323
|
+
// re-read the level on screen instead of waiting for the next poll tick.
|
|
4324
|
+
useHostRecovery(function () { setError(undefined); void recoverTree() })
|
|
4223
4325
|
// While an error is on screen, keep retrying by itself: stopping dsh used to
|
|
4224
4326
|
// leave a dead "重试" banner that survived the host coming back.
|
|
4225
4327
|
useEffect(function () {
|
|
@@ -4488,6 +4590,42 @@ window.__ModuleLoader__.load({
|
|
|
4488
4590
|
if (items.length === 0) return
|
|
4489
4591
|
setClipboard({ mode: mode, items: items })
|
|
4490
4592
|
notify((mode === 'copy' ? '已复制 ' : '已剪切 ') + (items.length > 1 ? items.length + ' 项' : '「' + items[0].name + '」'))
|
|
4593
|
+
// The tree's own Ctrl+V reads the in-memory clipboard; ALSO publishing the
|
|
4594
|
+
// same list to the OS clipboard is what lets the file manager paste it out.
|
|
4595
|
+
void publishSystemClipboard(items, mode)
|
|
4596
|
+
}
|
|
4597
|
+
|
|
4598
|
+
/**
|
|
4599
|
+
* Best-effort mirror of a tree copy onto the SYSTEM clipboard.
|
|
4600
|
+
*
|
|
4601
|
+
* A failure here must NOT fail the copy: the internal clipboard already holds
|
|
4602
|
+
* the entries, so the tree keeps working — only "paste outside the IDE" is
|
|
4603
|
+
* lost. When the Host has no backend at all (a Linux desktop without
|
|
4604
|
+
* xclip/wl-copy), fall back to the paths as TEXT, which a terminal or a text
|
|
4605
|
+
* field still accepts.
|
|
4606
|
+
* @param {Array<{path: string, isDir?: boolean, name?: string}>} items - the copied entries.
|
|
4607
|
+
* @param {'copy'|'cut'} mode - cut asks the OS for a MOVE intent.
|
|
4608
|
+
* @returns {Promise<void>} resolves either way; never rejects.
|
|
4609
|
+
*/
|
|
4610
|
+
async function publishSystemClipboard(items, mode) {
|
|
4611
|
+
try {
|
|
4612
|
+
await fsClipboardFiles(scope, items, mode === 'cut')
|
|
4613
|
+
return
|
|
4614
|
+
} catch (problem) {
|
|
4615
|
+
var code = problem !== null && problem !== undefined && typeof problem.code === 'string' ? problem.code : ''
|
|
4616
|
+
if (code === 'unsupported') {
|
|
4617
|
+
// No OS clipboard backend on this machine at all: a text list is still
|
|
4618
|
+
// better than nothing, and it cannot move any file.
|
|
4619
|
+
try {
|
|
4620
|
+
await navigator.clipboard.writeText(items.map(function (item) { return item.path }).join('\n'))
|
|
4621
|
+
} catch (denied) { /* the tree copy still stands */ }
|
|
4622
|
+
return
|
|
4623
|
+
}
|
|
4624
|
+
// Staging refused (too large / host failure). Saying nothing and falling
|
|
4625
|
+
// back to "the paths as text" would look like success while the files
|
|
4626
|
+
// never left the tree — report it instead.
|
|
4627
|
+
notify('没能放到系统剪贴板:' + messageOf(problem))
|
|
4628
|
+
}
|
|
4491
4629
|
}
|
|
4492
4630
|
|
|
4493
4631
|
/** Whether a failed host call was the "target exists" collision. */
|
|
@@ -4589,6 +4727,11 @@ window.__ModuleLoader__.load({
|
|
|
4589
4727
|
* Resolve a parked batch collision: 覆盖 replaces the existing names,
|
|
4590
4728
|
* 生成副本 suffixes them (`… 副本`, `… 副本(2)`). Every created/deleted path is
|
|
4591
4729
|
* folded into ONE undo entry.
|
|
4730
|
+
*
|
|
4731
|
+
* Two kinds of batch reach this card: tree entries (copy/cut, `item.path`)
|
|
4732
|
+
* and OS-pasted files (`external: true` — a `File` blob or an outside path,
|
|
4733
|
+
* so they are re-sent through `/fs/upload` / `/fs/import` instead of a
|
|
4734
|
+
* host-side copy).
|
|
4592
4735
|
* @param {string} policy - `'overwrite'` | `'copy'`.
|
|
4593
4736
|
*/
|
|
4594
4737
|
async function resolveBatchConflict(policy) {
|
|
@@ -4602,6 +4745,20 @@ window.__ModuleLoader__.load({
|
|
|
4602
4745
|
var failures = []
|
|
4603
4746
|
for (var index = 0; index < pending.items.length; index += 1) {
|
|
4604
4747
|
var item = pending.items[index]
|
|
4748
|
+
if (pending.external === true) {
|
|
4749
|
+
try {
|
|
4750
|
+
if (policy === 'overwrite') {
|
|
4751
|
+
created.push(await importOne(item, pending.dir, item.name, true))
|
|
4752
|
+
} else {
|
|
4753
|
+
var placedExternal = await importOneWithCopyName(item, pending.dir)
|
|
4754
|
+
created.push(placedExternal.path)
|
|
4755
|
+
if (placedExternal.renamed === true) renamed.push(placedExternal.name)
|
|
4756
|
+
}
|
|
4757
|
+
} catch (problem) {
|
|
4758
|
+
failures.push(item.name + '(' + messageOf(problem) + ')')
|
|
4759
|
+
}
|
|
4760
|
+
continue
|
|
4761
|
+
}
|
|
4605
4762
|
var leaf = fileBaseName(item.path)
|
|
4606
4763
|
try {
|
|
4607
4764
|
if (policy === 'overwrite') {
|
|
@@ -4622,15 +4779,16 @@ window.__ModuleLoader__.load({
|
|
|
4622
4779
|
}
|
|
4623
4780
|
}
|
|
4624
4781
|
if (created.length > 0) {
|
|
4625
|
-
var
|
|
4782
|
+
var external = pending.external === true
|
|
4783
|
+
var note = external ? '导入 ' : pending.mode === 'cut' ? '移动 ' : '粘贴 '
|
|
4626
4784
|
rememberUndo(note + created.length + ' 项', async function () {
|
|
4627
4785
|
for (var undo = created.length - 1; undo >= 0; undo -= 1) {
|
|
4628
|
-
if (pending.mode === 'cut') await fsMoveEntry(scope, created[undo], parentOf(origins[undo]), fileBaseName(origins[undo]))
|
|
4786
|
+
if (pending.mode === 'cut' && external !== true) await fsMoveEntry(scope, created[undo], parentOf(origins[undo]), fileBaseName(origins[undo]))
|
|
4629
4787
|
else await fsRemoveEntry(scope, created[undo], true)
|
|
4630
4788
|
}
|
|
4631
4789
|
for (var scan = 0; scan < touched.length; scan += 1) await refreshLevel(touched[scan])
|
|
4632
4790
|
})
|
|
4633
|
-
if (pending.mode === 'cut') setClipboard(null)
|
|
4791
|
+
if (external !== true && pending.mode === 'cut') setClipboard(null)
|
|
4634
4792
|
setExpanded(function (prev) { var next = Object.assign({}, prev); next[pending.dir] = true; return next })
|
|
4635
4793
|
setSelectedPaths(created.slice())
|
|
4636
4794
|
setSelectedPath(created[created.length - 1])
|
|
@@ -4638,8 +4796,11 @@ window.__ModuleLoader__.load({
|
|
|
4638
4796
|
for (var refresh = 0; refresh < touched.length; refresh += 1) await refreshLevel(touched[refresh])
|
|
4639
4797
|
if (renamed.length > 0 || failures.length > 0) notifyCollisionCopies(renamed, failures)
|
|
4640
4798
|
if (created.length > 0) {
|
|
4641
|
-
|
|
4642
|
-
|
|
4799
|
+
var done = pending.external === true
|
|
4800
|
+
? '已导入 ' + created.length + ' 个文件'
|
|
4801
|
+
: (pending.mode === 'cut' ? '已移动 ' : '已粘贴 ') + created.length + ' 项'
|
|
4802
|
+
var undone = '撤销这次' + (pending.external === true ? '导入' : pending.mode === 'cut' ? '移动' : '粘贴') + '(也可 Ctrl+Z)'
|
|
4803
|
+
notifyWithAction(done, undoAction(undone))
|
|
4643
4804
|
}
|
|
4644
4805
|
}
|
|
4645
4806
|
|
|
@@ -4759,7 +4920,7 @@ window.__ModuleLoader__.load({
|
|
|
4759
4920
|
} else if (source.kind === 'file') {
|
|
4760
4921
|
await fsUpload(scope, dir, name, source.file, replace)
|
|
4761
4922
|
} else {
|
|
4762
|
-
await fsImportPath(scope,
|
|
4923
|
+
await fsImportPath(scope, source.path, dir, name, replace)
|
|
4763
4924
|
}
|
|
4764
4925
|
} catch (problem) {
|
|
4765
4926
|
if (isExistsProblem(problem)) {
|
|
@@ -4798,53 +4959,274 @@ window.__ModuleLoader__.load({
|
|
|
4798
4959
|
await runPaste({ kind: 'clipboard' }, dirPath, undefined)
|
|
4799
4960
|
}
|
|
4800
4961
|
|
|
4962
|
+
/**
|
|
4963
|
+
* Put ONE OS-pasted source into `dir`: a `File` blob goes up as raw bytes,
|
|
4964
|
+
* an outside path goes through `/fs/import`.
|
|
4965
|
+
* @param {{kind:'file'|'path', file?:File, path?:string, name:string}} source - one pasted item.
|
|
4966
|
+
* @param {string} dir - absolute destination directory.
|
|
4967
|
+
* @param {string} name - leaf name to write.
|
|
4968
|
+
* @param {boolean} [overwrite] - replace an existing entry.
|
|
4969
|
+
* @returns {Promise<string>} the created absolute path.
|
|
4970
|
+
*/
|
|
4971
|
+
async function importOne(source, dir, name, overwrite) {
|
|
4972
|
+
var trimmedDir = dir.replace(/[\\/]+$/, '')
|
|
4973
|
+
if (source.kind === 'file') await fsUpload(scope, trimmedDir, name, source.file, overwrite === true)
|
|
4974
|
+
else await fsImportPath(scope, source.path, trimmedDir, name, overwrite === true)
|
|
4975
|
+
return trimmedDir + '/' + name
|
|
4976
|
+
}
|
|
4977
|
+
|
|
4978
|
+
/**
|
|
4979
|
+
* Put one OS-pasted source down WITHOUT colliding: retry as `… 副本`,
|
|
4980
|
+
* `… 副本(2)`, … exactly like a batch tree paste (see {@link collisionCopyName}).
|
|
4981
|
+
* @param {{kind:'file'|'path', name:string}} source - one pasted item.
|
|
4982
|
+
* @param {string} dir - absolute destination directory.
|
|
4983
|
+
* @returns {Promise<{path:string, name:string, renamed:boolean}>} where it landed.
|
|
4984
|
+
*/
|
|
4985
|
+
async function importOneWithCopyName(source, dir) {
|
|
4986
|
+
var attempt = 0
|
|
4987
|
+
while (attempt < 60) {
|
|
4988
|
+
var name = attempt === 0 ? source.name : collisionCopyName(source.name, false, attempt)
|
|
4989
|
+
try {
|
|
4990
|
+
return { path: await importOne(source, dir, name, false), name: name, renamed: attempt > 0 }
|
|
4991
|
+
} catch (problem) {
|
|
4992
|
+
if (!isExistsProblem(problem)) throw problem
|
|
4993
|
+
attempt += 1
|
|
4994
|
+
}
|
|
4995
|
+
}
|
|
4996
|
+
throw new Error('同名条目太多,换个目标目录再试')
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4801
4999
|
/**
|
|
4802
5000
|
* Import OS-clipboard content (a `paste` with no tree clipboard): `File`
|
|
4803
5001
|
* blobs go up as raw bytes, `file://`/path text goes through `/fs/import`.
|
|
4804
|
-
*
|
|
4805
|
-
*
|
|
5002
|
+
*
|
|
5003
|
+
* ONE pasted file keeps the single-file behavior: a collision opens the
|
|
5004
|
+
* 粘贴为 card (改名 / 覆盖). SEVERAL files must never stop on a collision —
|
|
5005
|
+
* the loop used to `break` there, so every file AFTER the first existing
|
|
5006
|
+
* name was silently dropped (copy three files into a folder that already
|
|
5007
|
+
* holds one of them and only part of the batch arrived). A batch therefore
|
|
5008
|
+
* collects the colliding names and parks the same 覆盖 / 生成副本 card a
|
|
5009
|
+
* batch tree paste uses; the rest of the batch is imported right away.
|
|
4806
5010
|
* @param {string} dir - absolute destination directory.
|
|
4807
5011
|
* @param {File[]} files - pasted blobs (may be empty).
|
|
4808
5012
|
* @param {string[]} paths - parseClipboardPaths() result (may be empty).
|
|
4809
5013
|
*/
|
|
4810
5014
|
async function importExternal(dir, files, paths) {
|
|
4811
|
-
var
|
|
4812
|
-
var
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5015
|
+
var trimmedDir = dir.replace(/[\\/]+$/, '')
|
|
5016
|
+
var sources = []
|
|
5017
|
+
var seen = {}
|
|
5018
|
+
for (var index = 0; index < files.length; index += 1) {
|
|
5019
|
+
var file = files[index]
|
|
5020
|
+
var fileName = String(file !== null && file !== undefined && file.name !== undefined ? file.name : '')
|
|
5021
|
+
if (fileName === '' || seen[fileName] === true) continue
|
|
5022
|
+
seen[fileName] = true
|
|
5023
|
+
sources.push({ kind: 'file', file: file, name: fileName })
|
|
5024
|
+
}
|
|
5025
|
+
for (var scan = 0; scan < paths.length; scan += 1) {
|
|
5026
|
+
var leaf = fileBaseName(paths[scan])
|
|
5027
|
+
if (leaf === '' || seen[leaf] === true) continue
|
|
5028
|
+
seen[leaf] = true
|
|
5029
|
+
sources.push({ kind: 'path', path: paths[scan], name: leaf })
|
|
5030
|
+
}
|
|
5031
|
+
if (sources.length === 0) return
|
|
5032
|
+
var created = []
|
|
5033
|
+
var conflicts = []
|
|
5034
|
+
var failures = []
|
|
5035
|
+
for (var cursor = 0; cursor < sources.length; cursor += 1) {
|
|
5036
|
+
var source = sources[cursor]
|
|
5037
|
+
try {
|
|
5038
|
+
created.push(await importOne(source, trimmedDir, source.name, false))
|
|
5039
|
+
} catch (problem) {
|
|
5040
|
+
if (!isExistsProblem(problem)) { failures.push(source.name + '(' + messageOf(problem) + ')'); continue }
|
|
5041
|
+
if (sources.length === 1) {
|
|
5042
|
+
// A single pasted file: the collision is a choice, not a batch.
|
|
5043
|
+
parkPasteName(source, trimmedDir, source.name)
|
|
5044
|
+
return
|
|
5045
|
+
}
|
|
5046
|
+
conflicts.push(source)
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
setExpanded(function (prev) { var next = Object.assign({}, prev); next[trimmedDir] = true; return next })
|
|
5050
|
+
if (conflicts.length > 0) {
|
|
5051
|
+
// The unresolved names (and the undo entry for the whole batch) belong to
|
|
5052
|
+
// the card's 覆盖 / 生成副本 resolution. The files that DID land are already
|
|
5053
|
+
// on disk, so the listing is refreshed here: cancelling the card must not
|
|
5054
|
+
// leave them invisible until the next manual refresh.
|
|
5055
|
+
await refreshLevel(trimmedDir)
|
|
5056
|
+
setBatchConflict({
|
|
5057
|
+
mode: 'copy', dir: trimmedDir, items: conflicts, created: created,
|
|
5058
|
+
origins: [], touched: [trimmedDir], external: true,
|
|
5059
|
+
})
|
|
5060
|
+
if (failures.length > 0) notify(failures.length + ' 项失败:' + failures[0])
|
|
5061
|
+
return
|
|
5062
|
+
}
|
|
5063
|
+
await refreshLevel(trimmedDir)
|
|
5064
|
+
if (created.length > 0) {
|
|
5065
|
+
setSelectedPaths(created.slice())
|
|
5066
|
+
setSelectedPath(created[created.length - 1])
|
|
5067
|
+
rememberUndo('导入 ' + created.length + ' 项', async function () {
|
|
5068
|
+
for (var undo = created.length - 1; undo >= 0; undo -= 1) await fsRemoveEntry(scope, created[undo], true)
|
|
5069
|
+
await refreshLevel(trimmedDir)
|
|
5070
|
+
})
|
|
4820
5071
|
}
|
|
4821
|
-
|
|
5072
|
+
var messages = []
|
|
5073
|
+
if (created.length > 0) messages.push('已导入 ' + created.length + ' 个文件')
|
|
5074
|
+
if (failures.length > 0) messages.push(failures.length + ' 项失败:' + failures[0])
|
|
5075
|
+
if (messages.length > 0) notify(messages.join(';'))
|
|
4822
5076
|
}
|
|
4823
5077
|
|
|
4824
5078
|
/**
|
|
4825
5079
|
* The tree list's `paste` handler. The tree only prevents the browser's
|
|
4826
5080
|
* default paste when it actually imports something: an ordinary text paste
|
|
4827
5081
|
* still behaves like a text paste.
|
|
5082
|
+
*
|
|
5083
|
+
* `files` and the URI list are read TOGETHER: some desktops hand over only
|
|
5084
|
+
* `text/uri-list` (no `File` blobs), and a clipboard can carry both — reading
|
|
5085
|
+
* just one half is how a multi-file copy lost the files it did not deliver
|
|
5086
|
+
* as blobs. Names seen on both halves are de-duplicated in
|
|
5087
|
+
* {@link importExternal}.
|
|
4828
5088
|
* @param {ClipboardEvent} event - paste event on the focused tree.
|
|
4829
5089
|
*/
|
|
4830
5090
|
function handleTreePaste(event) {
|
|
4831
5091
|
var transfer = event.clipboardData
|
|
4832
5092
|
if (transfer === null || transfer === undefined) return
|
|
5093
|
+
pasteAtRef.current = Date.now()
|
|
4833
5094
|
var files = []
|
|
4834
5095
|
try { files = Array.prototype.slice.call(transfer.files || []) } catch { files = [] }
|
|
4835
|
-
var dir = pasteTargetDir()
|
|
4836
|
-
if (files.length > 0) {
|
|
4837
|
-
event.preventDefault()
|
|
4838
|
-
void importExternal(dir, files, [])
|
|
4839
|
-
return
|
|
4840
|
-
}
|
|
4841
5096
|
var text = ''
|
|
4842
5097
|
try { text = transfer.getData('text/uri-list') || '' } catch { text = '' }
|
|
4843
5098
|
if (text.trim() === '') { try { text = transfer.getData('text/plain') || '' } catch { text = '' } }
|
|
4844
|
-
var paths = parseClipboardPaths(text)
|
|
4845
|
-
|
|
5099
|
+
var paths = text.trim() === '' ? [] : parseClipboardPaths(text)
|
|
5100
|
+
// The tree handles the gesture either way: it owns the destination.
|
|
4846
5101
|
event.preventDefault()
|
|
4847
|
-
|
|
5102
|
+
if (files.length > 0 || paths.length > 0) {
|
|
5103
|
+
void pasteTreePayload(files, paths)
|
|
5104
|
+
return
|
|
5105
|
+
}
|
|
5106
|
+
// EMPTY payload: in WSL a file copy made in Explorer never reaches the page
|
|
5107
|
+
// (the Windows CF_HDROP flavour is not bridged into Chromium), so the Host —
|
|
5108
|
+
// which can read the OS clipboard — has the final say.
|
|
5109
|
+
void pasteFromOsClipboard(text)
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
/**
|
|
5113
|
+
* Paste content the browser DID deliver, deciding where it came from.
|
|
5114
|
+
*
|
|
5115
|
+
* `beginCopy` publishes the tree's selection to the OS clipboard too, so our
|
|
5116
|
+
* own copy comes back looking exactly like external content. Matching names
|
|
5117
|
+
* are not proof on WSL (a desktop copy of same-named files looks identical),
|
|
5118
|
+
* so the Host's reading of the clipboard settles it: the same paths mean the
|
|
5119
|
+
* tree's own copy (keep cut = move); anything else is NEWER content.
|
|
5120
|
+
* @param {File[]} files - blobs from the paste payload.
|
|
5121
|
+
* @param {string[]} paths - paths parsed from the payload text.
|
|
5122
|
+
*/
|
|
5123
|
+
async function pasteTreePayload(files, paths) {
|
|
5124
|
+
if (clipboard !== null && isTreeClipboardCopy(files, paths)) {
|
|
5125
|
+
var host = await readHostClipboard()
|
|
5126
|
+
if (host === null || host.files.length === 0 || samePathList(host.files, clipboardItems())) {
|
|
5127
|
+
void pasteInto(pasteTargetDir())
|
|
5128
|
+
return
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
// Different files than the tree copied — or the same names now pointing at a
|
|
5132
|
+
// NEWER location: the newer clipboard wins, the in-memory copy is dropped.
|
|
5133
|
+
if (clipboard !== null) setClipboard(null)
|
|
5134
|
+
void importExternal(pasteTargetDir(), files, paths)
|
|
5135
|
+
}
|
|
5136
|
+
|
|
5137
|
+
/**
|
|
5138
|
+
* Paste when the payload is empty but the SYSTEM clipboard may still hold a
|
|
5139
|
+
* file list the page cannot see (WSL: Explorer → tree).
|
|
5140
|
+
* @param {string} text - the (usually empty) payload text flavour.
|
|
5141
|
+
*/
|
|
5142
|
+
async function pasteFromOsClipboard(text) {
|
|
5143
|
+
var host = await readHostClipboard()
|
|
5144
|
+
if (host !== null && host.files.length > 0) {
|
|
5145
|
+
if (clipboard !== null && samePathList(host.files, clipboardItems())) {
|
|
5146
|
+
// The tree's own copy is still what the OS clipboard carries.
|
|
5147
|
+
void pasteInto(pasteTargetDir())
|
|
5148
|
+
return
|
|
5149
|
+
}
|
|
5150
|
+
// Fresh files from the OS: a stale in-memory copy must not resurface them.
|
|
5151
|
+
if (clipboard !== null) setClipboard(null)
|
|
5152
|
+
void importExternal(pasteTargetDir(), [], host.files)
|
|
5153
|
+
return
|
|
5154
|
+
}
|
|
5155
|
+
if (clipboard === null) return
|
|
5156
|
+
// Something that is not a file list sits on the OS clipboard (a text copy):
|
|
5157
|
+
// the newer clipboard wins and the stale in-memory one is dropped.
|
|
5158
|
+
var newer = text.trim() !== '' || (host !== null && host.text.trim() !== '')
|
|
5159
|
+
if (newer) {
|
|
5160
|
+
setClipboard(null)
|
|
5161
|
+
notify('系统剪贴板里不是文件,已清空文件树里的旧复制')
|
|
5162
|
+
return
|
|
5163
|
+
}
|
|
5164
|
+
// No paste payload at all and nothing readable: the tree's own clipboard is
|
|
5165
|
+
// the only thing there is to paste.
|
|
5166
|
+
void pasteInto(pasteTargetDir())
|
|
5167
|
+
}
|
|
5168
|
+
|
|
5169
|
+
/**
|
|
5170
|
+
* Whether the OS clipboard holds exactly the entries the tree copied.
|
|
5171
|
+
* Paths are the only identity both sides share.
|
|
5172
|
+
* @param {string[]} files - paths the Host read back from the OS clipboard.
|
|
5173
|
+
* @param {Array<{path: string}>} items - the tree's in-memory clipboard.
|
|
5174
|
+
* @returns {boolean} true when both sides describe the same entries.
|
|
5175
|
+
*/
|
|
5176
|
+
function samePathList(files, items) {
|
|
5177
|
+
if (!Array.isArray(files) || files.length !== items.length) return false
|
|
5178
|
+
var left = files.map(function (path) { return trimTrailingSeparator(path) }).sort()
|
|
5179
|
+
var right = items.map(function (item) { return trimTrailingSeparator(item.path) }).sort()
|
|
5180
|
+
for (var index = 0; index < left.length; index += 1) {
|
|
5181
|
+
if (left[index] !== right[index]) return false
|
|
5182
|
+
}
|
|
5183
|
+
return true
|
|
5184
|
+
}
|
|
5185
|
+
|
|
5186
|
+
/** `/a/b/` → `/a/b`; `/` stays `/` (the root itself is a legal selection). */
|
|
5187
|
+
function trimTrailingSeparator(path) {
|
|
5188
|
+
var value = String(path === null || path === undefined ? '' : path)
|
|
5189
|
+
return value.length > 1 ? value.replace(/[\\/]+$/, '') : value
|
|
5190
|
+
}
|
|
5191
|
+
|
|
5192
|
+
/** The Host's reading of the OS clipboard, or null when it cannot read it. */
|
|
5193
|
+
async function readHostClipboard() {
|
|
5194
|
+
try {
|
|
5195
|
+
var payload = await fsClipboardState(scope)
|
|
5196
|
+
if (payload === null || payload === undefined || payload.ok !== true) return null
|
|
5197
|
+
return {
|
|
5198
|
+
files: Array.isArray(payload.files) ? payload.files : [],
|
|
5199
|
+
text: typeof payload.text === 'string' ? payload.text : '',
|
|
5200
|
+
}
|
|
5201
|
+
} catch (problem) {
|
|
5202
|
+
return null
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5205
|
+
|
|
5206
|
+
/**
|
|
5207
|
+
* Whether a `paste` payload is the tree's own clipboard coming back.
|
|
5208
|
+
*
|
|
5209
|
+
* Compares the name multiset (the only identity a pasted `File` exposes):
|
|
5210
|
+
* same names and same count means the OS clipboard carries the very entries
|
|
5211
|
+
* `beginCopy` published, so the tree can paste them itself.
|
|
5212
|
+
* @param {File[]} files - file blobs the OS clipboard delivered.
|
|
5213
|
+
* @param {string[]} paths - absolute paths read from the clipboard text.
|
|
5214
|
+
* @returns {boolean} true when this paste is our own copy.
|
|
5215
|
+
*/
|
|
5216
|
+
function isTreeClipboardCopy(files, paths) {
|
|
5217
|
+
if (clipboard === null) return false
|
|
5218
|
+
var own = clipboardItems().map(function (item) { return item.name || fileBaseName(item.path) })
|
|
5219
|
+
var seen = files.map(function (file) { return file.name })
|
|
5220
|
+
for (var index = 0; index < paths.length; index += 1) seen.push(fileBaseName(paths[index]))
|
|
5221
|
+
if (own.length === 0 || seen.length !== own.length) return false
|
|
5222
|
+
var bag = {}
|
|
5223
|
+
for (var count = 0; count < own.length; count += 1) bag[own[count]] = (bag[own[count]] || 0) + 1
|
|
5224
|
+
for (var scan = 0; scan < seen.length; scan += 1) {
|
|
5225
|
+
var name = seen[scan]
|
|
5226
|
+
if (bag[name] === undefined || bag[name] === 0) return false
|
|
5227
|
+
bag[name] -= 1
|
|
5228
|
+
}
|
|
5229
|
+
return true
|
|
4848
5230
|
}
|
|
4849
5231
|
/** Remember one inverse operation for Ctrl+Z (bounded: 50 entries). */
|
|
4850
5232
|
function rememberUndo(label, run) {
|
|
@@ -4868,7 +5250,7 @@ window.__ModuleLoader__.load({
|
|
|
4868
5250
|
/**
|
|
4869
5251
|
* Delete one row, or every row of the multi-selection (Del / menu 删除).
|
|
4870
5252
|
*
|
|
4871
|
-
* Delete = move into `<workspace>/.dsh-ris-ide
|
|
5253
|
+
* Delete = move into `<workspace>/.dsh-ris-ide/trash`, so Ctrl+Z restores it
|
|
4872
5254
|
* and nothing is lost by a mis-click. A batch is one compound undo entry.
|
|
4873
5255
|
* @param {Array<object>} entries - entries to remove, primary last.
|
|
4874
5256
|
*/
|
|
@@ -5080,8 +5462,16 @@ window.__ModuleLoader__.load({
|
|
|
5080
5462
|
// leave the key alone so the browser fires `paste` and
|
|
5081
5463
|
// `handleTreePaste` can import it. Only our own clipboard is ours.
|
|
5082
5464
|
if (clipboard === null) return
|
|
5083
|
-
|
|
5084
|
-
|
|
5465
|
+
// A text field owns Ctrl+V: a tree copy must not hijack typing.
|
|
5466
|
+
if (isTextEntry(event.target)) return
|
|
5467
|
+
// The OS clipboard WINS whenever it carries files: only the `paste`
|
|
5468
|
+
// event can see that, so never preventDefault here. An EMPTY OS
|
|
5469
|
+
// clipboard fires no paste at all — wait one beat, then paste ours.
|
|
5470
|
+
var askedAt = Date.now()
|
|
5471
|
+
window.setTimeout(function () {
|
|
5472
|
+
if (pasteAtRef.current >= askedAt) return
|
|
5473
|
+
void pasteInto(pasteTargetDir())
|
|
5474
|
+
}, 150)
|
|
5085
5475
|
}
|
|
5086
5476
|
}
|
|
5087
5477
|
window.addEventListener('keydown', onKey, true)
|
|
@@ -6499,6 +6889,33 @@ window.__ModuleLoader__.load({
|
|
|
6499
6889
|
return h('div', { key: first + index, style: S.largeTextLine, 'data-large-text-line': String(first + index + 1) }, line === '' ? '\u00a0' : line)
|
|
6500
6890
|
})))))
|
|
6501
6891
|
}
|
|
6892
|
+
/**
|
|
6893
|
+
* The ■ stop mark, drawn instead of typed. The character's ink is roughly
|
|
6894
|
+
* half its advance width, so at the control rows' 11–12px it read as a tiny
|
|
6895
|
+
* dot inside the 20px sidebar buttons and the 25px workbench ones (and not
|
|
6896
|
+
* the same size in both). A fixed square is unambiguous at a glance.
|
|
6897
|
+
*
|
|
6898
|
+
* Module scope on purpose: BOTH consoles draw it — the standalone
|
|
6899
|
+
* ProgramWorkbench (rows + batch bar) and the sidebar ProgramsPanel.
|
|
6900
|
+
*/
|
|
6901
|
+
function stopGlyph(size) {
|
|
6902
|
+
var side = typeof size === 'number' ? size : 10
|
|
6903
|
+
return h('span', {
|
|
6904
|
+
'data-glyph': 'stop',
|
|
6905
|
+
style: {
|
|
6906
|
+
// inline-block, not block: a block box carries no line box, so the
|
|
6907
|
+
// typed-glyph buttons around it kept their 20px line and the ■ one
|
|
6908
|
+
// collapsed to the square's own 10px — a visibly shorter border.
|
|
6909
|
+
// inline-block + `middle`, not a block box: a block box carries no
|
|
6910
|
+
// line box, so the typed-glyph buttons around it kept their 20px line
|
|
6911
|
+
// and the ■ one collapsed to the square's own height — a visibly
|
|
6912
|
+
// shorter border. As an inline box it inherits that line again.
|
|
6913
|
+
display: 'inline-block', verticalAlign: 'middle',
|
|
6914
|
+
width: side, height: side, flex: '0 0 auto',
|
|
6915
|
+
background: 'currentColor', borderRadius: 2,
|
|
6916
|
+
},
|
|
6917
|
+
})
|
|
6918
|
+
}
|
|
6502
6919
|
function ProgramWorkbench(props) {
|
|
6503
6920
|
var scope = props ? props.scope : undefined
|
|
6504
6921
|
var tab = props ? props.tab : undefined
|
|
@@ -6736,7 +7153,7 @@ var [ui, setUi] = useState(function () {
|
|
|
6736
7153
|
if (found === undefined) {
|
|
6737
7154
|
// Not in the workspace: it is a dependency class. Ask the host to pull
|
|
6738
7155
|
// it out of a `-sources.jar`, decompile it, or at least javap it (the
|
|
6739
|
-
// files land in `.dsh-ris-ide
|
|
7156
|
+
// files land in `.dsh-ris-ide/cache` and open in the editor).
|
|
6740
7157
|
statusNote('正在获取依赖源码:' + cleaned + '…', 0)
|
|
6741
7158
|
found = await fsDependencySource(scopeRef.current, cleaned, activePathRef === undefined ? activePath : activePathRef.current)
|
|
6742
7159
|
setStatusText('')
|
|
@@ -6843,6 +7260,8 @@ var [ui, setUi] = useState(function () {
|
|
|
6843
7260
|
/** Latest docs map for async loaders (state is closure-stale otherwise). */
|
|
6844
7261
|
var docsRef = useRef(docs)
|
|
6845
7262
|
docsRef.current = docs
|
|
7263
|
+
/** Latest `ensureDoc` (the recovery hook runs outside this render). */
|
|
7264
|
+
var ensureDocRef = useRef(function () {})
|
|
6846
7265
|
/**
|
|
6847
7266
|
* Paths the user chose to force-edit from a large preview: reopening such a
|
|
6848
7267
|
* tab must skip the read-only preview and load the whole file again.
|
|
@@ -7226,6 +7645,23 @@ var [ui, setUi] = useState(function () {
|
|
|
7226
7645
|
return next
|
|
7227
7646
|
})
|
|
7228
7647
|
}
|
|
7648
|
+
// A `dsh web` restart fails every open document once ("读取失败"). The stream
|
|
7649
|
+
// reopening means the host is back: retry only the failed ones (a doc the user
|
|
7650
|
+
// already edited must not be replaced, hence the kind check).
|
|
7651
|
+
useHostRecovery(function () {
|
|
7652
|
+
Object.keys(docsRef.current).forEach(function (path) {
|
|
7653
|
+
var doc = docsRef.current[path]
|
|
7654
|
+
if (doc === null || doc === undefined || doc.kind !== 'error') return
|
|
7655
|
+
setDocs(function (prev) {
|
|
7656
|
+
if (prev[path] === undefined) return prev
|
|
7657
|
+
var next = Object.assign({}, prev)
|
|
7658
|
+
delete next[path]
|
|
7659
|
+
return next
|
|
7660
|
+
})
|
|
7661
|
+
})
|
|
7662
|
+
setTimeout(function () { Object.keys(docsRef.current).forEach(function (path) { ensureDocRef.current(path) }) }, 0)
|
|
7663
|
+
})
|
|
7664
|
+
|
|
7229
7665
|
/** Load one document (idempotent): media kinds need no read at all. */
|
|
7230
7666
|
function ensureDoc(path) {
|
|
7231
7667
|
if (typeof path !== 'string' || path === '') return
|
|
@@ -7295,6 +7731,8 @@ var [ui, setUi] = useState(function () {
|
|
|
7295
7731
|
})
|
|
7296
7732
|
})
|
|
7297
7733
|
}
|
|
7734
|
+
ensureDocRef.current = ensureDoc
|
|
7735
|
+
|
|
7298
7736
|
/**
|
|
7299
7737
|
* Append the next page to a large text preview.
|
|
7300
7738
|
*
|
|
@@ -7491,7 +7929,7 @@ var [ui, setUi] = useState(function () {
|
|
|
7491
7929
|
}
|
|
7492
7930
|
// 📄 in the CONSOLE title bar of the standalone window: that window has no
|
|
7493
7931
|
// DSH sidebar editor, so the panel hands the config path over and it opens
|
|
7494
|
-
// here as an ordinary tab (`.dsh-ris-ide.json` is a hidden dotfile, so the
|
|
7932
|
+
// here as an ordinary tab (`.dsh-ris-ide/config.json` is a hidden dotfile, so the
|
|
7495
7933
|
// tree and the search box cannot reach it).
|
|
7496
7934
|
var configOpenNonce = props.openConfigRequest !== null && typeof props.openConfigRequest === 'object'
|
|
7497
7935
|
&& typeof props.openConfigRequest.nonce === 'number' ? props.openConfigRequest.nonce : 0
|
|
@@ -9417,7 +9855,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9417
9855
|
h('span', { style: S.status }, '已勾选 ' + checkedIds.length + ' 项'),
|
|
9418
9856
|
h('span', { style: S.spacer }),
|
|
9419
9857
|
button('▶', function () { void consoleBatch('start') }, { icon: true, width: 25, start: true, action: 'batch-start', title: '按列表顺序启动勾选的项目(跳过已运行的)' }),
|
|
9420
|
-
button(
|
|
9858
|
+
button(stopGlyph(11), function () { void consoleBatch('stop') }, { icon: true, width: 25, stop: true, action: 'batch-stop', title: '按列表倒序停止勾选的项目(跳过未运行的)' }),
|
|
9421
9859
|
button('清除', function () { setCheckedIds([]) }, { action: 'batch-clear', title: '取消全部勾选' }))
|
|
9422
9860
|
: null
|
|
9423
9861
|
return h('div', { style: S.ideBody },
|
|
@@ -9458,7 +9896,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9458
9896
|
? h('span', { style: S.meta, title: '常驻内存(VmRSS)' }, formatMemory(program.running.rssBytes))
|
|
9459
9897
|
: null,
|
|
9460
9898
|
startable && !alive ? button('▶', function (event) { event.stopPropagation(); void consoleStart(program) }, { icon: true, width: 25, start: true, action: 'console-start', title: '启动 ' + program.name }) : null,
|
|
9461
|
-
alive ? button(
|
|
9899
|
+
alive ? button(stopGlyph(11), function (event) { event.stopPropagation(); void consoleStop(program) }, { icon: true, width: 25, stop: true, action: 'console-stop', title: '停止 ' + program.name }) : null,
|
|
9462
9900
|
// ⟳ shares ▶'s green: both (re)start the program, only ■ is red.
|
|
9463
9901
|
startable ? button('⟳', function (event) { event.stopPropagation(); void consoleRestart(program) }, { icon: true, width: 25, start: true, action: 'console-restart', title: '重启 ' + program.name }) : null,
|
|
9464
9902
|
program.kind === 'spring' ? button(ideBadgeIcon('bug', 'play', 13), function (event) { event.stopPropagation(); void consoleDebug(program) }, { icon: true, width: 25, debug: true, off: ui.busy, action: 'console-debug', title: '调试 ' + program.name }) : null,
|
|
@@ -9723,16 +10161,16 @@ var [ui, setUi] = useState(function () {
|
|
|
9723
10161
|
}))
|
|
9724
10162
|
}
|
|
9725
10163
|
// The config actions belong to the CONSOLE title bar, not the source pane's:
|
|
9726
|
-
// `.dsh-ris-ide.json` describes the PROGRAMS the console lists (the sidebar
|
|
10164
|
+
// `.dsh-ris-ide/config.json` describes the PROGRAMS the console lists (the sidebar
|
|
9727
10165
|
// console already keeps 打开配置/更新配置 there), so the two controls moved
|
|
9728
10166
|
// next to the program list.
|
|
9729
10167
|
var paneConfig = props.onConfig !== null && typeof props.onConfig === 'object' ? props.onConfig : null
|
|
9730
10168
|
var consoleConfigActions = []
|
|
9731
10169
|
if (paneConfig !== null && typeof paneConfig.open === 'function') {
|
|
9732
|
-
consoleConfigActions.push(button('📄', function () { paneConfig.open() }, { key: 'config-open', icon: true, height: 20, action: 'config-open', title: '打开配置文件 .dsh-ris-ide.json(启动参数由你维护)' }))
|
|
10170
|
+
consoleConfigActions.push(button('📄', function () { paneConfig.open() }, { key: 'config-open', icon: true, height: 20, action: 'config-open', title: '打开配置文件 .dsh-ris-ide/config.json(启动参数由你维护)' }))
|
|
9733
10171
|
}
|
|
9734
10172
|
if (paneConfig !== null && typeof paneConfig.generate === 'function') {
|
|
9735
|
-
consoleConfigActions.push(button('⚙', function () { paneConfig.generate() }, { key: 'config-generate', icon: true, height: 20, action: 'config-generate', title: paneConfig.exists === true ? '更新配置:按当前扫描结果同步 .dsh-ris-ide.json(保留你改过的字段)' : '生成配置:把扫描到的程序写成 .dsh-ris-ide.json' }))
|
|
10173
|
+
consoleConfigActions.push(button('⚙', function () { paneConfig.generate() }, { key: 'config-generate', icon: true, height: 20, action: 'config-generate', title: paneConfig.exists === true ? '更新配置:按当前扫描结果同步 .dsh-ris-ide/config.json(保留你改过的字段)' : '生成配置:把扫描到的程序写成 .dsh-ris-ide/config.json' }))
|
|
9736
10174
|
}
|
|
9737
10175
|
paneActions.push(button('⟲', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态)' }))
|
|
9738
10176
|
|
|
@@ -9831,7 +10269,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9831
10269
|
settingsRow('反编译工具 jar(可选)', '如 CFR / Procyon 的 jar;填了就把字节码还原成 .java。', jarInput),
|
|
9832
10270
|
settingsRow('参数(可选)', '默认 {classfile}。', argsInput),
|
|
9833
10271
|
h('div', { style: { fontSize: 11, opacity: 0.5, lineHeight: 1.5, marginTop: 10 } },
|
|
9834
|
-
'缓存:.dsh-ris-ide
|
|
10272
|
+
'缓存:.dsh-ris-ide/cache(已从文件树隐藏)'),
|
|
9835
10273
|
debugSettings.error === '' ? null : h('div', { style: { fontSize: 11, color: '#d9534f', marginTop: 8 } }, debugSettings.error),
|
|
9836
10274
|
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 } },
|
|
9837
10275
|
h('button', { type: 'button', style: S.buttonOn || S.buttonOff, 'data-debug-settings-save': '1', disabled: debugSettings.loading === true, onClick: function () { void saveDebugSettings() } }, debugSettings.loading === true ? '保存中…' : '保存'),
|
|
@@ -10009,7 +10447,7 @@ var [ui, setUi] = useState(function () {
|
|
|
10009
10447
|
? '当前工作区没有可用的 git:文件树本就显示所有文件'
|
|
10010
10448
|
: (treeShowAll === true
|
|
10011
10449
|
? '显示所有文件:开(含 .gitignore 忽略的;点击恢复过滤)'
|
|
10012
|
-
: '.gitignore
|
|
10450
|
+
: '.gitignore 过滤:开(.git 元数据一并隐藏;点击显示所有文件)'),
|
|
10013
10451
|
onClick: toggleTreeFilter,
|
|
10014
10452
|
}, ideIcon(treeShowAll === true ? 'eyeOff' : 'eye', 14)),
|
|
10015
10453
|
maximize)
|
|
@@ -10467,7 +10905,19 @@ var [ui, setUi] = useState(function () {
|
|
|
10467
10905
|
* @returns {Window} the opened window handle.
|
|
10468
10906
|
* @throws {Error} when the environment has no `window.open`, or the popup was blocked.
|
|
10469
10907
|
*/
|
|
10470
|
-
|
|
10908
|
+
/**
|
|
10909
|
+
* Open — or bring forward — the workspace's ONE IDE window.
|
|
10910
|
+
*
|
|
10911
|
+
* A workspace owns exactly one IDE window, so the registry is asked BEFORE any
|
|
10912
|
+
* window exists: its entries come from the windows' own streams, so it stays
|
|
10913
|
+
* right across `dsh web` restarts (the page reconnects) and only goes quiet well
|
|
10914
|
+
* after the window is really gone. Creating a blank window first and closing it
|
|
10915
|
+
* again (the previous approach) flashes a popup that then disappears and still
|
|
10916
|
+
* cannot focus the window the user already has.
|
|
10917
|
+
* @param {{sessionId?: string, cwd?: string, windowCwd?: string, programId?: string, debug?: boolean}} [options] - scope and target.
|
|
10918
|
+
* @returns {Promise<Window|null>} the window when one was opened, else null (an existing window was asked to come forward).
|
|
10919
|
+
*/
|
|
10920
|
+
async function openStandaloneWindow(options) {
|
|
10471
10921
|
var opts = options === null || options === undefined ? {} : options
|
|
10472
10922
|
if (typeof window === 'undefined' || typeof window.open !== 'function') {
|
|
10473
10923
|
throw new Error('当前环境不支持打开独立窗口')
|
|
@@ -10487,6 +10937,16 @@ var [ui, setUi] = useState(function () {
|
|
|
10487
10937
|
// `debug: true` = open on that program AND start its JDWP session, which is
|
|
10488
10938
|
// what the compact panel's 🐞 button promises (the window owns the debug UI).
|
|
10489
10939
|
if (opts.debug === true) url.searchParams.set('debug', '1')
|
|
10940
|
+
var state = await standaloneWindowState(windowName, windowCwd)
|
|
10941
|
+
if (state.exists === true && state.alive === true) {
|
|
10942
|
+
// The browser will not let this document raise a window some OTHER document
|
|
10943
|
+
// opened, and it will not put the old one on top either. The old window does
|
|
10944
|
+
// not have that problem with itself: ask it to close (it was opened by
|
|
10945
|
+
// script, so it may), wait for the lock to be free, then open a fresh one.
|
|
10946
|
+
// Worst case (old window unresponsive) the new window still boots and shows
|
|
10947
|
+
// the single-window notice with a manual choice.
|
|
10948
|
+
await requestStandaloneWindowClose(windowName)
|
|
10949
|
+
}
|
|
10490
10950
|
// A browser cannot be told to "maximize" through window.open features, so ask
|
|
10491
10951
|
// for the screen's work area at 0,0; window.html enforces it once more on load
|
|
10492
10952
|
// in case the opener size is clamped (the OS still allows restore/resize).
|
|
@@ -10501,6 +10961,112 @@ var [ui, setUi] = useState(function () {
|
|
|
10501
10961
|
return handle
|
|
10502
10962
|
}
|
|
10503
10963
|
|
|
10964
|
+
/**
|
|
10965
|
+
* Ask the host whether the workspace's IDE window is there.
|
|
10966
|
+
* @param windowName - the window name to look up.
|
|
10967
|
+
* @param windowCwd - workspace, for the older name-less registrations.
|
|
10968
|
+
* @returns {Promise<{exists: boolean, alive: boolean}>} what the registry knows.
|
|
10969
|
+
*/
|
|
10970
|
+
async function standaloneWindowState(windowName, windowCwd) {
|
|
10971
|
+
var missing = { exists: false, alive: false }
|
|
10972
|
+
try {
|
|
10973
|
+
var url = routeUrl('dsh-ris-ide/windows')
|
|
10974
|
+
if (typeof windowName === 'string' && windowName !== '') url.searchParams.set('name', windowName)
|
|
10975
|
+
if (typeof windowCwd === 'string' && windowCwd !== '') url.searchParams.set('cwd', windowCwd)
|
|
10976
|
+
var signal = typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(1500) : undefined
|
|
10977
|
+
var response = await fetch(url.href, { headers: { accept: 'application/json' }, signal: signal })
|
|
10978
|
+
if (response.ok !== true) return missing
|
|
10979
|
+
var payload = await response.json()
|
|
10980
|
+
var list = payload !== null && payload !== undefined && Array.isArray(payload.windows) ? payload.windows : []
|
|
10981
|
+
if (list.length === 0) return missing
|
|
10982
|
+
return { exists: true, alive: list.some(function (entry) { return entry !== null && entry.alive === true }) }
|
|
10983
|
+
} catch (error) {
|
|
10984
|
+
return missing
|
|
10985
|
+
}
|
|
10986
|
+
}
|
|
10987
|
+
|
|
10988
|
+
/**
|
|
10989
|
+
* Bring the workspace's window to the front through its BroadcastChannel.
|
|
10990
|
+
* @param windowName - the channel the window listens on.
|
|
10991
|
+
* @returns {void}
|
|
10992
|
+
*/
|
|
10993
|
+
/**
|
|
10994
|
+
* Ask the ONE open IDE window of this workspace to close itself.
|
|
10995
|
+
*
|
|
10996
|
+
* The browser will not let us raise a window another document opened, but that
|
|
10997
|
+
* window was opened by `window.open`, so IT may call `window.close()` on itself.
|
|
10998
|
+
* The opener tells it to and waits (briefly) for the host registry to report the
|
|
10999
|
+
* stream gone, i.e. for the single-window lock to be free again.
|
|
11000
|
+
* @param {string} windowName - workspace-derived window/lock name.
|
|
11001
|
+
* @returns {Promise<boolean>} true when the old window closed in time.
|
|
11002
|
+
*/
|
|
11003
|
+
function requestStandaloneWindowClose(windowName) {
|
|
11004
|
+
if (typeof windowName !== 'string' || windowName === '' || typeof BroadcastChannel !== 'function') return Promise.resolve(false)
|
|
11005
|
+
var channel
|
|
11006
|
+
try {
|
|
11007
|
+
channel = new BroadcastChannel(windowName)
|
|
11008
|
+
} catch (error) {
|
|
11009
|
+
return Promise.resolve(false)
|
|
11010
|
+
}
|
|
11011
|
+
var done = false
|
|
11012
|
+
function release() { if (done === true) return; done = true; try { channel.close() } catch (error) { /* already closed */ } }
|
|
11013
|
+
try {
|
|
11014
|
+
channel.postMessage({ type: 'close' })
|
|
11015
|
+
} catch (error) {
|
|
11016
|
+
release()
|
|
11017
|
+
return Promise.resolve(false)
|
|
11018
|
+
}
|
|
11019
|
+
return new Promise(function (resolve) {
|
|
11020
|
+
var deadline = Date.now() + 1500
|
|
11021
|
+
function poll() {
|
|
11022
|
+
void standaloneWindowState(windowName, undefined).then(function (state) {
|
|
11023
|
+
if (state.alive !== true) { release(); resolve(true); return }
|
|
11024
|
+
if (Date.now() >= deadline) { release(); resolve(false); return }
|
|
11025
|
+
setTimeout(poll, 100)
|
|
11026
|
+
}, function () { release(); resolve(false) })
|
|
11027
|
+
}
|
|
11028
|
+
setTimeout(poll, 100)
|
|
11029
|
+
})
|
|
11030
|
+
}
|
|
11031
|
+
|
|
11032
|
+
/**
|
|
11033
|
+
* The standalone window's React root — it owns the scope the panels run on.
|
|
11034
|
+
*
|
|
11035
|
+
* The window's session id comes from the URL, so a window left open across a
|
|
11036
|
+
* `dsh web` restart keeps an id that no longer exists. The host's `hello` frame
|
|
11037
|
+
* carries the session the workspace is really on now; adopt it when this
|
|
11038
|
+
* window's own id is gone (and stay put while it is still live, so a window
|
|
11039
|
+
* opened by THIS dsh keeps the session its titles and logs belong to).
|
|
11040
|
+
* @param {{sessionId: string, cwd: string}} props - scope taken from the URL.
|
|
11041
|
+
* @returns {object} the panel tree.
|
|
11042
|
+
*/
|
|
11043
|
+
function StandaloneWindow(props) {
|
|
11044
|
+
var initial = props.sessionId
|
|
11045
|
+
var scopeState = useState(initial)
|
|
11046
|
+
var sessionId = scopeState[0]
|
|
11047
|
+
var setSessionId = scopeState[1]
|
|
11048
|
+
useEffect(function () {
|
|
11049
|
+
var hub = risStreamHub()
|
|
11050
|
+
return hub.subscribe({
|
|
11051
|
+
topics: ['hello'],
|
|
11052
|
+
handlers: {
|
|
11053
|
+
hello: function (payload) {
|
|
11054
|
+
if (payload === null || payload === undefined || payload.ok !== true) return
|
|
11055
|
+
var session = payload.session !== null && payload.session !== undefined ? payload.session : null
|
|
11056
|
+
var live = session !== null ? session.id : undefined
|
|
11057
|
+
if (typeof live !== 'string' || live === '' || live === sessionId) return
|
|
11058
|
+
var mine = payload.windowSession !== null && payload.windowSession !== undefined ? payload.windowSession : null
|
|
11059
|
+
// Still live: this window belongs to a session that exists, so the
|
|
11060
|
+
// newer session in the same workspace is a DIFFERENT thread — leave it.
|
|
11061
|
+
if (mine !== null && mine.live === true) return
|
|
11062
|
+
setSessionId(live)
|
|
11063
|
+
},
|
|
11064
|
+
},
|
|
11065
|
+
})
|
|
11066
|
+
}, [sessionId, props.cwd])
|
|
11067
|
+
return h(ProgramsPanel, { sessionId: sessionId, cwd: props.cwd, visible: true, compact: false })
|
|
11068
|
+
}
|
|
11069
|
+
|
|
10504
11070
|
/**
|
|
10505
11071
|
* Mount the IDE panel into a plain container, outside DSH's module system.
|
|
10506
11072
|
*
|
|
@@ -10530,9 +11096,15 @@ var [ui, setUi] = useState(function () {
|
|
|
10530
11096
|
var reactDom = require('react-dom/client')
|
|
10531
11097
|
var createRoot = reactDom !== null && reactDom !== undefined ? reactDom.createRoot : undefined
|
|
10532
11098
|
if (typeof createRoot !== 'function') throw new Error('react-dom/client 不可用')
|
|
11099
|
+
if (typeof window !== 'undefined') {
|
|
11100
|
+
// The hub puts these in the stream URL: `window=1` registers this window's
|
|
11101
|
+
// liveness with the host, and the name is what the DSH page looks up before
|
|
11102
|
+
// it opens a second one.
|
|
11103
|
+
window.__dshRisIdeWindowName = typeof opts.windowName === 'string' ? opts.windowName : ''
|
|
11104
|
+
}
|
|
10533
11105
|
var root = createRoot(container)
|
|
10534
11106
|
// The window always shows the FULL IDE (compact is the sidebar's shape).
|
|
10535
|
-
root.render(h(IdeErrorBoundary, null, h(
|
|
11107
|
+
root.render(h(IdeErrorBoundary, null, h(StandaloneWindow, { sessionId: sessionId, cwd: cwd })))
|
|
10536
11108
|
return root
|
|
10537
11109
|
}
|
|
10538
11110
|
|
|
@@ -10584,11 +11156,11 @@ var [ui, setUi] = useState(function () {
|
|
|
10584
11156
|
if (blocked === true) {
|
|
10585
11157
|
return h('span', { style: S.windowButtonError, role: 'status', title: '允许本站弹窗后重试' }, '窗口被拦截')
|
|
10586
11158
|
}
|
|
10587
|
-
function onClick(event) {
|
|
11159
|
+
async function onClick(event) {
|
|
10588
11160
|
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
10589
11161
|
try {
|
|
10590
|
-
var handle = openStandaloneWindow({ sessionId: sessionId })
|
|
10591
|
-
if (handle !== null && typeof handle.focus === 'function') handle.focus()
|
|
11162
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId })
|
|
11163
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
10592
11164
|
} catch (error) {
|
|
10593
11165
|
console.warn('dsh-ris-ide: 独立窗口打开失败:' + messageOf(error))
|
|
10594
11166
|
setBlocked(true)
|
|
@@ -11228,8 +11800,76 @@ var [ui, setUi] = useState(function () {
|
|
|
11228
11800
|
* @param {boolean} [overwrite] - replace an existing entry.
|
|
11229
11801
|
* @returns {Promise<object>} the host payload (`{ok, path, name}`).
|
|
11230
11802
|
*/
|
|
11231
|
-
async function fsImportPath(scope,
|
|
11232
|
-
|
|
11803
|
+
async function fsImportPath(scope, sourcePath, dir, name, overwrite) {
|
|
11804
|
+
// The host reads `from` = SOURCE and `dir` = DESTINATION; keep that order here.
|
|
11805
|
+
return fsOp('import', scope, { from: sourcePath, dir: dir, name: name, overwrite: overwrite === true })
|
|
11806
|
+
}
|
|
11807
|
+
|
|
11808
|
+
/**
|
|
11809
|
+
* `?sessionId&cwd` for the clipboard routes.
|
|
11810
|
+
*
|
|
11811
|
+
* The Host stages a COPY inside the workspace (`<root>/.dsh-ris-ide/stage`), so
|
|
11812
|
+
* both the publish and the read need to know WHICH workspace: the read has to
|
|
11813
|
+
* translate a staged path back to the original one, otherwise Ctrl+C → Ctrl+V
|
|
11814
|
+
* would look like foreign files and import a second copy.
|
|
11815
|
+
* @param {{sessionId?: string, cwd?: string}|undefined} scope - owning session.
|
|
11816
|
+
* @returns {string} a query string, `''` when the scope is unknown.
|
|
11817
|
+
*/
|
|
11818
|
+
function clipboardQuery(scope) {
|
|
11819
|
+
if (scope === null || scope === undefined) return ''
|
|
11820
|
+
var query = []
|
|
11821
|
+
if (typeof scope.sessionId === 'string' && scope.sessionId !== '') query.push('sessionId=' + encodeURIComponent(scope.sessionId))
|
|
11822
|
+
if (typeof scope.cwd === 'string' && scope.cwd !== '') query.push('cwd=' + encodeURIComponent(scope.cwd))
|
|
11823
|
+
return query.length === 0 ? '' : '?' + query.join('&')
|
|
11824
|
+
}
|
|
11825
|
+
|
|
11826
|
+
/**
|
|
11827
|
+
* Publish a file list to the SYSTEM clipboard through the Host.
|
|
11828
|
+
*
|
|
11829
|
+
* A web page cannot do this itself: Chromium refuses `text/uri-list` (and
|
|
11830
|
+
* `x-special/gnome-copied-files`) on `Clipboard.write`, and a synthetic
|
|
11831
|
+
* `copy` event only produces Chrome's private `x-web-custom-data` flavour.
|
|
11832
|
+
* Only the Host can put a real file list (CF_HDROP / `file://` URIs) on the
|
|
11833
|
+
* OS clipboard, so that a file manager can paste the files out of the tree.
|
|
11834
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
11835
|
+
* @param {Array<{path: string}>} items - entries to publish (absolute paths).
|
|
11836
|
+
* @param {boolean} cut - `true` for a MOVE intent, `false` for COPY.
|
|
11837
|
+
* @returns {Promise<{ok: boolean, count?: number, method?: string, staged?: boolean}>} host payload.
|
|
11838
|
+
*/
|
|
11839
|
+
async function fsClipboardFiles(scope, items, cut) {
|
|
11840
|
+
var response = await fetch(routeUrl('dsh-ris-ide/clipboard/files').href + clipboardQuery(scope), {
|
|
11841
|
+
method: 'POST',
|
|
11842
|
+
headers: { 'content-type': 'application/json' },
|
|
11843
|
+
body: JSON.stringify({
|
|
11844
|
+
paths: items.map(function (item) { return item.path }),
|
|
11845
|
+
cut: cut === true,
|
|
11846
|
+
}),
|
|
11847
|
+
})
|
|
11848
|
+
var parsed = await response.json().catch(function () { return null })
|
|
11849
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
11850
|
+
var failure = new Error(parsed !== null && parsed.message !== undefined ? parsed.message : 'HTTP ' + response.status)
|
|
11851
|
+
failure.code = parsed !== null && typeof parsed.code === 'string' ? parsed.code : ''
|
|
11852
|
+
throw failure
|
|
11853
|
+
}
|
|
11854
|
+
return parsed
|
|
11855
|
+
}
|
|
11856
|
+
|
|
11857
|
+
/**
|
|
11858
|
+
* Ask the Host what the SYSTEM clipboard holds (file list + text flavour).
|
|
11859
|
+
*
|
|
11860
|
+
* The page cannot read a file list itself — and on WSL it cannot even tell that
|
|
11861
|
+
* one exists: a copy made in Explorer arrives as an EMPTY paste payload.
|
|
11862
|
+
* @returns {Promise<object>} `{ ok, files, text, method }`.
|
|
11863
|
+
*/
|
|
11864
|
+
async function fsClipboardState(scope) {
|
|
11865
|
+
var response = await fetch(routeUrl('dsh-ris-ide/clipboard/read').href + clipboardQuery(scope), { method: 'GET' })
|
|
11866
|
+
var parsed = await response.json().catch(function () { return null })
|
|
11867
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
11868
|
+
var failure = new Error(parsed !== null && parsed.message !== undefined ? parsed.message : 'HTTP ' + response.status)
|
|
11869
|
+
failure.code = parsed !== null && typeof parsed.code === 'string' ? parsed.code : ''
|
|
11870
|
+
throw failure
|
|
11871
|
+
}
|
|
11872
|
+
return parsed
|
|
11233
11873
|
}
|
|
11234
11874
|
|
|
11235
11875
|
/**
|
|
@@ -12148,6 +12788,10 @@ var [ui, setUi] = useState(function () {
|
|
|
12148
12788
|
}
|
|
12149
12789
|
}, [sessionId, cwd])
|
|
12150
12790
|
|
|
12791
|
+
// After a `dsh web` restart the console keeps its error row ("扫描失败…")
|
|
12792
|
+
// until something re-reads. The stream reopening IS that signal.
|
|
12793
|
+
useHostRecovery(function () { void refresh(false) })
|
|
12794
|
+
|
|
12151
12795
|
/** Console rows stream (fallback: the 3 s poll below). */
|
|
12152
12796
|
var [streamOk, setStreamOk] = useState(function () { return typeof EventSource === 'function' })
|
|
12153
12797
|
useEffect(function () {
|
|
@@ -12343,7 +12987,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12343
12987
|
}
|
|
12344
12988
|
// The standalone window has no DSH right sidebar, so there is no sidebar
|
|
12345
12989
|
// editor to open into: the workbench editor is the only editor there, so
|
|
12346
|
-
// hand the path over and let it open `.dsh-ris-ide.json` as a normal tab
|
|
12990
|
+
// hand the path over and let it open `.dsh-ris-ide/config.json` as a normal tab
|
|
12347
12991
|
// (a hidden dotfile is not reachable from the tree or the search box).
|
|
12348
12992
|
if (panelCtx === null || panelCtx === undefined) {
|
|
12349
12993
|
setOpenConfigRequest(function (previous) {
|
|
@@ -12360,7 +13004,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12360
13004
|
|
|
12361
13005
|
/**
|
|
12362
13006
|
* Config notices the console owes the user: first-run generation, a config
|
|
12363
|
-
* sync, and drift between `.dsh-ris-ide.json` and the current scan. The
|
|
13007
|
+
* sync, and drift between `.dsh-ris-ide/config.json` and the current scan. The
|
|
12364
13008
|
* dismissal signature travels with each item so closing one sticks.
|
|
12365
13009
|
* @returns {Array<{kind: string, signature: string, text: string}>} live notices.
|
|
12366
13010
|
*/
|
|
@@ -12454,14 +13098,17 @@ var [ui, setUi] = useState(function () {
|
|
|
12454
13098
|
/** Open the standalone window on the picked program (or on the workspace). */
|
|
12455
13099
|
function openCompactWindow() {
|
|
12456
13100
|
var picked = compactProgram()
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
13101
|
+
void (async function () {
|
|
13102
|
+
try {
|
|
13103
|
+
// One window per workspace: a second click on ⧉ must focus the IDE the
|
|
13104
|
+
// user already has (the registry knows), never open a twin.
|
|
13105
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: picked !== undefined ? picked.id : undefined })
|
|
13106
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
13107
|
+
else setState(function (prev) { return Object.assign({}, prev, { note: '已切到本工作空间的 IDE 窗口' }) })
|
|
13108
|
+
} catch (error) {
|
|
13109
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
13110
|
+
}
|
|
13111
|
+
})()
|
|
12465
13112
|
}
|
|
12466
13113
|
|
|
12467
13114
|
/** Drag the hairline above the log pane; the height is remembered on release. */
|
|
@@ -12563,7 +13210,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12563
13210
|
type: 'button', style: busy ? S.paneIconOff : S.stopIcon, disabled: busy, 'data-action': 'stop',
|
|
12564
13211
|
title: '停止 ' + program.name,
|
|
12565
13212
|
onClick: function (event) { event.stopPropagation(); void act('stop', program) },
|
|
12566
|
-
}, busy ? '…' :
|
|
13213
|
+
}, busy ? '…' : stopGlyph())
|
|
12567
13214
|
: null,
|
|
12568
13215
|
// Restart is the daily loop after a code change (PM gap #1): it works on
|
|
12569
13216
|
// a running program (stop → start, pidfile released first) and on a
|
|
@@ -12582,11 +13229,13 @@ var [ui, setUi] = useState(function () {
|
|
|
12582
13229
|
title: '在独立窗口里调试 ' + program.name + '(含断点/调用栈/变量)',
|
|
12583
13230
|
onClick: function (event) {
|
|
12584
13231
|
event.stopPropagation()
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
13232
|
+
void (async function () {
|
|
13233
|
+
try {
|
|
13234
|
+
await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: program.id, debug: true })
|
|
13235
|
+
} catch (error) {
|
|
13236
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
13237
|
+
}
|
|
13238
|
+
})()
|
|
12590
13239
|
},
|
|
12591
13240
|
}, ideBadgeIcon('bug', 'play', 13))
|
|
12592
13241
|
: null,
|
|
@@ -12634,7 +13283,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12634
13283
|
configExists === true
|
|
12635
13284
|
? h('button', {
|
|
12636
13285
|
type: 'button', style: S.paneIcon, 'data-action': 'compact-config-open',
|
|
12637
|
-
title: '打开配置文件 .dsh-ris-ide.json(启动参数由你维护)',
|
|
13286
|
+
title: '打开配置文件 .dsh-ris-ide/config.json(启动参数由你维护)',
|
|
12638
13287
|
onClick: openConfig,
|
|
12639
13288
|
}, '📄')
|
|
12640
13289
|
: null,
|
|
@@ -12642,8 +13291,8 @@ var [ui, setUi] = useState(function () {
|
|
|
12642
13291
|
type: 'button', style: busyId === '__config__' ? S.paneIconOff : S.paneIcon,
|
|
12643
13292
|
disabled: busyId === '__config__', 'data-action': 'compact-config-generate',
|
|
12644
13293
|
title: configExists === true
|
|
12645
|
-
? '更新配置:按当前扫描结果同步 .dsh-ris-ide.json(保留你改过的字段)'
|
|
12646
|
-
: '生成配置:把扫描到的程序写成 .dsh-ris-ide.json',
|
|
13294
|
+
? '更新配置:按当前扫描结果同步 .dsh-ris-ide/config.json(保留你改过的字段)'
|
|
13295
|
+
: '生成配置:把扫描到的程序写成 .dsh-ris-ide/config.json',
|
|
12647
13296
|
onClick: function () { generateConfigFile(configExists ? 'update' : undefined) },
|
|
12648
13297
|
}, busyId === '__config__' ? '…' : '⚙'),
|
|
12649
13298
|
h('button', {
|
|
@@ -12692,17 +13341,18 @@ var [ui, setUi] = useState(function () {
|
|
|
12692
13341
|
h('span', { style: S.status }, '已勾选 ' + checkedIds.length + ' 项'),
|
|
12693
13342
|
h('span', { style: S.spacer }),
|
|
12694
13343
|
h('button', {
|
|
12695
|
-
|
|
13344
|
+
// Same tones as the row actions they repeat: ▶/⟳ green, ■ red.
|
|
13345
|
+
type: 'button', style: busyId !== undefined || bulk !== null ? S.paneIconOff : S.startIcon, 'data-action': 'batch-start',
|
|
12696
13346
|
disabled: busyId !== undefined || bulk !== null,
|
|
12697
13347
|
title: '按列表顺序启动勾选的项目(跳过已在运行的)',
|
|
12698
13348
|
onClick: function () { void actMany('start') },
|
|
12699
13349
|
}, bulk !== null && bulk.kind === 'start' ? (bulk.index + 1) + '/' + bulk.total : '▶'),
|
|
12700
13350
|
h('button', {
|
|
12701
|
-
type: 'button', style: S.
|
|
13351
|
+
type: 'button', style: busyId !== undefined || bulk !== null ? S.paneIconOff : S.stopIcon, 'data-action': 'batch-stop',
|
|
12702
13352
|
disabled: busyId !== undefined || bulk !== null,
|
|
12703
13353
|
title: '按列表倒序停止勾选的项目(跳过未运行的)',
|
|
12704
13354
|
onClick: function () { void actMany('stop') },
|
|
12705
|
-
}, bulk !== null && bulk.kind === 'stop' ? (bulk.index + 1) + '/' + bulk.total :
|
|
13355
|
+
}, bulk !== null && bulk.kind === 'stop' ? (bulk.index + 1) + '/' + bulk.total : stopGlyph()),
|
|
12706
13356
|
h('button', {
|
|
12707
13357
|
type: 'button', style: S.paneButton, 'data-action': 'batch-clear',
|
|
12708
13358
|
title: '取消全部勾选',
|
|
@@ -12839,7 +13489,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12839
13489
|
return h('div', { key: program.id, style: S.progRow, 'data-program': program.name, 'data-kind': program.kind },
|
|
12840
13490
|
h('span', { style: alive ? S.instDotOn : S.instDotOff, title: alive ? '运行中' : '未运行' }, '●'),
|
|
12841
13491
|
h('span', { style: S.instName, title: program.dir }, program.name,
|
|
12842
|
-
edited ? h('span', { style: S.editedMark, title: '来自 .dsh-ris-ide.json(可编辑/禁用/改启动参数)' }, '✎') : null),
|
|
13492
|
+
edited ? h('span', { style: S.editedMark, title: '来自 .dsh-ris-ide/config.json(可编辑/禁用/改启动参数)' }, '✎') : null),
|
|
12843
13493
|
h('span', { style: kindStyle, title: program.kind }, kindLabel),
|
|
12844
13494
|
h('span', { style: S.progWhere },
|
|
12845
13495
|
h('span', { style: S.progRel, title: program.dir }, program.relDir),
|
|
@@ -12859,7 +13509,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12859
13509
|
type: 'button', style: busy ? S.stopDisabled : S.stop, disabled: busy, 'data-action': 'stop',
|
|
12860
13510
|
title: '停止 ' + program.name,
|
|
12861
13511
|
onClick: function () { act('stop', program) },
|
|
12862
|
-
}, busy ? '…' :
|
|
13512
|
+
}, busy ? '…' : stopGlyph())
|
|
12863
13513
|
: h('button', { type: 'button', style: S.buttonOff, disabled: true, 'data-action': 'stop' }, '停止'),
|
|
12864
13514
|
program.kind === 'spring'
|
|
12865
13515
|
? h('button', {
|
|
@@ -12892,7 +13542,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12892
13542
|
type: 'button', style: S.button, disabled: busyId === '__config__', 'data-action': 'config',
|
|
12893
13543
|
title: state.config !== undefined && state.config !== null && state.config.exists === true
|
|
12894
13544
|
? '按当前扫描结果更新配置:新增的程序补上、失效的自动条目删掉,你改过的字段与自定义程序保持不动'
|
|
12895
|
-
: '把扫描到的程序与启停参数写成 .dsh-ris-ide.json,之后由你维护',
|
|
13545
|
+
: '把扫描到的程序与启停参数写成 .dsh-ris-ide/config.json,之后由你维护',
|
|
12896
13546
|
onClick: function () {
|
|
12897
13547
|
var exists = state.config !== undefined && state.config !== null && state.config.exists === true
|
|
12898
13548
|
generateConfigFile(exists ? 'update' : undefined)
|
|
@@ -12966,6 +13616,8 @@ var [ui, setUi] = useState(function () {
|
|
|
12966
13616
|
RisIdeWindowAction: RisIdeWindowAction,
|
|
12967
13617
|
openStandaloneWindow: openStandaloneWindow,
|
|
12968
13618
|
mountStandalone: mountStandalone,
|
|
13619
|
+
StandaloneWindow: StandaloneWindow,
|
|
13620
|
+
requestStandaloneWindowClose: requestStandaloneWindowClose,
|
|
12969
13621
|
fetchProgramById: fetchProgramById,
|
|
12970
13622
|
WINDOW_NAME: WINDOW_NAME,
|
|
12971
13623
|
standaloneWindowKey: standaloneWindowKey,
|