dsh-ris-ide 1.7.1 → 1.7.3
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 +29 -2
- package/bin/check-listing.mjs +247 -0
- package/bin/proxy-janitor.mjs +88 -0
- package/lib/client-codemirror.js +110 -66
- package/lib/client.js +1809 -70
- package/lib/index.js +1638 -11
- package/lib/janitor.js +286 -0
- package/lib/proxy.js +1498 -0
- package/lib/redirector.js +2109 -0
- package/package.json +4 -2
- package/skills/dsh-ris-ide-debug/SKILL.md +37 -2
- package/test/client-viewer.test.mjs +622 -6
- package/test/companion.test.mjs +65 -0
- package/test/host-search.test.mjs +125 -1
- package/test/host-tail.test.mjs +95 -1
- package/test/inherit-engine.test.mjs +175 -0
- package/test/install-phase.test.mjs +36 -0
- package/test/janitor.test.mjs +144 -0
- package/test/lifecycle.test.mjs +88 -0
- package/test/proxy-route.test.mjs +599 -0
- package/test/proxy.test.mjs +873 -0
- package/test/redirector.test.mjs +521 -0
package/lib/client.js
CHANGED
|
@@ -179,6 +179,101 @@ window.__ModuleLoader__.load({
|
|
|
179
179
|
return knownWorkspaceCwd()
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The workspace of ONE session, read through the slot's standard `useSessions`
|
|
184
|
+
* hook.
|
|
185
|
+
*
|
|
186
|
+
* Every slot entry receives `useSessions` (the session store) and, inside a
|
|
187
|
+
* session-scoped slot, that session's `sessionId`. Asking the store is the only
|
|
188
|
+
* way to learn the CURRENT session's workspace: `knownWorkspaceCwd()` is
|
|
189
|
+
* whatever the last host answer happened to mention, i.e. possibly the
|
|
190
|
+
* PREVIOUS session's workspace. A missing hook (an older host, the standalone
|
|
191
|
+
* window page, a bare render) or an unknown session answers `undefined`, so
|
|
192
|
+
* callers keep their own fallback.
|
|
193
|
+
* @param {Function|undefined} useSessions - standard slot prop, `useSessions(select)`.
|
|
194
|
+
* @param {string} sessionId - this session's id.
|
|
195
|
+
* @returns {string|undefined} the session's workspace path.
|
|
196
|
+
*/
|
|
197
|
+
function sessionWorkspaceCwd(useSessions, sessionId) {
|
|
198
|
+
if (typeof useSessions !== 'function' || typeof sessionId !== 'string' || sessionId === '') return undefined
|
|
199
|
+
return useSessions(function (state) {
|
|
200
|
+
var rows = state !== null && state !== undefined ? state.byId : undefined
|
|
201
|
+
var row = rows !== null && rows !== undefined && typeof rows === 'object' ? rows[sessionId] : undefined
|
|
202
|
+
var cwd = row !== null && row !== undefined ? row.cwd : undefined
|
|
203
|
+
return typeof cwd === 'string' && cwd !== '' ? cwd : undefined
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Which Session the right Sidebar is drawn for RIGHT NOW, read from the DOM.
|
|
209
|
+
*
|
|
210
|
+
* `keepMounted: true` deliberately keeps a visited tab body alive "through
|
|
211
|
+
* hiding, Session changes and docking", so its props keep the session it was
|
|
212
|
+
* OPENED in. Switching workspace then left the console listing the previous
|
|
213
|
+
* project. DSH already marks the live one for its own focus logic
|
|
214
|
+
* (`data-sidebar-right-session`), and reading that attribute needs no extra
|
|
215
|
+
* plugin dependency and no host round trip.
|
|
216
|
+
* @returns {string|undefined} the live session id, or undefined off-DOM.
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* The Session whose right Sidebar is on screen right now.
|
|
220
|
+
*
|
|
221
|
+
* The tab body outlives Session switches (`keepMounted`), so its injected
|
|
222
|
+
* `sessionId` keeps naming the Session it was opened in. The sidebar marks
|
|
223
|
+
* its DOM with `data-sidebar-right-session`: the panel element carries the
|
|
224
|
+
* live Session, while retained `SessionView` wrappers each carry their own
|
|
225
|
+
* and sit hidden. Taking the first match therefore returns a stale hidden
|
|
226
|
+
* wrapper, so the panel is preferred and visibility is required.
|
|
227
|
+
* @returns the live Session id, or undefined when no sidebar is mounted.
|
|
228
|
+
*/
|
|
229
|
+
function liveSidebarSessionId(origin) {
|
|
230
|
+
if (typeof document === 'undefined') return undefined
|
|
231
|
+
/**
|
|
232
|
+
* Whether the marker sits in what the reader can see right now.
|
|
233
|
+
* @param {Element} node - element carrying `data-sidebar-right-session`.
|
|
234
|
+
* @returns {boolean} true when it is rendered and not inside a hidden tree.
|
|
235
|
+
*/
|
|
236
|
+
function shown(node) {
|
|
237
|
+
if (node.hidden === true) return false
|
|
238
|
+
if (typeof node.closest === 'function' && node.closest('[hidden]') !== null) return false
|
|
239
|
+
if (typeof node.getClientRects === 'function' && node.getClientRects().length === 0) return false
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @param {Element|undefined} node - candidate marker.
|
|
244
|
+
* @returns {string|undefined} its Session id.
|
|
245
|
+
*/
|
|
246
|
+
function valueOf(node) {
|
|
247
|
+
if (node === null || node === undefined || typeof node.getAttribute !== 'function') return undefined
|
|
248
|
+
var value = node.getAttribute('data-sidebar-right-session')
|
|
249
|
+
return typeof value === 'string' && value !== '' ? value : undefined
|
|
250
|
+
}
|
|
251
|
+
// 1. The body's own ancestor, when it is on screen: DSH re-parents a retained
|
|
252
|
+
// tab body into the Session that is showing now, so this is the truth.
|
|
253
|
+
if (origin !== null && origin !== undefined && typeof origin.closest === 'function') {
|
|
254
|
+
var nearest = origin.closest('[data-sidebar-right-session]')
|
|
255
|
+
var nearestId = valueOf(nearest)
|
|
256
|
+
if (nearestId !== undefined && shown(nearest)) return nearestId
|
|
257
|
+
}
|
|
258
|
+
if (typeof document.querySelectorAll !== 'function') return undefined
|
|
259
|
+
// 2. Otherwise the sidebar PANEL element, which always names the live
|
|
260
|
+
// Session, then any other visible marker (a floating pane inside a
|
|
261
|
+
// SessionView). Retained wrappers are hidden, so they never win here.
|
|
262
|
+
var nodes = document.querySelectorAll('[data-sidebar-right-session]')
|
|
263
|
+
var fallback
|
|
264
|
+
for (var i = 0; i < nodes.length; i += 1) {
|
|
265
|
+
var node = nodes[i]
|
|
266
|
+
var value = valueOf(node)
|
|
267
|
+
if (value === undefined) continue
|
|
268
|
+
if (!shown(node)) continue
|
|
269
|
+
if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-sidebar-right-panel')) return value
|
|
270
|
+
if (fallback === undefined) fallback = value
|
|
271
|
+
}
|
|
272
|
+
// 3. Nothing visible (collapsed sidebar): no opinion, the caller keeps its
|
|
273
|
+
// last good answer rather than falling back to the stale injected one.
|
|
274
|
+
return fallback
|
|
275
|
+
}
|
|
276
|
+
|
|
182
277
|
/**
|
|
183
278
|
* The log pane of ONE plugin instance (sidebar console or standalone window)
|
|
184
279
|
* has no idea that another instance just started/debugged a program. A storage
|
|
@@ -1129,6 +1224,16 @@ window.__ModuleLoader__.load({
|
|
|
1129
1224
|
var PREF_FONT_SIZE = 'dsh-ris-ide.fontSize'
|
|
1130
1225
|
/** The theme's mono token first, then what a Linux desktop actually has. */
|
|
1131
1226
|
var MONO_FAMILY = "var(--dsw-font-mono, 'Ubuntu Sans Mono', 'Ubuntu Mono', 'JetBrains Mono', 'Fira Code', 'Noto Sans Mono', 'DejaVu Sans Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace)"
|
|
1227
|
+
/**
|
|
1228
|
+
* The chrome font the IDE window renders with.
|
|
1229
|
+
*
|
|
1230
|
+
* The IDE page defines `--dsw-font-mono` (this theme maps it to a system UI
|
|
1231
|
+
* stack), but the DSH sidebar does not, so a sidebar dialog that repeated the
|
|
1232
|
+
* mono list fell back to a real monospace face and measured wider than the
|
|
1233
|
+
* same dialog in the IDE window — rule rows wrapped only in the sidebar. The
|
|
1234
|
+
* fallback is therefore the stack the token resolves to, not a mono list.
|
|
1235
|
+
*/
|
|
1236
|
+
var CHROME_FAMILY = "var(--dsw-font-mono, system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif)"
|
|
1132
1237
|
|
|
1133
1238
|
var BASE_STYLES = {
|
|
1134
1239
|
root: {
|
|
@@ -1789,6 +1894,1086 @@ window.__ModuleLoader__.load({
|
|
|
1789
1894
|
/** The unscaled set: components outside the IDE (the sidebar's own viewers). */
|
|
1790
1895
|
var S = stylesFor(1)
|
|
1791
1896
|
|
|
1897
|
+
/**
|
|
1898
|
+
* The 「代理」 dialog: the upstream SOCKS address on top, the rule table below.
|
|
1899
|
+
*
|
|
1900
|
+
* Rules are the contract with the engine (`lib/proxy.js`): each row names a
|
|
1901
|
+
* PROGRAM (display only for now), an IP allow-list (`1.1.1.*`, comma lists) and
|
|
1902
|
+
* a PORT allow-list (`5432`, `1000-1010`). An empty host or port cell means
|
|
1903
|
+
* "this axis is unrestricted", which the host route reports back so the table
|
|
1904
|
+
* can colour the row instead of silently allowing the world.
|
|
1905
|
+
*
|
|
1906
|
+
* Editing is local until 保存: the engine keeps its listeners until restarted,
|
|
1907
|
+
* so the dialog says so out loud instead of pretending a save took effect.
|
|
1908
|
+
*/
|
|
1909
|
+
function ProxyDialog(props) {
|
|
1910
|
+
var scope = props && typeof props.scope === 'object' && props.scope !== null ? props.scope : {}
|
|
1911
|
+
var sessionId = typeof scope.sessionId === 'string' ? scope.sessionId : ''
|
|
1912
|
+
var cwd = typeof scope.cwd === 'string' ? scope.cwd : ''
|
|
1913
|
+
var onClose = props && typeof props.onClose === 'function' ? props.onClose : function () {}
|
|
1914
|
+
var [state, setState] = useState({
|
|
1915
|
+
loading: true, error: '', note: '', view: null, draft: null, pickFor: '', pickFilter: '', busy: '',
|
|
1916
|
+
// Auto-save runs on its own flag: a background write must not disable the
|
|
1917
|
+
// 启动/停止 buttons, and it must not look like a manual action either.
|
|
1918
|
+
saving: false,
|
|
1919
|
+
// Command handed back by the redirector action when this route cannot
|
|
1920
|
+
// elevate: it is shown verbatim so the user can paste it in a terminal.
|
|
1921
|
+
redirectorCommand: '',
|
|
1922
|
+
})
|
|
1923
|
+
var [programs, setPrograms] = useState([])
|
|
1924
|
+
var [programsLoaded, setProgramsLoaded] = useState(false)
|
|
1925
|
+
// Two sources for a rule's 程序 field: a process that is running NOW, or a
|
|
1926
|
+
// fixed executable picked from disk (configure it before the program ever
|
|
1927
|
+
// starts, so it is proxied from its first connection).
|
|
1928
|
+
// Three sources for the 程序 field: a process running NOW, a file on this
|
|
1929
|
+
// (Linux/WSL) side, a file on the Windows side. The two file sources are the
|
|
1930
|
+
// only way to configure a program that never runs as a child of this pane.
|
|
1931
|
+
var [pickMode, setPickMode] = useState('running')
|
|
1932
|
+
// ONE tree per dialog, lazily filled: `nodes[path] = {dirs, files, error}`.
|
|
1933
|
+
// Expanding a folder reads just that folder, so a huge drive never has to be
|
|
1934
|
+
// walked up front, and the tree keeps its shape while it grows in place.
|
|
1935
|
+
var [tree, setTree] = useState({ side: 'local', roots: null, nodes: {}, expanded: {}, loading: {}, error: '' })
|
|
1936
|
+
|
|
1937
|
+
/**
|
|
1938
|
+
* Read ONE directory into the tree (roots when `target` is '').
|
|
1939
|
+
*
|
|
1940
|
+
* Called lazily: when a folder is first expanded, and when a side is first
|
|
1941
|
+
* shown. Everything already read stays cached for the life of the dialog, so
|
|
1942
|
+
* collapsing and re-expanding costs nothing.
|
|
1943
|
+
*/
|
|
1944
|
+
function loadTreeDir(target, sideOverride) {
|
|
1945
|
+
var side = typeof sideOverride === 'string' && sideOverride !== '' ? sideOverride : tree.side
|
|
1946
|
+
var key = typeof target === 'string' ? target : ''
|
|
1947
|
+
setTree(function (prev) {
|
|
1948
|
+
var loading = Object.assign({}, prev.loading)
|
|
1949
|
+
loading[key] = true
|
|
1950
|
+
return Object.assign({}, prev, { loading: loading, error: '' })
|
|
1951
|
+
})
|
|
1952
|
+
var url = routeUrl('/dsh-ris-ide/proxy/browse')
|
|
1953
|
+
url.searchParams.set('sessionId', sessionId)
|
|
1954
|
+
if (cwd !== '') url.searchParams.set('cwd', cwd)
|
|
1955
|
+
url.searchParams.set('side', side)
|
|
1956
|
+
if (key !== '') url.searchParams.set('path', key)
|
|
1957
|
+
return fetch(url.href, { headers: { accept: 'application/json' } })
|
|
1958
|
+
.then(function (response) { return response.json() })
|
|
1959
|
+
.then(function (payload) {
|
|
1960
|
+
if (payload.ok !== true) throw new Error(payload.message || '读取目录失败')
|
|
1961
|
+
setTree(function (prev) {
|
|
1962
|
+
var nodes = Object.assign({}, prev.nodes)
|
|
1963
|
+
nodes[payload.path] = { dirs: payload.dirs || [], files: payload.files || [] }
|
|
1964
|
+
var loading = Object.assign({}, prev.loading)
|
|
1965
|
+
delete loading[key]
|
|
1966
|
+
return Object.assign({}, prev, {
|
|
1967
|
+
side: payload.side === 'windows' ? 'windows' : 'local',
|
|
1968
|
+
// The roots are only known from the first answer: they are the quick
|
|
1969
|
+
// entry points (workspace / home / temp / drives).
|
|
1970
|
+
roots: prev.roots === null ? (payload.roots || []) : prev.roots,
|
|
1971
|
+
nodes: nodes,
|
|
1972
|
+
loading: loading,
|
|
1973
|
+
error: '',
|
|
1974
|
+
})
|
|
1975
|
+
})
|
|
1976
|
+
})
|
|
1977
|
+
.catch(function (error) {
|
|
1978
|
+
setTree(function (prev) {
|
|
1979
|
+
var loading = Object.assign({}, prev.loading)
|
|
1980
|
+
delete loading[key]
|
|
1981
|
+
return Object.assign({}, prev, { loading: loading, error: String(error && error.message ? error.message : error) })
|
|
1982
|
+
})
|
|
1983
|
+
})
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/** Toggle a folder open/closed, reading it the first time. */
|
|
1987
|
+
function toggleDir(dir) {
|
|
1988
|
+
var key = dir.path
|
|
1989
|
+
var known = tree.nodes[key]
|
|
1990
|
+
if (known !== undefined && known.dirs.length === 0 && known.files.length === 0) return
|
|
1991
|
+
var open = tree.expanded[key] === true
|
|
1992
|
+
setTree(function (prev) {
|
|
1993
|
+
var expanded = Object.assign({}, prev.expanded)
|
|
1994
|
+
if (open) delete expanded[key]
|
|
1995
|
+
else expanded[key] = true
|
|
1996
|
+
return Object.assign({}, prev, { expanded: expanded })
|
|
1997
|
+
})
|
|
1998
|
+
if (open !== true && tree.nodes[key] === undefined) void loadTreeDir(key)
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
// Fingerprint of the table the form was rendered from: it travels with every
|
|
2002
|
+
// write, so another window's save is detected instead of being overwritten.
|
|
2003
|
+
var revisionRef = useRef('')
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* The editable form shape for one host view.
|
|
2007
|
+
*
|
|
2008
|
+
* Two callers need it: the first read and the 409 reload (another window saved
|
|
2009
|
+
* first). Keeping one mapper means both produce the SAME folded fields, so the
|
|
2010
|
+
* dialog compares like with like when it decides whether a write is needed.
|
|
2011
|
+
*/
|
|
2012
|
+
function draftFromView(payload) {
|
|
2013
|
+
return {
|
|
2014
|
+
socks: {
|
|
2015
|
+
host: payload.socks && payload.socks.host ? payload.socks.host : '',
|
|
2016
|
+
port: payload.socks && payload.socks.port ? String(payload.socks.port) : '',
|
|
2017
|
+
},
|
|
2018
|
+
listenPort: String(payload.listenPort || ''),
|
|
2019
|
+
rules: (Array.isArray(payload.rules) ? payload.rules : []).map(function (rule) {
|
|
2020
|
+
return {
|
|
2021
|
+
id: rule.id, program: rule.program, hosts: rule.hosts || '', ports: rule.ports || '',
|
|
2022
|
+
enabled: rule.enabled === true, shadow: rule.shadow === true, source: rule.source,
|
|
2023
|
+
shadowable: rule.shadowable === true, hostsInvalid: rule.hostsInvalid || [], portsInvalid: rule.portsInvalid || [],
|
|
2024
|
+
socksCapable: rule.socksCapable === true, autoShadow: rule.autoShadow === true, workspace: rule.workspace || '',
|
|
2025
|
+
// Whether the rule's own program is up (started from this row).
|
|
2026
|
+
run: rule.run || null, runLogPath: rule.runLogPath || '',
|
|
2027
|
+
// Host-derived facts, so the row shows what the ENGINE concluded instead
|
|
2028
|
+
// of recomputing it here and drifting from the host's answer.
|
|
2029
|
+
// A starter row: shown, but not written until the user actually changes it.
|
|
2030
|
+
template: rule.template === true,
|
|
2031
|
+
effective: rule.effective === true, ineffectiveReason: String(rule.ineffectiveReason || ''),
|
|
2032
|
+
portsParsed: Array.isArray(rule.portsParsed) ? rule.portsParsed : [],
|
|
2033
|
+
}
|
|
2034
|
+
}),
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
/** Close the dialog, but never throw away a write that is still debounced. */
|
|
2039
|
+
function closeDialog() {
|
|
2040
|
+
flushSave().catch(function () {}).then(function () { onClose() })
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
/** GET the stored rules; `draft` is what the form edits. */
|
|
2044
|
+
function load() {
|
|
2045
|
+
setState(function (prev) { return Object.assign({}, prev, { loading: true, error: '' }) })
|
|
2046
|
+
var url = routeUrl('/dsh-ris-ide/proxy')
|
|
2047
|
+
url.searchParams.set('sessionId', sessionId)
|
|
2048
|
+
if (cwd !== '') url.searchParams.set('cwd', cwd)
|
|
2049
|
+
return fetch(url.href, { headers: { accept: 'application/json' } })
|
|
2050
|
+
.then(function (response) {
|
|
2051
|
+
// A 404 here means the host half of this plugin is older than the
|
|
2052
|
+
// client half (the page reloads from disk, the host only on restart).
|
|
2053
|
+
if (response.ok !== true) throw new Error('读取代理配置失败:HTTP ' + String(response.status) + (response.status === 404 ? '(dsh-ris-ide 宿主未加载该路由,需重启 dsh web)' : ''))
|
|
2054
|
+
return response.json()
|
|
2055
|
+
})
|
|
2056
|
+
.then(function (payload) {
|
|
2057
|
+
if (payload.ok !== true) throw new Error(payload.message || '读取代理配置失败')
|
|
2058
|
+
var draft = draftFromView(payload)
|
|
2059
|
+
// Remember the loaded shape: without this the first render would look
|
|
2060
|
+
// like an edit and auto-save the file back onto itself.
|
|
2061
|
+
savedSignature.current = draftSignature(draft)
|
|
2062
|
+
revisionRef.current = typeof payload.revision === 'string' ? payload.revision : ''
|
|
2063
|
+
var ids = {}
|
|
2064
|
+
payload.rules.forEach(function (rule) { ids[rule.id] = true })
|
|
2065
|
+
savedIds.current = ids
|
|
2066
|
+
setState(function (prev) { return Object.assign({}, prev, { loading: false, view: payload, draft: draft }) })
|
|
2067
|
+
})
|
|
2068
|
+
.catch(function (error) { setState(function (prev) { return Object.assign({}, prev, { loading: false, error: String(error && error.message ? error.message : error) }) }) })
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
useEffect(function () { load() }, [sessionId, cwd])
|
|
2072
|
+
/**
|
|
2073
|
+
* The running-process list is only needed once the picker opens (it costs a
|
|
2074
|
+
* PowerShell round trip on Windows), so it is fetched lazily and then cached.
|
|
2075
|
+
*/
|
|
2076
|
+
function loadPrograms(force) {
|
|
2077
|
+
if (programsLoaded === true && force !== true) return Promise.resolve()
|
|
2078
|
+
var url = routeUrl('/dsh-ris-ide/proxy/programs')
|
|
2079
|
+
url.searchParams.set('sessionId', sessionId)
|
|
2080
|
+
if (cwd !== '') url.searchParams.set('cwd', cwd)
|
|
2081
|
+
return fetch(url.href, { headers: { accept: 'application/json' } })
|
|
2082
|
+
.then(function (response) { return response.json() })
|
|
2083
|
+
.then(function (payload) {
|
|
2084
|
+
if (payload && payload.ok === true && Array.isArray(payload.programs)) {
|
|
2085
|
+
setPrograms(payload.programs)
|
|
2086
|
+
setProgramsLoaded(true)
|
|
2087
|
+
}
|
|
2088
|
+
})
|
|
2089
|
+
.catch(function () { /* the picker falls back to free text */ })
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
/** Patch one rule of the draft (by id). */
|
|
2093
|
+
function patchRule(id, patch) {
|
|
2094
|
+
setState(function (prev) {
|
|
2095
|
+
if (prev.draft === null) return prev
|
|
2096
|
+
// Editing a starter row is what turns it into a stored rule: until then it
|
|
2097
|
+
// is only a suggestion the host re-derives on every read.
|
|
2098
|
+
var rules = prev.draft.rules.map(function (rule) {
|
|
2099
|
+
return rule.id === id ? Object.assign({}, rule, patch, { template: false }) : rule
|
|
2100
|
+
})
|
|
2101
|
+
return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { rules: rules }) })
|
|
2102
|
+
})
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
/** Add one blank rule for the user to fill in. */
|
|
2106
|
+
function addRule() {
|
|
2107
|
+
setState(function (prev) {
|
|
2108
|
+
if (prev.draft === null) return prev
|
|
2109
|
+
var id = 'r' + Date.now().toString(36)
|
|
2110
|
+
var rules = prev.draft.rules.concat([{ id: id, program: '', hosts: '', ports: '', enabled: true, shadow: false, source: 'user', workspace: cwd }])
|
|
2111
|
+
// Just the row: the program cell is editable and has its own 选… button,
|
|
2112
|
+
// so opening the picker here would cover the table the user just added to.
|
|
2113
|
+
return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { rules: rules }) })
|
|
2114
|
+
})
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Whether this program can take the SOCKS address directly, so the mapping
|
|
2119
|
+
* checkbox can say what it is for: `java`/`git`/`node`/`curl` do not need
|
|
2120
|
+
* it, a JDBC/Navicat-style client cannot work without it.
|
|
2121
|
+
*/
|
|
2122
|
+
var SOCKS_CAPABLE = ['java', 'javaw', 'mvn', 'gradle', 'node', 'npm', 'npx', 'git', 'curl', 'python', 'python3', 'bash', 'sh', 'zsh']
|
|
2123
|
+
|
|
2124
|
+
function programBasename(program) {
|
|
2125
|
+
var text = String(program || '').replace(/\\/g, '/')
|
|
2126
|
+
var base = text.split('/').pop() || ''
|
|
2127
|
+
return base.trim().toLowerCase().replace(/\.(exe|cmd|bat|sh)$/, '')
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
function programSpeaksSocks(program) {
|
|
2131
|
+
return SOCKS_CAPABLE.indexOf(programBasename(program)) !== -1
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
/**
|
|
2135
|
+
* Recompute what this draft row can do without asking the host: which
|
|
2136
|
+
* fragments parse, whether a loopback port can be bound (literal IPv4 +
|
|
2137
|
+
* explicit ports), and whether the program needs one at all.
|
|
2138
|
+
*/
|
|
2139
|
+
function parseRuleSpec(rule) {
|
|
2140
|
+
var hosts = String(rule.hosts || '').split(',').map(function (part) { return part.trim() }).filter(Boolean)
|
|
2141
|
+
var hostsInvalid = hosts.filter(function (part) { return !/^[A-Za-z0-9*]([A-Za-z0-9.*_-]*[A-Za-z0-9*])?$/.test(part) })
|
|
2142
|
+
var literal = hosts.length > 0 && hosts.every(function (part) { return /^\d{1,3}(\.\d{1,3}){3}$/.test(part) })
|
|
2143
|
+
var ports = []
|
|
2144
|
+
var portsInvalid = []
|
|
2145
|
+
var portsAny = false
|
|
2146
|
+
String(rule.ports || '').split(',').forEach(function (part) {
|
|
2147
|
+
var text = part.trim()
|
|
2148
|
+
if (text === '') return
|
|
2149
|
+
// `*` = every port; a blank spec is NOT that (the rule would not apply).
|
|
2150
|
+
if (text === '*') { portsAny = true; return }
|
|
2151
|
+
// The host's grammar, not a second dialect: `1000 - 1003` is a range there.
|
|
2152
|
+
var range = /^(\d{1,5})\s*-\s*(\d{1,5})$/.exec(text)
|
|
2153
|
+
if (range !== null) {
|
|
2154
|
+
var from = Number(range[1])
|
|
2155
|
+
var to = Number(range[2])
|
|
2156
|
+
if (from >= 1 && to <= 65535 && from <= to) { for (var port = from; port <= to; port += 1) ports.push(port) } else portsInvalid.push(text)
|
|
2157
|
+
return
|
|
2158
|
+
}
|
|
2159
|
+
var value = Number(text)
|
|
2160
|
+
if (Number.isInteger(value) && value >= 1 && value <= 65535) ports.push(value)
|
|
2161
|
+
else portsInvalid.push(text)
|
|
2162
|
+
})
|
|
2163
|
+
// `*` means "any port" (0) and cannot be bound, so it never makes a row shadowable.
|
|
2164
|
+
var bindable = ports.filter(function (port) { return port > 0 })
|
|
2165
|
+
var shadowable = literal && bindable.length > 0
|
|
2166
|
+
var speaksSocks = programSpeaksSocks(rule.program)
|
|
2167
|
+
// Same rule as the host: enabled + program + IP + port, all explicit
|
|
2168
|
+
// (`*` = everything). A blank axis means "does not apply", shown in the row.
|
|
2169
|
+
var program = String(rule.program || '').trim()
|
|
2170
|
+
var verdict = { effective: true, reason: '' }
|
|
2171
|
+
if (rule.enabled !== true) verdict = { effective: false, reason: '未启用' }
|
|
2172
|
+
else if (program === '') verdict = { effective: false, reason: '缺程序' }
|
|
2173
|
+
else if (hosts.length === 0) verdict = { effective: false, reason: '缺 IP(全匹配写 *)' }
|
|
2174
|
+
else if (hostsInvalid.length > 0) verdict = { effective: false, reason: 'IP 有无效片段' }
|
|
2175
|
+
else if (ports.length === 0 && portsAny !== true) verdict = { effective: false, reason: '缺端口(全匹配写 *)' }
|
|
2176
|
+
else if (portsInvalid.length > 0) verdict = { effective: false, reason: '端口有无效片段' }
|
|
2177
|
+
return {
|
|
2178
|
+
hosts: rule.hosts, ports: rule.ports,
|
|
2179
|
+
hostsInvalid: hostsInvalid, portsInvalid: portsInvalid,
|
|
2180
|
+
shadowable: shadowable,
|
|
2181
|
+
socksCapable: speaksSocks,
|
|
2182
|
+
effective: verdict.effective,
|
|
2183
|
+
ineffectiveReason: verdict.reason,
|
|
2184
|
+
autoShadow: shadowable && !speaksSocks,
|
|
2185
|
+
shadow: rule.shadow === true && shadowable ? true : (rule.shadow === false ? false : shadowable && !speaksSocks),
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/** Drop a rule (the auto rows are re-added by the host, so this is safe). */
|
|
2190
|
+
function dropRule(id) {
|
|
2191
|
+
setState(function (prev) {
|
|
2192
|
+
if (prev.draft === null) return prev
|
|
2193
|
+
return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { rules: prev.draft.rules.filter(function (rule) { return rule.id !== id }) }), pickFor: '' })
|
|
2194
|
+
})
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
/** POST the draft; the host normalises it and answers the parse diagnostics. */
|
|
2198
|
+
/**
|
|
2199
|
+
* What the form currently says, in one comparable string.
|
|
2200
|
+
*
|
|
2201
|
+
* The dialog has no 保存 button: every edit is written automatically, so it
|
|
2202
|
+
* needs a cheap way to tell "the user changed something" from "this is just
|
|
2203
|
+
* the echo of my own write".
|
|
2204
|
+
*/
|
|
2205
|
+
function draftSignature(draft) {
|
|
2206
|
+
if (draft === null) return ''
|
|
2207
|
+
return JSON.stringify({
|
|
2208
|
+
socks: [String(draft.socks.host).trim(), String(draft.socks.port).trim()],
|
|
2209
|
+
listenPort: String(draft.listenPort).trim(),
|
|
2210
|
+
rules: draft.rules.map(function (rule) {
|
|
2211
|
+
return [rule.id, String(rule.program).trim(), rule.hosts, rule.ports, rule.enabled === true, rule.shadow === true, rule.source]
|
|
2212
|
+
}),
|
|
2213
|
+
})
|
|
2214
|
+
}
|
|
2215
|
+
// Signature of what the host last confirmed. A write that comes back identical
|
|
2216
|
+
// must not schedule another write, or the dialog would loop forever.
|
|
2217
|
+
var savedSignature = useRef('')
|
|
2218
|
+
// Rule ids that exist on disk right now: a NEW half-typed row is simply not
|
|
2219
|
+
// written, while a SAVED row edited into a half-typed state must not keep its
|
|
2220
|
+
// old content silently — it is written as disabled instead.
|
|
2221
|
+
var savedIds = useRef({})
|
|
2222
|
+
// The 700 ms debounce means an edit can still be in flight when the dialog
|
|
2223
|
+
// closes or a button is pressed; both paths must write first, or the reload
|
|
2224
|
+
// that follows silently throws the edit away.
|
|
2225
|
+
var saveTimer = useRef(null)
|
|
2226
|
+
|
|
2227
|
+
/** Write now if the form differs from what the host confirmed. */
|
|
2228
|
+
function flushSave() {
|
|
2229
|
+
if (saveTimer.current !== null) { clearTimeout(saveTimer.current); saveTimer.current = null }
|
|
2230
|
+
if (state.draft === null) return Promise.resolve()
|
|
2231
|
+
if (draftSignature(state.draft) === savedSignature.current) return Promise.resolve()
|
|
2232
|
+
return save()
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/**
|
|
2236
|
+
* Rows that are half-typed do not go to disk.
|
|
2237
|
+
*
|
|
2238
|
+
* Auto-save fires while the user is still typing, so a rule with no program or
|
|
2239
|
+
* no port would otherwise be written as a broken row and come back as a rule
|
|
2240
|
+
* that silently does nothing. A DISABLED row is kept: that is a decision, not
|
|
2241
|
+
* an unfinished edit.
|
|
2242
|
+
*/
|
|
2243
|
+
function storableRule(rule) {
|
|
2244
|
+
var spec = parseRuleSpec(rule)
|
|
2245
|
+
if (String(rule.program || '').trim() === '') return false
|
|
2246
|
+
if (String(rule.hosts || '').trim() === '') return false
|
|
2247
|
+
if (String(rule.ports || '').trim() === '') return false
|
|
2248
|
+
if (spec.hostsInvalid.length > 0) return false
|
|
2249
|
+
if (spec.portsInvalid.length > 0) return false
|
|
2250
|
+
return true
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
/**
|
|
2254
|
+
* What to write for one row: `write` (complete), `disable` (a row that is
|
|
2255
|
+
* already on disk was edited into an incomplete state) or `skip` (a brand new
|
|
2256
|
+
* row that is still being typed).
|
|
2257
|
+
*/
|
|
2258
|
+
function writeMode(rule) {
|
|
2259
|
+
if (storableRule(rule)) return 'write'
|
|
2260
|
+
return savedIds.current[rule.id] === true ? 'disable' : 'skip'
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
function save() {
|
|
2264
|
+
if (state.draft === null) return
|
|
2265
|
+
var skipped = 0
|
|
2266
|
+
var disabledByEdit = 0
|
|
2267
|
+
var storable = []
|
|
2268
|
+
state.draft.rules.forEach(function (rule) {
|
|
2269
|
+
// Starter rows are re-derived from AUTO_PROGRAMS on every read: writing one
|
|
2270
|
+
// would freeze today's suggestion into the machine-wide table forever.
|
|
2271
|
+
if (rule.template === true) return
|
|
2272
|
+
var mode = writeMode(rule)
|
|
2273
|
+
if (mode === 'skip') { skipped += 1; return }
|
|
2274
|
+
if (mode === 'disable') { disabledByEdit += 1; storable.push(Object.assign({}, rule, { enabled: false })); return }
|
|
2275
|
+
storable.push(rule)
|
|
2276
|
+
})
|
|
2277
|
+
// Nothing writable at all (every row is a new row still being typed): keep
|
|
2278
|
+
// what is on disk instead of writing an empty table over it.
|
|
2279
|
+
if (storable.length === 0 && skipped > 0) {
|
|
2280
|
+
setState(function (prev) { return Object.assign({}, prev, { saving: false, note: '规则还没填完整,暂不写入(' + skipped + ' 条待补全)' }) })
|
|
2281
|
+
return Promise.resolve()
|
|
2282
|
+
}
|
|
2283
|
+
var body = {
|
|
2284
|
+
sessionId: sessionId,
|
|
2285
|
+
cwd: cwd,
|
|
2286
|
+
// What the form was rendered from: a mismatch means someone else saved first.
|
|
2287
|
+
revision: revisionRef.current,
|
|
2288
|
+
config: {
|
|
2289
|
+
socks: { host: state.draft.socks.host.trim(), port: Number(state.draft.socks.port) || 0 },
|
|
2290
|
+
listenPort: Number(state.draft.listenPort) || 0,
|
|
2291
|
+
rules: storable.map(function (rule) {
|
|
2292
|
+
return { id: rule.id, program: rule.program.trim(), hosts: rule.hosts, ports: rule.ports, enabled: rule.enabled, shadow: rule.shadow, source: rule.source, workspace: cwd }
|
|
2293
|
+
}),
|
|
2294
|
+
},
|
|
2295
|
+
}
|
|
2296
|
+
var signature = draftSignature(state.draft)
|
|
2297
|
+
setState(function (prev) { return Object.assign({}, prev, { saving: true, error: '' }) })
|
|
2298
|
+
return fetch(routeUrl('/dsh-ris-ide/proxy').href, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
|
|
2299
|
+
.then(function (response) { return response.json().then(function (payload) { return { status: response.status, payload: payload } }) })
|
|
2300
|
+
.then(function (answer) {
|
|
2301
|
+
var payload = answer.payload
|
|
2302
|
+
if (answer.status === 409 && payload.conflict === true) {
|
|
2303
|
+
// Reload instead of retrying: the other window's rows are the truth now,
|
|
2304
|
+
// and the user's own pending edit is gone from disk — say so plainly.
|
|
2305
|
+
revisionRef.current = typeof payload.revision === 'string' ? payload.revision : ''
|
|
2306
|
+
var fresh = payload.view && Array.isArray(payload.view.rules) ? draftFromView(payload.view) : null
|
|
2307
|
+
setState(function (prev) {
|
|
2308
|
+
return Object.assign({}, prev, {
|
|
2309
|
+
saving: false,
|
|
2310
|
+
view: payload.view || prev.view,
|
|
2311
|
+
draft: fresh === null ? prev.draft : fresh,
|
|
2312
|
+
note: '规则表已在别处被修改,已重新载入(本次改动未写入)',
|
|
2313
|
+
error: '',
|
|
2314
|
+
})
|
|
2315
|
+
})
|
|
2316
|
+
if (fresh !== null) {
|
|
2317
|
+
savedSignature.current = draftSignature(fresh)
|
|
2318
|
+
var conflictIds = {}
|
|
2319
|
+
fresh.rules.forEach(function (rule) { conflictIds[rule.id] = true })
|
|
2320
|
+
savedIds.current = conflictIds
|
|
2321
|
+
}
|
|
2322
|
+
return
|
|
2323
|
+
}
|
|
2324
|
+
if (payload.ok !== true) throw new Error(payload.message || '保存失败')
|
|
2325
|
+
revisionRef.current = typeof payload.revision === 'string' ? payload.revision : ''
|
|
2326
|
+
savedSignature.current = signature
|
|
2327
|
+
var ids = {}
|
|
2328
|
+
;(payload.rules || []).forEach(function (rule) { ids[rule.id] = true })
|
|
2329
|
+
savedIds.current = ids
|
|
2330
|
+
var note = (payload.reloadNote ? '已自动保存 · ' + payload.reloadNote : '已自动保存,本机引擎已实时应用')
|
|
2331
|
+
+ (skipped > 0 ? '(' + skipped + ' 条未填完整,未写入)' : '')
|
|
2332
|
+
+ (disabledByEdit > 0 ? '(' + disabledByEdit + ' 条改到一半,已置为停用)' : '')
|
|
2333
|
+
setState(function (prev) { return Object.assign({}, prev, { saving: false, note: note, view: payload }) })
|
|
2334
|
+
})
|
|
2335
|
+
.catch(function (error) { setState(function (prev) { return Object.assign({}, prev, { saving: false, error: String(error && error.message ? error.message : error) }) }) })
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
// Write 700ms after the last edit: typing an IP should produce one write, not
|
|
2339
|
+
// one per keystroke (each write may also reload the system-level interceptor).
|
|
2340
|
+
useEffect(function () {
|
|
2341
|
+
if (state.draft === null) return undefined
|
|
2342
|
+
var signature = draftSignature(state.draft)
|
|
2343
|
+
if (signature === savedSignature.current) return undefined
|
|
2344
|
+
saveTimer.current = setTimeout(function () { saveTimer.current = null; void save() }, 700)
|
|
2345
|
+
return function () {
|
|
2346
|
+
if (saveTimer.current !== null) { clearTimeout(saveTimer.current); saveTimer.current = null }
|
|
2347
|
+
}
|
|
2348
|
+
}, [state.draft])
|
|
2349
|
+
|
|
2350
|
+
/**
|
|
2351
|
+
* start / stop / git-on / git-off, then refresh the view.
|
|
2352
|
+
* `ruleId` is only used by run/run-stop (the per-row 启动/停止 button).
|
|
2353
|
+
*/
|
|
2354
|
+
function act(action, ruleId, side) {
|
|
2355
|
+
// The action reloads the whole view; a pending auto-save must land first or
|
|
2356
|
+
// the reload would overwrite the edit and it would never reach the disk.
|
|
2357
|
+
flushSave().catch(function () {}).then(function () { actNow(action, ruleId, side) })
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
function actNow(action, ruleId, side) {
|
|
2361
|
+
setState(function (prev) { return Object.assign({}, prev, { busy: action, error: '', note: '' }) })
|
|
2362
|
+
fetch(routeUrl('/dsh-ris-ide/proxy/action').href, {
|
|
2363
|
+
method: 'POST',
|
|
2364
|
+
headers: { 'content-type': 'application/json' },
|
|
2365
|
+
body: JSON.stringify({ sessionId: sessionId, cwd: cwd, action: action, ruleId: ruleId, side: side }),
|
|
2366
|
+
})
|
|
2367
|
+
.then(function (response) { return response.json() })
|
|
2368
|
+
.then(function (payload) {
|
|
2369
|
+
if (payload.ok !== true) throw new Error(payload.message || '操作失败')
|
|
2370
|
+
var result = payload.result || {}
|
|
2371
|
+
var redirectorCommand = typeof result.command === 'object' && result.command !== null && typeof result.command.display === 'string'
|
|
2372
|
+
? result.command.display
|
|
2373
|
+
: (action === 'redirector-stop' ? '' : state.redirectorCommand)
|
|
2374
|
+
// The redirector rides along with start/stop, so its outcome is part of
|
|
2375
|
+
// the note: a UAC prompt that was dismissed must not look like success.
|
|
2376
|
+
var bridgeNote = ''
|
|
2377
|
+
var bridge = result.redirector
|
|
2378
|
+
if (bridge !== undefined && bridge !== null && typeof bridge === 'object') {
|
|
2379
|
+
var started = Array.isArray(bridge.started) ? bridge.started : []
|
|
2380
|
+
var skipped = Array.isArray(bridge.skipped) ? bridge.skipped : []
|
|
2381
|
+
if (action === 'start') {
|
|
2382
|
+
bridgeNote = started.length > 0
|
|
2383
|
+
? ' · 系统层拦截已启动(' + started.map(function (item) { return item.side }).join('+') + ')'
|
|
2384
|
+
: (skipped.length > 0 && skipped[0].reason !== undefined ? ' · 系统层拦截:' + String(skipped[0].reason) : '')
|
|
2385
|
+
} else if (action === 'stop') {
|
|
2386
|
+
bridgeNote = bridge.stopped === true ? ' · 系统层拦截已停止' : ''
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
var gitNote = ''
|
|
2390
|
+
if (result.git !== undefined && result.git !== null && typeof result.git === 'object') {
|
|
2391
|
+
if (action === 'start') {
|
|
2392
|
+
gitNote = result.git.ok === true && result.git.key !== ''
|
|
2393
|
+
? ' · git 代理已写入 ' + String(result.git.key)
|
|
2394
|
+
: (result.git.error !== undefined ? ' · git:' + String(result.git.error) : '')
|
|
2395
|
+
} else if (action === 'stop' && result.git.key !== undefined && result.git.key !== '') {
|
|
2396
|
+
gitNote = ' · git 代理已清除'
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
var note = action === 'start'
|
|
2400
|
+
? (result.ok === true ? '已启动:' + (payload.socksUrl || '') + bridgeNote + gitNote : String(result.error || '启动失败'))
|
|
2401
|
+
: action === 'stop'
|
|
2402
|
+
? (result.ok === true ? '已停止' + bridgeNote + gitNote : String(result.error || '停止失败'))
|
|
2403
|
+
: action === 'git-on' || action === 'git-off'
|
|
2404
|
+
? (result.ok === true ? 'git 配置 ' + String(result.key || '') + (action === 'git-on' ? ' 已写入' : ' 已清除') : String(result.error || 'git 配置失败'))
|
|
2405
|
+
: action === 'redirector-sync'
|
|
2406
|
+
? '配置已导出' + (result.reason ? ':' + String(result.reason) : '')
|
|
2407
|
+
: action === 'redirector-start'
|
|
2408
|
+
? (result.started === true
|
|
2409
|
+
? '系统层拦截已启动(pid ' + String(result.pid || '') + ')'
|
|
2410
|
+
: '未能启动' + (result.reason ? ':' + String(result.reason) : '') + '(命令见下方)')
|
|
2411
|
+
: action === 'redirector-stop'
|
|
2412
|
+
? (result.stopped === true ? '系统层拦截已停止' : '未能停止' + (result.reason ? ':' + String(result.reason) : ''))
|
|
2413
|
+
: ''
|
|
2414
|
+
return load().then(function () {
|
|
2415
|
+
setState(function (prev) { return Object.assign({}, prev, { busy: '', note: note, redirectorCommand: redirectorCommand }) })
|
|
2416
|
+
})
|
|
2417
|
+
})
|
|
2418
|
+
.catch(function (error) { setState(function (prev) { return Object.assign({}, prev, { busy: '', error: String(error && error.message ? error.message : error) }) }) })
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
var draft = state.draft
|
|
2422
|
+
var view = state.view
|
|
2423
|
+
// `fontFamily: 'inherit'` is load-bearing: a form control does NOT inherit the
|
|
2424
|
+
// page font, so without it the dialog's inputs and buttons render in the
|
|
2425
|
+
// browser's UI font and the sidebar shape still wraps rows.
|
|
2426
|
+
var field = { width: '100%', boxSizing: 'border-box', fontFamily: 'inherit', fontSize: 12, padding: '3px 6px', borderRadius: 4, border: '1px solid color-mix(in srgb, currentColor 22%, transparent)', background: 'transparent', color: 'inherit' }
|
|
2427
|
+
var tiny = { fontSize: 11, opacity: 0.62 }
|
|
2428
|
+
/** One labelled input of the address section. */
|
|
2429
|
+
function addressField(label, value, placeholder, onInput, width) {
|
|
2430
|
+
return h('label', { style: { display: 'flex', flexDirection: 'column', gap: 2, width: width || 150 } },
|
|
2431
|
+
h('span', { style: tiny }, label),
|
|
2432
|
+
h('input', { type: 'text', value: value, placeholder: placeholder, style: field, onInput: onInput }))
|
|
2433
|
+
}
|
|
2434
|
+
/** Basename of a path-shaped program value, for the row button. */
|
|
2435
|
+
function programLabel(value) {
|
|
2436
|
+
if (typeof value !== 'string' || value === '') return ''
|
|
2437
|
+
var cut = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'))
|
|
2438
|
+
return cut === -1 ? value : value.slice(cut + 1)
|
|
2439
|
+
}
|
|
2440
|
+
/**
|
|
2441
|
+
* The program picker: ① processes running now (this OS + Windows when
|
|
2442
|
+
* reachable), ② a fixed executable picked from disk — the second source is
|
|
2443
|
+
* what lets a rule exist before its program is started.
|
|
2444
|
+
*/
|
|
2445
|
+
/** Close the nested picker (it is a dialog of its own). */
|
|
2446
|
+
function closePicker() {
|
|
2447
|
+
setState(function (prev) { return Object.assign({}, prev, { pickFor: '', pickFilter: '' }) })
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
// The host half reports which OS it runs on ('windows' | 'wsl' | 'linux' | …);
|
|
2451
|
+
// only a posix host has a second (Windows) file system reachable via /mnt.
|
|
2452
|
+
var hostIsPosix = !(view !== null && view.side === 'windows')
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* Write a picked path the way the program's own OS spells it.
|
|
2456
|
+
*
|
|
2457
|
+
* WSL sees the Windows disks under /mnt, so one file browser covers both
|
|
2458
|
+
* sides — but a rule has to name `D:\Program Files\...`, not `/mnt/d/...`,
|
|
2459
|
+
* or a Windows-side interceptor cannot match the process.
|
|
2460
|
+
*/
|
|
2461
|
+
function pickedPath(value) {
|
|
2462
|
+
var match = /^\/mnt\/([A-Za-z])\/(.*)$/.exec(value)
|
|
2463
|
+
if (match === null) return value
|
|
2464
|
+
return match[1].toUpperCase() + ':\\' + match[2].replace(/\//g, '\\')
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
/**
|
|
2468
|
+
* Entry points: on a posix host the tree starts at `/` and the Windows disks,
|
|
2469
|
+
* nothing else. The roots list comes from the host half (which only reloads
|
|
2470
|
+
* with dsh web), so this both adds `/` when an older host omits it and drops
|
|
2471
|
+
* the workspace/home/temp shortcuts — they only pushed the real start down.
|
|
2472
|
+
*/
|
|
2473
|
+
function withFilesystemRoot(roots, posix) {
|
|
2474
|
+
if (posix !== true) return roots
|
|
2475
|
+
var kept = roots.filter(function (root) { return root.path === '/' || /^\/mnt\/[A-Za-z](\/|$)/.test(root.path) })
|
|
2476
|
+
if (kept.some(function (root) { return root.path === '/' })) return kept
|
|
2477
|
+
return [{ name: '根路径 /', path: '/' }].concat(kept)
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Rows of the file tree, one level at a time.
|
|
2482
|
+
*
|
|
2483
|
+
* The tree grows IN PLACE: a folder is a row that toggles, not a "enter this
|
|
2484
|
+
* directory" navigation, so a path three levels deep costs three clicks and
|
|
2485
|
+
* the parent stays visible the whole time.
|
|
2486
|
+
*/
|
|
2487
|
+
function dirRow(dir, depth, chooser) {
|
|
2488
|
+
var open = tree.expanded[dir.path] === true
|
|
2489
|
+
var node = tree.nodes[dir.path]
|
|
2490
|
+
// A folder whose listing came back empty is a LEAF in practice: showing a
|
|
2491
|
+
// caret there invites a click that can only disappoint.
|
|
2492
|
+
var leaf = node !== undefined && node.dirs.length === 0 && node.files.length === 0
|
|
2493
|
+
var rows = [h('div', {
|
|
2494
|
+
key: 'd:' + dir.path,
|
|
2495
|
+
title: leaf ? dir.path + '(空目录)' : dir.path,
|
|
2496
|
+
style: {
|
|
2497
|
+
display: 'flex', alignItems: 'center', gap: 4, cursor: leaf ? 'default' : 'pointer',
|
|
2498
|
+
padding: '1px 4px', paddingLeft: 4 + depth * 14, borderRadius: 4, fontSize: 12,
|
|
2499
|
+
opacity: leaf ? 0.66 : 1,
|
|
2500
|
+
},
|
|
2501
|
+
'data-proxy-tree-dir': dir.path,
|
|
2502
|
+
'data-proxy-tree-leaf': leaf ? '1' : '0',
|
|
2503
|
+
onClick: leaf ? undefined : function () { toggleDir(dir) },
|
|
2504
|
+
onMouseDown: function (event) { event.preventDefault() },
|
|
2505
|
+
},
|
|
2506
|
+
h('span', { style: { width: 12, opacity: 0.8 } }, leaf ? '·' : open ? '▾' : '▸'),
|
|
2507
|
+
h('span', null, (leaf ? '📂 ' : '📁 ') + dir.name),
|
|
2508
|
+
tree.loading[dir.path] === true ? h('span', { style: tiny }, '…') : null)]
|
|
2509
|
+
if (open === true) rows = rows.concat(treeRows(dir.path, depth + 1, chooser))
|
|
2510
|
+
return rows
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
function treeRows(path, depth, chooser) {
|
|
2514
|
+
var node = tree.nodes[path]
|
|
2515
|
+
if (node === undefined) {
|
|
2516
|
+
return tree.loading[path] === true
|
|
2517
|
+
? [h('div', { key: 'loading:' + path, style: Object.assign({}, tiny, { paddingLeft: 8 + depth * 14 }) }, '读取中…')]
|
|
2518
|
+
: []
|
|
2519
|
+
}
|
|
2520
|
+
var rows = []
|
|
2521
|
+
node.dirs.forEach(function (dir) {
|
|
2522
|
+
rows = rows.concat(dirRow(dir, depth, chooser))
|
|
2523
|
+
})
|
|
2524
|
+
node.files.forEach(function (file) {
|
|
2525
|
+
rows.push(h('button', {
|
|
2526
|
+
key: 'f:' + file.path, type: 'button', title: '选这个程序:' + file.path,
|
|
2527
|
+
style: {
|
|
2528
|
+
// Same box as a folder row (12px caret slot, then the name), so the
|
|
2529
|
+
// indentation lines up — but the slot stays EMPTY: a file cannot be
|
|
2530
|
+
// expanded, and an arrow there reads as "click me twice".
|
|
2531
|
+
display: 'flex', alignItems: 'center', gap: 4, width: '100%', textAlign: 'left',
|
|
2532
|
+
cursor: 'pointer', padding: '1px 4px', paddingLeft: 4 + depth * 14, fontSize: 12,
|
|
2533
|
+
background: 'transparent', border: 'none', color: 'inherit', borderRadius: 4,
|
|
2534
|
+
},
|
|
2535
|
+
'data-proxy-tree-file': file.path,
|
|
2536
|
+
onClick: function () { chooser(file.path) },
|
|
2537
|
+
},
|
|
2538
|
+
h('span', { style: { width: 12 } }, ''),
|
|
2539
|
+
h('span', null, '📄 ' + file.name)))
|
|
2540
|
+
})
|
|
2541
|
+
return rows
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
function pickerCard(rule) {
|
|
2545
|
+
var needle = state.pickFilter.trim().toLowerCase()
|
|
2546
|
+
var items = programs.filter(function (item) { return needle === '' || item.name.toLowerCase().indexOf(needle) !== -1 }).slice(0, 40)
|
|
2547
|
+
var chooser = function (value) {
|
|
2548
|
+
// Picking a program also picks the mechanism: a SOCKS-aware program is
|
|
2549
|
+
// told the upstream address at launch (no mapping), anything else can
|
|
2550
|
+
// only reach the tunnel through 127.0.0.1:<same port>.
|
|
2551
|
+
var speaksSocks = programSpeaksSocks(value)
|
|
2552
|
+
patchRule(rule.id, {
|
|
2553
|
+
program: pickedPath(value),
|
|
2554
|
+
socksCapable: speaksSocks,
|
|
2555
|
+
shadow: speaksSocks ? false : rule.shadow === true || rule.shadowable !== false,
|
|
2556
|
+
})
|
|
2557
|
+
setState(function (prev) { return Object.assign({}, prev, { pickFor: '', pickFilter: '' }) })
|
|
2558
|
+
}
|
|
2559
|
+
var tabButton = function (mode, label) {
|
|
2560
|
+
var active = pickMode === mode
|
|
2561
|
+
return h('button', {
|
|
2562
|
+
type: 'button',
|
|
2563
|
+
style: Object.assign({}, field, { width: 'auto', cursor: 'pointer', fontWeight: active ? 600 : 400, opacity: active ? 1 : 0.6 }),
|
|
2564
|
+
'data-proxy-pick-mode': mode,
|
|
2565
|
+
onClick: function () {
|
|
2566
|
+
setPickMode(mode)
|
|
2567
|
+
if (mode === 'running') { if (programsLoaded !== true) void loadPrograms() ; return }
|
|
2568
|
+
// Switching sides starts a fresh tree for that file system; the read
|
|
2569
|
+
// is lazy (only the roots now, folders when expanded).
|
|
2570
|
+
var side = mode === 'windows' ? 'windows' : 'local'
|
|
2571
|
+
if (tree.side !== side) {
|
|
2572
|
+
setTree({ side: side, roots: null, nodes: {}, expanded: {}, loading: {}, error: '' })
|
|
2573
|
+
void loadTreeDir('', side)
|
|
2574
|
+
} else if (tree.roots === null) void loadTreeDir('', side)
|
|
2575
|
+
},
|
|
2576
|
+
}, label)
|
|
2577
|
+
}
|
|
2578
|
+
return h('div', {
|
|
2579
|
+
style: { width: 680, maxWidth: '92vw', maxHeight: '80vh', display: 'flex', flexDirection: 'column', padding: 12, borderRadius: 8, background: 'var(--dsw-surface, #fff)', border: '1px solid color-mix(in srgb, currentColor 18%, transparent)' },
|
|
2580
|
+
'data-proxy-picker': rule.id,
|
|
2581
|
+
},
|
|
2582
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6 } },
|
|
2583
|
+
h('strong', { style: { fontSize: 13 } }, '选择程序'),
|
|
2584
|
+
h('span', { style: Object.assign({}, tiny, { flex: 1 }) }, '给规则「' + (rule.label || rule.program || rule.id) + '」选择可执行文件'),
|
|
2585
|
+
h('button', {
|
|
2586
|
+
type: 'button', style: Object.assign({}, field, { width: 26, cursor: 'pointer' }),
|
|
2587
|
+
title: '关闭', 'data-proxy-picker-close': '1',
|
|
2588
|
+
onClick: function () { closePicker() },
|
|
2589
|
+
}, '×')),
|
|
2590
|
+
h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', marginBottom: 6, flexWrap: 'wrap' } },
|
|
2591
|
+
tabButton('running', '运行中的程序'),
|
|
2592
|
+
// ONE file tab: on WSL the Windows disks are ordinary folders under
|
|
2593
|
+
// /mnt, so a second tab would only be a different spelling of the same
|
|
2594
|
+
// tree. A pick from there is written back as `D:\…` (see pickedPath).
|
|
2595
|
+
tabButton('local', '选择文件'),
|
|
2596
|
+
h('span', { style: Object.assign({}, tiny, { marginLeft: 4 }) },
|
|
2597
|
+
pickMode === 'running' ? '进程名即程序名,也可直接在上方的输入框手写' : '点文件夹展开,点文件选中;也可以直接用输入框写路径')),
|
|
2598
|
+
pickMode === 'running'
|
|
2599
|
+
? h('div', null,
|
|
2600
|
+
h('input', {
|
|
2601
|
+
type: 'text', value: state.pickFilter, placeholder: '过滤程序名(如 java / navicat)', style: Object.assign({}, field, { marginBottom: 4 }),
|
|
2602
|
+
autoFocus: true,
|
|
2603
|
+
onInput: function (event) { setState(function (prev) { return Object.assign({}, prev, { pickFilter: event.target.value }) }) },
|
|
2604
|
+
}),
|
|
2605
|
+
items.length === 0
|
|
2606
|
+
? h('div', { style: tiny }, programsLoaded !== true ? '读取中…' : '没有匹配的程序;直接在上面输入程序名也可以')
|
|
2607
|
+
: items.map(function (item) {
|
|
2608
|
+
return h('button', {
|
|
2609
|
+
key: item.name + ':' + item.side, type: 'button',
|
|
2610
|
+
style: { display: 'block', width: '100%', textAlign: 'left', fontSize: 12, padding: '2px 4px', background: 'transparent', border: 'none', color: 'inherit', cursor: 'pointer' },
|
|
2611
|
+
title: item.side === 'windows' ? 'Windows 侧进程' : '本侧进程',
|
|
2612
|
+
onClick: function () { chooser(item.name) },
|
|
2613
|
+
}, item.name + (item.side === 'windows' ? '(Windows)' : ''))
|
|
2614
|
+
}))
|
|
2615
|
+
: h('div', { style: { flex: 1, minHeight: 220, maxHeight: '58vh', overflowY: 'auto', border: '1px solid color-mix(in srgb, currentColor 12%, transparent)', borderRadius: 6, padding: '4px 2px' }, 'data-proxy-tree': tree.side },
|
|
2616
|
+
tree.error !== '' ? h('div', { style: { fontSize: 11, color: '#d9534f', padding: 4 } }, tree.error) : null,
|
|
2617
|
+
tree.roots === null
|
|
2618
|
+
? h('div', { style: Object.assign({}, tiny, { padding: 6 }) }, '读取中…')
|
|
2619
|
+
// The top level is the list of entry points, each one a folder row:
|
|
2620
|
+
// the tree never has a "current directory" to step out of.
|
|
2621
|
+
//
|
|
2622
|
+
// `/` is added here as well as in the host: the roots list comes from
|
|
2623
|
+
// the host half, which only reloads when `dsh web` restarts, and a
|
|
2624
|
+
// browser refresh must not leave the tree without the one entry that
|
|
2625
|
+
// reaches everything.
|
|
2626
|
+
: [].concat.apply([], withFilesystemRoot(tree.roots, hostIsPosix).map(function (root) { return dirRow(root, 0, chooser) }))))
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* ProxyBridge state of BOTH sides, plus the exact command to run.
|
|
2630
|
+
*
|
|
2631
|
+
* The web route cannot elevate (a browser click cannot become root/UAC), so
|
|
2632
|
+
* "start" writes the profile and hands back the command when rights are
|
|
2633
|
+
* missing — the block shows it verbatim instead of a bare failure.
|
|
2634
|
+
*/
|
|
2635
|
+
function redirectorBlock() {
|
|
2636
|
+
var dialogState = state
|
|
2637
|
+
var info = view === null ? null : view.redirector
|
|
2638
|
+
if (info === null || info === undefined) return null
|
|
2639
|
+
var describe = function (side, label) {
|
|
2640
|
+
var sideState = info[side] || {}
|
|
2641
|
+
var text = sideState.available === true
|
|
2642
|
+
? (sideState.version ? 'v' + String(sideState.version) : '已找到')
|
|
2643
|
+
: (side === 'windows' && view.side === 'windows' ? '未安装' : '未安装(可选)')
|
|
2644
|
+
return h('span', { style: { fontSize: 11, whiteSpace: 'nowrap' }, title: sideState.path || '' },
|
|
2645
|
+
label + ':' + text)
|
|
2646
|
+
}
|
|
2647
|
+
var command = typeof state.redirectorCommand === 'string' ? state.redirectorCommand : ''
|
|
2648
|
+
return h('div', {
|
|
2649
|
+
style: { marginTop: 8, padding: '6px 8px', border: '1px solid color-mix(in srgb, currentColor 12%, transparent)', borderRadius: 6 },
|
|
2650
|
+
'data-proxy-redirector': '1',
|
|
2651
|
+
},
|
|
2652
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
|
|
2653
|
+
h('span', { style: { fontWeight: 600, fontSize: 12 } }, '系统层拦截(ProxyBridge)'),
|
|
2654
|
+
describe('local', '本侧'),
|
|
2655
|
+
describe('windows', 'Windows'),
|
|
2656
|
+
h('span', { style: { fontSize: 11, opacity: 0.75 } },
|
|
2657
|
+
info.running === true ? '运行中' : '随代理启停'),
|
|
2658
|
+
),
|
|
2659
|
+
h('div', { style: Object.assign({}, tiny, { marginTop: 4, lineHeight: 1.5 }) },
|
|
2660
|
+
'覆盖任何方式启动的程序;两端独立进程,启动需 root/管理员(会弹窗提权)。'),
|
|
2661
|
+
// No controls of its own: this block reports what the one 启动/停止 pair
|
|
2662
|
+
// does, and shows the command only when the automatic start could not
|
|
2663
|
+
// elevate (a web click cannot become root).
|
|
2664
|
+
command !== ''
|
|
2665
|
+
? h('div', {
|
|
2666
|
+
style: Object.assign({}, tiny, { marginTop: 4, fontFamily: 'monospace', wordBreak: 'break-all', userSelect: 'text' }),
|
|
2667
|
+
'data-proxy-redirector-command': '1',
|
|
2668
|
+
title: '自动启动提权失败时,在终端里执行(需要 sudo / 管理员)',
|
|
2669
|
+
}, command)
|
|
2670
|
+
: null)
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
/**
|
|
2674
|
+
* The port suffix of the mapping hint, e.g. `:1521` for "1521,6890".
|
|
2675
|
+
*
|
|
2676
|
+
* One listener is created per (host,port) pair, so the hint names the first
|
|
2677
|
+
* port and says how many there are instead of listing them all.
|
|
2678
|
+
*/
|
|
2679
|
+
function portSuffix(rule) {
|
|
2680
|
+
var ports = rule.portsParsed || []
|
|
2681
|
+
if (ports.length === 0) return ''
|
|
2682
|
+
return ':' + String(ports[0]) + (ports.length > 1 ? ' 等 ' + String(ports.length) + ' 个' : '')
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
/**
|
|
2686
|
+
* The host's verdict for this row, when the row still says what the host saved.
|
|
2687
|
+
*
|
|
2688
|
+
* Local parsing is a typing PREVIEW: the host owns the real rule (`ruleEffectiveness`
|
|
2689
|
+
* + the engine's allow-list). Comparing the texts is how this stays one source of
|
|
2690
|
+
* truth — a message like「界面说生效、引擎说不生效」cannot survive the comparison.
|
|
2691
|
+
*/
|
|
2692
|
+
function hostVerdictFor(rule) {
|
|
2693
|
+
var view = state.view
|
|
2694
|
+
if (view === null || !Array.isArray(view.rules)) return null
|
|
2695
|
+
var found = null
|
|
2696
|
+
view.rules.forEach(function (row) { if (row !== null && row.id === rule.id) found = row })
|
|
2697
|
+
if (found === null) return null
|
|
2698
|
+
var same = String(found.program || '').trim() === String(rule.program || '').trim()
|
|
2699
|
+
&& String(found.hosts || '') === String(rule.hosts || '')
|
|
2700
|
+
&& String(found.ports || '') === String(rule.ports || '')
|
|
2701
|
+
&& (found.enabled === true) === (rule.enabled === true)
|
|
2702
|
+
return same ? found : null
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
/** One rule row. */
|
|
2706
|
+
function ruleRow(rule) {
|
|
2707
|
+
var invalid = (rule.hostsInvalid || []).length > 0 || (rule.portsInvalid || []).length > 0
|
|
2708
|
+
// What the ENGINE will conclude, once the host has seen this exact row.
|
|
2709
|
+
var hostRow = hostVerdictFor(rule)
|
|
2710
|
+
var effective = hostRow === null ? rule.effective : hostRow.effective === true
|
|
2711
|
+
var ineffectiveReason = hostRow === null ? rule.ineffectiveReason : hostRow.ineffectiveReason
|
|
2712
|
+
// Every row is editable: ProxyBridge hooks the kernel and matches process
|
|
2713
|
+
// names, so a rule is machine-wide and the workspace it came from is only
|
|
2714
|
+
// a provenance label (shown as 来源).
|
|
2715
|
+
return h('div', {
|
|
2716
|
+
key: rule.id,
|
|
2717
|
+
style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 6, padding: '5px 0', borderTop: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
|
|
2718
|
+
'data-proxy-rule': rule.id,
|
|
2719
|
+
'data-proxy-effective': rule.enabled === true && effective === false ? '0' : '1',
|
|
2720
|
+
},
|
|
2721
|
+
h('label', { style: { display: 'flex', alignItems: 'center', gap: 4, fontSize: 12, width: 58 } },
|
|
2722
|
+
h('input', { type: 'checkbox', checked: rule.enabled, onChange: function (event) { patchRule(rule.id, { enabled: event.target.checked }) } }),
|
|
2723
|
+
'启用'),
|
|
2724
|
+
// The name is typed, not chosen: `java` matches any path (ProxyBridge uses a
|
|
2725
|
+
// bare name as *java*), `D:\…\java.exe` matches exactly that executable.
|
|
2726
|
+
// The button opens the two-source picker (running process / file tree).
|
|
2727
|
+
h('input', {
|
|
2728
|
+
type: 'text', value: rule.program, placeholder: '程序名或路径:java / D:\\…\\java.exe',
|
|
2729
|
+
style: Object.assign({}, field, { width: 150 }),
|
|
2730
|
+
title: '直接输入程序名(如 java,匹配任意路径)或完整路径(精确匹配)',
|
|
2731
|
+
'data-proxy-program': rule.id,
|
|
2732
|
+
onInput: function (event) {
|
|
2733
|
+
var value = event.target.value
|
|
2734
|
+
patchRule(rule.id, { program: value, socksCapable: programSpeaksSocks(value) })
|
|
2735
|
+
},
|
|
2736
|
+
}),
|
|
2737
|
+
h('button', {
|
|
2738
|
+
type: 'button',
|
|
2739
|
+
style: Object.assign({}, field, { width: 42, cursor: 'pointer' }),
|
|
2740
|
+
title: '从运行中的进程或文件树中选择(弹窗)',
|
|
2741
|
+
'data-proxy-pick': rule.id,
|
|
2742
|
+
onClick: function () {
|
|
2743
|
+
setState(function (prev) { return Object.assign({}, prev, { pickFor: rule.id, pickFilter: '' }) })
|
|
2744
|
+
void loadPrograms()
|
|
2745
|
+
},
|
|
2746
|
+
}, '选…'),
|
|
2747
|
+
// Rows a provider generated (yds: "YonCode java", "YonCode git") carry a
|
|
2748
|
+
// label so the table says where the rule came from without opening it.
|
|
2749
|
+
rule.label === undefined || rule.label === ''
|
|
2750
|
+
? null
|
|
2751
|
+
: h('span', {
|
|
2752
|
+
style: { fontSize: 10, opacity: 0.8, whiteSpace: 'nowrap' },
|
|
2753
|
+
'data-proxy-label': rule.label,
|
|
2754
|
+
title: rule.label + ':' + rule.program,
|
|
2755
|
+
}, rule.label),
|
|
2756
|
+
h('input', {
|
|
2757
|
+
type: 'text', value: rule.hosts, placeholder: 'IP 允许:1.1.1.*, 10.0.0.5(全部写 *;空=本行不生效)',
|
|
2758
|
+
style: Object.assign({}, field, { width: 168 }), title: '支持逗号分隔与 * 段通配',
|
|
2759
|
+
onInput: function (event) { patchRule(rule.id, parseRuleSpec(Object.assign({}, rule, { hosts: event.target.value }))) },
|
|
2760
|
+
}),
|
|
2761
|
+
h('input', {
|
|
2762
|
+
type: 'text', value: rule.ports, placeholder: '端口:1521, 1000-1010(全部写 *;空=本行不生效)',
|
|
2763
|
+
style: Object.assign({}, field, { width: 104 }), title: '支持逗号分隔与范围',
|
|
2764
|
+
onInput: function (event) { patchRule(rule.id, parseRuleSpec(Object.assign({}, rule, { ports: event.target.value }))) },
|
|
2765
|
+
}),
|
|
2766
|
+
// No mapping switch: whether a program can take a SOCKS address decides
|
|
2767
|
+
// it (SOCKS-aware → nothing to map; everything else → mapped on the same
|
|
2768
|
+
// port), so the row only reports HOW the traffic leaves. "直连" used to be
|
|
2769
|
+
// shown here and read like "no proxy at all" — it always means SOCKS.
|
|
2770
|
+
h('span', {
|
|
2771
|
+
style: { fontSize: 10, opacity: 0.75, whiteSpace: 'nowrap' },
|
|
2772
|
+
'data-proxy-map': rule.shadow === true ? 'mapped' : 'socks',
|
|
2773
|
+
title: rule.shadow === true
|
|
2774
|
+
? '这个程序不能配 SOCKS(如 Navicat / JDBC),自动映射 127.0.0.1:同端口走代理'
|
|
2775
|
+
: (rule.socksCapable === true
|
|
2776
|
+
? '这个程序能直接吃 SOCKS 地址(ProxyBridge 按进程拦截,或启动时注入),无需映射'
|
|
2777
|
+
: '通过 SOCKS 代理(ProxyBridge 按进程拦截,或启动时注入),无需映射'),
|
|
2778
|
+
}, rule.shadow === true ? '127.0.0.1' + portSuffix(rule) : 'SOCKS'),
|
|
2779
|
+
rule.source === 'yds'
|
|
2780
|
+
? h('span', { style: { fontSize: 10, opacity: 0.55 }, title: 'yds start 自动生成的规则:删除后会在下次启动时重新写入' }, 'yds 自动')
|
|
2781
|
+
: null,
|
|
2782
|
+
rule.origin !== undefined && rule.origin !== ''
|
|
2783
|
+
? h('span', {
|
|
2784
|
+
style: { fontSize: 10, opacity: 0.55, whiteSpace: 'nowrap' },
|
|
2785
|
+
title: '这一行由哪个工作区写入(仅供参考,规则本身是整机生效的):' + rule.workspace,
|
|
2786
|
+
}, '来源 ' + rule.origin)
|
|
2787
|
+
: null,
|
|
2788
|
+
h('button', {
|
|
2789
|
+
type: 'button', style: { ...field, width: 26, cursor: 'pointer' }, title: '删除这一行',
|
|
2790
|
+
onClick: function () { dropRule(rule.id) },
|
|
2791
|
+
}, '×'),
|
|
2792
|
+
// A row can look "on" and still apply to nothing: enabled is only one of
|
|
2793
|
+
// four required inputs (program / IP / port, with `*` for "everything").
|
|
2794
|
+
rule.enabled === true && effective === false
|
|
2795
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 11, color: '#d9534f' }, 'data-proxy-ineffective': rule.id },
|
|
2796
|
+
'不生效:' + (ineffectiveReason || '缺少程序 / IP / 端口'))
|
|
2797
|
+
: null,
|
|
2798
|
+
invalid
|
|
2799
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 11, color: '#d9534f' } },
|
|
2800
|
+
(rule.hostsInvalid || []).length > 0 ? '无效 IP:' + rule.hostsInvalid.join(', ') + ' ' : '',
|
|
2801
|
+
(rule.portsInvalid || []).length > 0 ? '无效端口:' + rule.portsInvalid.join(', ') : '')
|
|
2802
|
+
: null)
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
/**
|
|
2806
|
+
* One footer button shape for every action.
|
|
2807
|
+
*
|
|
2808
|
+
* `S.buttonOff` is the DISABLED style (opacity .4), so painting an enabled
|
|
2809
|
+
* action with it made 启动/停止 look equally dead — you could not tell which
|
|
2810
|
+
* one the dialog wanted you to press. Here the box is identical for all
|
|
2811
|
+
* three and only the actionable one is filled.
|
|
2812
|
+
* @param {{label: string, primary?: boolean, disabled?: boolean, onClick: Function, action: string, title?: string}} spec - button.
|
|
2813
|
+
* @returns {object} the button element.
|
|
2814
|
+
*/
|
|
2815
|
+
function dialogButton(spec) {
|
|
2816
|
+
var filled = spec.primary === true && spec.disabled !== true
|
|
2817
|
+
return h('button', {
|
|
2818
|
+
type: 'button',
|
|
2819
|
+
disabled: spec.disabled === true,
|
|
2820
|
+
'data-proxy-action': spec.action,
|
|
2821
|
+
title: spec.title || '',
|
|
2822
|
+
style: {
|
|
2823
|
+
font: 'inherit', fontFamily: 'inherit', fontSize: 'inherit', lineHeight: 1.4,
|
|
2824
|
+
minWidth: 84, height: 28, padding: '0 14px', borderRadius: 4, boxSizing: 'border-box',
|
|
2825
|
+
cursor: spec.disabled === true ? 'default' : 'pointer',
|
|
2826
|
+
opacity: spec.disabled === true ? 0.45 : 1,
|
|
2827
|
+
color: filled ? '#fff' : 'inherit',
|
|
2828
|
+
background: filled ? 'var(--dsw-accent, #2f6feb)' : 'transparent',
|
|
2829
|
+
border: '1px solid ' + (filled ? 'var(--dsw-accent, #2f6feb)' : 'color-mix(in srgb, currentColor 34%, transparent)'),
|
|
2830
|
+
},
|
|
2831
|
+
onClick: spec.onClick,
|
|
2832
|
+
}, spec.label)
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
var running = view !== null && view.running === true
|
|
2836
|
+
var statusLine = view === null
|
|
2837
|
+
? (state.loading ? '读取中…' : '')
|
|
2838
|
+
: (running ? '运行中' : '未运行')
|
|
2839
|
+
+ (view.shared === true ? ' · 全机共享' : '')
|
|
2840
|
+
return h('div', {
|
|
2841
|
+
style: { position: 'fixed', inset: 0, zIndex: 1000, background: 'color-mix(in srgb, #000 38%, transparent)', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
2842
|
+
'data-proxy-dialog': '1',
|
|
2843
|
+
onMouseDown: onClose,
|
|
2844
|
+
},
|
|
2845
|
+
// Every control (including the program picker's filter box and the row
|
|
2846
|
+
// buttons) must agree with the card's font; form controls ignore
|
|
2847
|
+
// inheritance unless told otherwise.
|
|
2848
|
+
h('style', { key: 'proxy-dialog-font' },
|
|
2849
|
+
'[data-proxy-dialog] input, [data-proxy-dialog] button, [data-proxy-dialog] select, [data-proxy-dialog] textarea { font-family: inherit; font-size: inherit; }'),
|
|
2850
|
+
h('div', {
|
|
2851
|
+
style: Object.assign({}, S.card || {}, {
|
|
2852
|
+
width: 760, maxWidth: '94vw', padding: 14, borderRadius: 8, display: 'flex', flexDirection: 'column', gap: 2,
|
|
2853
|
+
background: 'var(--dsw-surface, #ffffff)', color: 'inherit', boxShadow: '0 18px 40px rgba(0,0,0,.35)', maxHeight: '88vh', overflowY: 'auto',
|
|
2854
|
+
// One dialog in two shells: the sidebar inherits the DSH shell's font,
|
|
2855
|
+
// the standalone window the IDE chrome's. Pin the chrome stack so both
|
|
2856
|
+
// shapes measure identically (`--dsw-font-mono` is IDE-page-only).
|
|
2857
|
+
fontFamily: CHROME_FAMILY, fontSize: DEFAULT_FONT_SIZE + 'px',
|
|
2858
|
+
}),
|
|
2859
|
+
onMouseDown: function (event) { event.stopPropagation() },
|
|
2860
|
+
},
|
|
2861
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
2862
|
+
h('span', { style: { fontWeight: 600 } }, '代理'),
|
|
2863
|
+
h('span', { style: S.spacer }),
|
|
2864
|
+
h('button', {
|
|
2865
|
+
type: 'button', 'data-proxy-close': '1', title: '关闭', onClick: function () { closeDialog() },
|
|
2866
|
+
style: { font: 'inherit', fontFamily: 'inherit', fontSize: 'inherit', width: 24, height: 24, lineHeight: 1, padding: 0, cursor: 'pointer', color: 'inherit', background: 'transparent', border: '1px solid transparent', borderRadius: 4 },
|
|
2867
|
+
}, '×')),
|
|
2868
|
+
h('div', {
|
|
2869
|
+
style: Object.assign({}, tiny, { marginTop: 2, lineHeight: 1.5 }),
|
|
2870
|
+
title: view !== null && typeof view.configPath === 'string'
|
|
2871
|
+
? '全机一份配置与一个引擎:' + view.configPath + '(规则按工作区打标签,端口只绑一次)'
|
|
2872
|
+
: '',
|
|
2873
|
+
}, statusLine),
|
|
2874
|
+
// A previous dsh left this engine behind (the Ctrl+C leak before the
|
|
2875
|
+
// lifecycle fix). The host adopted it on mount, so it keeps working —
|
|
2876
|
+
// say so, and offer the stop instead of leaving the user to wonder who
|
|
2877
|
+
// started it.
|
|
2878
|
+
view !== null && view.inherited === true
|
|
2879
|
+
? h('div', {
|
|
2880
|
+
'data-proxy-inherited': '1',
|
|
2881
|
+
style: {
|
|
2882
|
+
marginTop: 6, padding: '6px 8px', borderRadius: 4, fontSize: 11, lineHeight: 1.5,
|
|
2883
|
+
display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap',
|
|
2884
|
+
border: '1px solid color-mix(in srgb, #c98a1b 45%, transparent)',
|
|
2885
|
+
background: 'color-mix(in srgb, #c98a1b 10%, transparent)',
|
|
2886
|
+
},
|
|
2887
|
+
},
|
|
2888
|
+
h('span', null,
|
|
2889
|
+
'代理由上一个会话启动(引擎 pid ' + (view.inheritedPid || view.pid || '?')
|
|
2890
|
+
+ (view.inheritedFrom > 0 ? ',原 dsh pid ' + view.inheritedFrom : '')
|
|
2891
|
+
+ '),本会话已接管:可直接使用,或在这里停止。'),
|
|
2892
|
+
h('span', { style: S.spacer }),
|
|
2893
|
+
dialogButton({
|
|
2894
|
+
action: 'stop-inherited',
|
|
2895
|
+
label: state.busy === 'stop' ? '停止中…' : '停止代理',
|
|
2896
|
+
disabled: state.busy !== '',
|
|
2897
|
+
onClick: function () { act('stop') },
|
|
2898
|
+
title: '停止上一个会话留下的代理引擎,并清除系统层拦截与 git 代理',
|
|
2899
|
+
}))
|
|
2900
|
+
: null,
|
|
2901
|
+
draft === null
|
|
2902
|
+
? h('div', { style: { marginTop: 10, fontSize: 12, display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
2903
|
+
state.loading ? '读取中…' : null,
|
|
2904
|
+
state.loading ? null : h('span', { style: { color: '#d9534f' } }, state.error || '没有配置'),
|
|
2905
|
+
state.loading ? null : h('button', {
|
|
2906
|
+
type: 'button', style: Object.assign({}, field, { width: 'auto', cursor: 'pointer' }),
|
|
2907
|
+
onClick: function () { load() },
|
|
2908
|
+
}, '重试'))
|
|
2909
|
+
: h('div', null,
|
|
2910
|
+
// 上部:代理地址
|
|
2911
|
+
h('div', { style: { display: 'flex', alignItems: 'flex-end', gap: 8, marginTop: 10, flexWrap: 'wrap' } },
|
|
2912
|
+
addressField('代理地址(SOCKS5 主机)', draft.socks.host, '如 10.3.91.121',
|
|
2913
|
+
function (event) { setState(function (prev) { return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { socks: Object.assign({}, prev.draft.socks, { host: event.target.value }) }) }) }) }),
|
|
2914
|
+
addressField('端口', draft.socks.port, '1080',
|
|
2915
|
+
function (event) { setState(function (prev) { return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { socks: Object.assign({}, prev.draft.socks, { port: event.target.value }) }) }) }) }, 90),
|
|
2916
|
+
addressField('本地监听端口', draft.listenPort, '11081',
|
|
2917
|
+
function (event) { setState(function (prev) { return Object.assign({}, prev, { draft: Object.assign({}, prev.draft, { listenPort: event.target.value }) }) }) }, 110)),
|
|
2918
|
+
h('div', { style: Object.assign({}, tiny, { marginTop: 6, lineHeight: 1.5 }) },
|
|
2919
|
+
'规则整机生效(不区分工作区)。主路 ProxyBridge 按进程名在系统层拦截;'
|
|
2920
|
+
+ '未运行时退回注入与 127.0.0.1 映射。'),
|
|
2921
|
+
// 系统层拦截器(ProxyBridge):主路,两端各自独立
|
|
2922
|
+
redirectorBlock(),
|
|
2923
|
+
// 下部:规则列表
|
|
2924
|
+
state.error !== '' && draft !== null
|
|
2925
|
+
? h('div', { style: { marginTop: 8, fontSize: 11, color: '#d9534f' } }, state.error)
|
|
2926
|
+
: null,
|
|
2927
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 } },
|
|
2928
|
+
h('span', { style: { fontWeight: 600, fontSize: 12 } }, '代理规则'),
|
|
2929
|
+
h('span', { style: tiny }, '程序 / IP / 端口'),
|
|
2930
|
+
h('span', { style: S.spacer }),
|
|
2931
|
+
h('button', {
|
|
2932
|
+
type: 'button', 'data-proxy-add': '1', onClick: addRule,
|
|
2933
|
+
style: { font: 'inherit', fontFamily: 'inherit', fontSize: 'inherit', height: 26, padding: '0 10px', cursor: 'pointer', color: 'inherit', background: 'transparent', border: '1px solid color-mix(in srgb, currentColor 34%, transparent)', borderRadius: 4 },
|
|
2934
|
+
}, '+ 添加规则')),
|
|
2935
|
+
draft.rules.length === 0
|
|
2936
|
+
? h('div', { style: Object.assign({}, tiny, { marginTop: 6 }) }, '没有规则:没有程序走代理')
|
|
2937
|
+
: h('div', { style: { marginTop: 4 } }, draft.rules.map(ruleRow)),
|
|
2938
|
+
(state.note === '' ? null : h('div', { style: { fontSize: 11, opacity: 0.7, marginTop: 8 } }, state.note)),
|
|
2939
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12, flexWrap: 'wrap' } },
|
|
2940
|
+
h('span', { style: Object.assign({}, tiny, { minWidth: 64 }), 'data-proxy-autosave': state.saving === true ? 'saving' : 'saved' },
|
|
2941
|
+
state.saving === true ? '保存中…' : '自动保存'),
|
|
2942
|
+
dialogButton({
|
|
2943
|
+
action: 'start', label: state.busy === 'start' ? '启动中…' : '启动',
|
|
2944
|
+
// Exactly one of start/stop is the next thing to do, so exactly one
|
|
2945
|
+
// of them is filled: grey is reserved for "nothing to do here".
|
|
2946
|
+
primary: !running,
|
|
2947
|
+
disabled: state.busy !== '' || running,
|
|
2948
|
+
onClick: function () { act('start') },
|
|
2949
|
+
title: '启动代理引擎 + 系统层拦截(需要时弹提权)+ 写入 git 代理',
|
|
2950
|
+
}),
|
|
2951
|
+
dialogButton({
|
|
2952
|
+
action: 'stop', label: state.busy === 'stop' ? '停止中…' : '停止',
|
|
2953
|
+
primary: running,
|
|
2954
|
+
disabled: state.busy !== '' || !running,
|
|
2955
|
+
onClick: function () { act('stop') },
|
|
2956
|
+
title: '停止引擎、系统层拦截,并清除 git 代理',
|
|
2957
|
+
}),
|
|
2958
|
+
// No separate git buttons: the git entry is written on 启动 and cleared
|
|
2959
|
+
// on 停止 (and on host exit) together with the engine and the
|
|
2960
|
+
// redirector, so one control governs the whole tunnel.
|
|
2961
|
+
h('span', { style: Object.assign({}, tiny, { marginLeft: 'auto' }) },
|
|
2962
|
+
'启动同时写入 git 代理,停止同时清除')))),
|
|
2963
|
+
// The program picker is its own dialog on top of this one: a tree with two
|
|
2964
|
+
// lazily-loaded roots does not fit inside a rule row.
|
|
2965
|
+
state.pickFor === ''
|
|
2966
|
+
? null
|
|
2967
|
+
: h('div', {
|
|
2968
|
+
style: { position: 'fixed', inset: 0, zIndex: 1001, background: 'color-mix(in srgb, #000 45%, transparent)', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
2969
|
+
'data-proxy-picker-dialog': '1',
|
|
2970
|
+
onMouseDown: function (event) { event.stopPropagation(); closePicker() },
|
|
2971
|
+
},
|
|
2972
|
+
h('div', { onMouseDown: function (event) { event.stopPropagation() } },
|
|
2973
|
+
pickerCard((state.draft === null ? { id: '', program: '' } : state.draft.rules.filter(function (rule) { return rule.id === state.pickFor })[0]) || { id: state.pickFor, program: '' })))
|
|
2974
|
+
)
|
|
2975
|
+
}
|
|
2976
|
+
|
|
1792
2977
|
/** Scaled CSS for viewers that paint their own font (CodeMirror pins 13px). */
|
|
1793
2978
|
function viewerFontCss(size) {
|
|
1794
2979
|
return '[data-workbench="ris-ide"] .cm-editor{font-size:' + size + 'px !important}'
|
|
@@ -2333,6 +3518,10 @@ window.__ModuleLoader__.load({
|
|
|
2333
3518
|
setFindIndex(0)
|
|
2334
3519
|
}
|
|
2335
3520
|
setFindOpen(true)
|
|
3521
|
+
// `findOpen` may already be true (the bar is open, focus is in the log
|
|
3522
|
+
// body), so the focus effect below would not run again — put the caret
|
|
3523
|
+
// in the find field right here, like the CodeMirror panel does.
|
|
3524
|
+
if (findInputRef.current !== null) findInputRef.current.focus()
|
|
2336
3525
|
return
|
|
2337
3526
|
}
|
|
2338
3527
|
if (event.key === 'Escape' && findOpen) {
|
|
@@ -3687,6 +4876,28 @@ window.__ModuleLoader__.load({
|
|
|
3687
4876
|
return out
|
|
3688
4877
|
}
|
|
3689
4878
|
|
|
4879
|
+
/**
|
|
4880
|
+
* Whether `child` is `parent` itself or lives below it.
|
|
4881
|
+
*
|
|
4882
|
+
* The file tree can be re-rooted into a subfolder (context menu 进入 / a folder
|
|
4883
|
+
* search hit), so `activeRoot` is NOT always the workspace root: locating a
|
|
4884
|
+
* file then has to ask whether the file is reachable from where the tree is
|
|
4885
|
+
* currently rooted at all.
|
|
4886
|
+
* @param {string} parent - absolute directory (trailing slashes ignored).
|
|
4887
|
+
* @param {string} child - absolute path.
|
|
4888
|
+
* @returns {boolean} true when `child` is `parent` or inside it.
|
|
4889
|
+
*/
|
|
4890
|
+
function pathWithin(parent, child) {
|
|
4891
|
+
var raw = String(parent === undefined || parent === null ? '' : parent).replace(/\\/g, '/')
|
|
4892
|
+
var value = String(child === undefined || child === null ? '' : child).replace(/\\/g, '/')
|
|
4893
|
+
var base = raw.replace(/\/+$/, '')
|
|
4894
|
+
// The filesystem root is the one parent whose trailing slash IS its name.
|
|
4895
|
+
if (base === '' && raw !== '') base = '/'
|
|
4896
|
+
if (base === '' || value === '') return false
|
|
4897
|
+
if (base === '/') return value.charAt(0) === '/'
|
|
4898
|
+
return value === base || value.indexOf(base + '/') === 0
|
|
4899
|
+
}
|
|
4900
|
+
|
|
3690
4901
|
/**
|
|
3691
4902
|
* The visible entry of ONE level that contains `filePath` (its own path, or a
|
|
3692
4903
|
* prefix of it). Compaction means a single entry can stand for a whole raw
|
|
@@ -3916,11 +5127,31 @@ window.__ModuleLoader__.load({
|
|
|
3916
5127
|
* (`cn.com.ris.cloud.model`) is expanded as the ONE row it is instead of
|
|
3917
5128
|
* walking absolute-path ancestors that no row represents — the old walk left
|
|
3918
5129
|
* the branch empty. Depth is capped and a visited set stops on any repeat.
|
|
5130
|
+
*
|
|
5131
|
+
* Two things used to make the button「sometimes do nothing」:
|
|
5132
|
+
* - the walk read its per-level key from the loop variable inside the
|
|
5133
|
+
* `setExpanded` updater, and React runs that updater LATER — by then the
|
|
5134
|
+
* variable held a deeper path, so the top ancestors never expanded and
|
|
5135
|
+
* the row never existed (the same trap `fetchLevel` documents). The chain
|
|
5136
|
+
* is collected in an array and committed in ONE update instead.
|
|
5137
|
+
* - a tree re-rooted into a subfolder (进入 / a folder search hit) walked
|
|
5138
|
+
* from that subfolder only, so a file outside it was unreachable and the
|
|
5139
|
+
* click silently did nothing. The walk now falls back to the workspace
|
|
5140
|
+
* root, which also re-roots the tree there.
|
|
3919
5141
|
* @param {string} target - file path (relative to `cwd` or absolute).
|
|
3920
5142
|
*/
|
|
3921
5143
|
async function locate(target) {
|
|
3922
5144
|
var filePath = absolutePath(cwd, target)
|
|
3923
|
-
var
|
|
5145
|
+
var workspaceRoot = absolutePath(cwd, rootPath)
|
|
5146
|
+
var startRoot = absolutePath(cwd, activeRoot)
|
|
5147
|
+
// The tree only walks from its current root; a file outside it is only
|
|
5148
|
+
// reachable from the workspace root, so the tree follows the locate.
|
|
5149
|
+
if (!pathWithin(startRoot, filePath) && pathWithin(workspaceRoot, filePath)) {
|
|
5150
|
+
startRoot = workspaceRoot
|
|
5151
|
+
setRootTrail([])
|
|
5152
|
+
}
|
|
5153
|
+
var chain = []
|
|
5154
|
+
var current = startRoot
|
|
3924
5155
|
var visited = {}
|
|
3925
5156
|
for (var guard = 0; guard < 64; guard += 1) {
|
|
3926
5157
|
if (visited[current] === true) break
|
|
@@ -3942,9 +5173,22 @@ window.__ModuleLoader__.load({
|
|
|
3942
5173
|
if (levels[descend] === undefined) {
|
|
3943
5174
|
try { await fetchLevel(descend) } catch (problem) { /* best effort */ }
|
|
3944
5175
|
}
|
|
3945
|
-
|
|
5176
|
+
chain.push(descend)
|
|
3946
5177
|
current = descend
|
|
3947
5178
|
}
|
|
5179
|
+
if (chain.length > 0) {
|
|
5180
|
+
// `chain` is frozen once the walk is done, and the updater reads it (never
|
|
5181
|
+
// the loop variable) — every ancestor of the file is open in one commit.
|
|
5182
|
+
setExpanded(function (prev) {
|
|
5183
|
+
var state = Object.assign({}, prev)
|
|
5184
|
+
for (var index = 0; index < chain.length; index += 1) state[chain[index]] = true
|
|
5185
|
+
return state
|
|
5186
|
+
})
|
|
5187
|
+
}
|
|
5188
|
+
// The located file becomes the tree's selection: a folder that happened to
|
|
5189
|
+
// be selected before (a right click, a multi-selection) must not keep the
|
|
5190
|
+
// strong tint next to the file the editor is now showing.
|
|
5191
|
+
selectOne(filePath)
|
|
3948
5192
|
props.onOpen(filePath)
|
|
3949
5193
|
revealRow(filePath)
|
|
3950
5194
|
}
|
|
@@ -4120,6 +5364,12 @@ window.__ModuleLoader__.load({
|
|
|
4120
5364
|
var [batchConflict, setBatchConflict] = useState(null)
|
|
4121
5365
|
/** Pending delete confirmation: the entry to remove. */
|
|
4122
5366
|
var [pendingDelete, setPendingDelete] = useState(null)
|
|
5367
|
+
/**
|
|
5368
|
+
* A drag that landed on a folder: the move waits for 确认 (`{paths, dir}`).
|
|
5369
|
+
* Dropping used to relocate files on release, so a slip of the mouse (or a
|
|
5370
|
+
* drop meant for the editor) moved them with no way to notice in time.
|
|
5371
|
+
*/
|
|
5372
|
+
var [pendingMove, setPendingMove] = useState(null)
|
|
4123
5373
|
/** Clipboard for copy/cut: `{mode, items:[{path,isDir,name}]}`. */
|
|
4124
5374
|
var [clipboard, setClipboard] = useState(null)
|
|
4125
5375
|
var [selectedPath, setSelectedPath] = useState(null)
|
|
@@ -4135,6 +5385,7 @@ window.__ModuleLoader__.load({
|
|
|
4135
5385
|
var promptInputRef = useRef(null)
|
|
4136
5386
|
/** The delete dialog's 取消 button: focus target so Esc/Enter never fall to BODY. */
|
|
4137
5387
|
var confirmCancelRef = useRef(null)
|
|
5388
|
+
var moveCancelRef = useRef(null)
|
|
4138
5389
|
/** Auto-retry bookkeeping for an unreachable/reloading host. */
|
|
4139
5390
|
var treeRetryRef = useRef({ attempt: 0, timer: null })
|
|
4140
5391
|
var levelsRef = useRef(levels)
|
|
@@ -4409,6 +5660,24 @@ window.__ModuleLoader__.load({
|
|
|
4409
5660
|
}
|
|
4410
5661
|
}, [pendingDelete])
|
|
4411
5662
|
|
|
5663
|
+
// Same contract for the move confirmation: 取消 owns focus, Esc cancels,
|
|
5664
|
+
// and the tree gets the keyboard back when it closes.
|
|
5665
|
+
useEffect(function () {
|
|
5666
|
+
if (pendingMove === null) return undefined
|
|
5667
|
+
var cancel = moveCancelRef.current
|
|
5668
|
+
if (cancel !== null && cancel !== undefined && typeof cancel.focus === 'function') cancel.focus()
|
|
5669
|
+
function onKey(event) {
|
|
5670
|
+
if (event.key !== 'Escape') return
|
|
5671
|
+
event.preventDefault()
|
|
5672
|
+
setPendingMove(null)
|
|
5673
|
+
}
|
|
5674
|
+
document.addEventListener('keydown', onKey, true)
|
|
5675
|
+
return function () {
|
|
5676
|
+
document.removeEventListener('keydown', onKey, true)
|
|
5677
|
+
focusTreeRoot()
|
|
5678
|
+
}
|
|
5679
|
+
}, [pendingMove])
|
|
5680
|
+
|
|
4412
5681
|
// The selection follows the disk: a path that vanished (deleted, moved away,
|
|
4413
5682
|
// watcher reload, folded folder) must leave the batch, or the status bar and
|
|
4414
5683
|
// the delete dialog count ghosts (PM review P1-3, found live: 「删除 3 项?」
|
|
@@ -5297,13 +6566,44 @@ window.__ModuleLoader__.load({
|
|
|
5297
6566
|
}
|
|
5298
6567
|
}
|
|
5299
6568
|
/**
|
|
5300
|
-
*
|
|
5301
|
-
*
|
|
6569
|
+
* Paths a drop on `dirPath` would actually move: skips the folder itself,
|
|
6570
|
+
* rows already in it, and a folder dragged into its own subtree.
|
|
6571
|
+
* @param {string[]} paths - dragged absolute paths.
|
|
6572
|
+
* @param {string} dirPath - drop directory.
|
|
6573
|
+
* @returns {string[]} the paths worth confirming.
|
|
6574
|
+
*/
|
|
6575
|
+
function movablePaths(paths, dirPath) {
|
|
6576
|
+
var trimmedDir = dirPath.replace(/[\\/]+$/, '')
|
|
6577
|
+
var movable = []
|
|
6578
|
+
for (var index = 0; index < paths.length; index += 1) {
|
|
6579
|
+
var from = paths[index]
|
|
6580
|
+
if (typeof from !== 'string' || from === '') continue
|
|
6581
|
+
if (from === trimmedDir || parentOf(from) === trimmedDir) continue
|
|
6582
|
+
var entry = findEntry(from)
|
|
6583
|
+
if (entry !== undefined && entry !== null && entry.isDir === true && trimmedDir.indexOf(from + '/') === 0) continue
|
|
6584
|
+
movable.push(from)
|
|
6585
|
+
}
|
|
6586
|
+
return movable
|
|
6587
|
+
}
|
|
6588
|
+
|
|
6589
|
+
/** A drop inside the tree: ask first, announce exactly what moves where. */
|
|
6590
|
+
function requestMove(paths, dirPath) {
|
|
6591
|
+
var movable = movablePaths(paths, dirPath)
|
|
6592
|
+
setDropTarget(null)
|
|
6593
|
+
if (movable.length === 0) return
|
|
6594
|
+
setSelectedPaths(movable)
|
|
6595
|
+
setSelectedPath(movable[movable.length - 1])
|
|
6596
|
+
setPendingMove({ paths: movable, dir: dirPath })
|
|
6597
|
+
}
|
|
6598
|
+
|
|
6599
|
+
/**
|
|
6600
|
+
* Move rows (one confirmed drag of a row, or of the whole multi-selection)
|
|
6601
|
+
* into `dirPath`.
|
|
5302
6602
|
*
|
|
5303
|
-
* Every collision becomes a `… 副本` name — a
|
|
5304
|
-
* dialog — and the batch is reported in one toast. Rows
|
|
5305
|
-
* target (or a directory dropped into itself) are
|
|
5306
|
-
* entry (Ctrl+Z) puts everything back.
|
|
6603
|
+
* Every collision becomes a `… 副本` name — even a confirmed move must not
|
|
6604
|
+
* stop half way for a dialog — and the batch is reported in one toast. Rows
|
|
6605
|
+
* already inside the target (or a directory dropped into itself) are
|
|
6606
|
+
* skipped. One compound undo entry (Ctrl+Z) puts everything back.
|
|
5307
6607
|
* @param {string[]} paths - absolute source paths, in drop order.
|
|
5308
6608
|
* @param {string} dirPath - absolute destination directory.
|
|
5309
6609
|
*/
|
|
@@ -5405,7 +6705,7 @@ window.__ModuleLoader__.load({
|
|
|
5405
6705
|
|| active === root
|
|
5406
6706
|
)
|
|
5407
6707
|
if (!inside) return
|
|
5408
|
-
if (prompt !== null || pendingDelete !== null) return
|
|
6708
|
+
if (prompt !== null || pendingDelete !== null || pendingMove !== null) return
|
|
5409
6709
|
if (event.key === 'Escape' && selectedPaths.length > 1) {
|
|
5410
6710
|
// Esc drops the batch but keeps the primary row: batch ops are silent,
|
|
5411
6711
|
// so there must be a one-key way out of a mis-clicked selection.
|
|
@@ -5570,12 +6870,18 @@ window.__ModuleLoader__.load({
|
|
|
5570
6870
|
seen[entry.path] = true
|
|
5571
6871
|
var open = expanded[entry.path] === true
|
|
5572
6872
|
var isActive = props.activePath === entry.path
|
|
5573
|
-
var isRevealed = reveal !== null && reveal.path === entry.path
|
|
5574
6873
|
var isSelected = selectedPath === entry.path
|
|
5575
6874
|
&& (entry.isDir === true || !Array.isArray(props.openFiles) || props.openFiles.indexOf(entry.path) !== -1)
|
|
5576
6875
|
// Extra rows of a multi-selection: highlighted but NOT the primary row
|
|
5577
6876
|
// (menus, rename/delete and the paste target keep acting on `selectedPath`).
|
|
5578
6877
|
var isMulti = selectedPaths.length > 1 && selectedPaths.indexOf(entry.path) !== -1 && !isSelected
|
|
6878
|
+
// The STRONG row tint means one thing only: this is the file the editor is
|
|
6879
|
+
// showing (or the directory a rename/delete/paste is aimed at). A locate
|
|
6880
|
+
// used to paint the located row and keep it lit until the next locate, so
|
|
6881
|
+
// old files stayed highlighted after switching tabs; a file row that is
|
|
6882
|
+
// merely selected (right click, Ctrl+click) now wears the softer multi
|
|
6883
|
+
// tint, keeping the tree's current-file highlight in step with the tabs.
|
|
6884
|
+
var isCurrent = isActive || (isSelected && entry.isDir === true)
|
|
5579
6885
|
// Dropping ON a file means "into the folder that file lives in" — a row
|
|
5580
6886
|
// is always a drop target; only the expand/collapse toggle is dir-only.
|
|
5581
6887
|
var dropDir = entry.isDir === true ? entry.path : parentOf(entry.path)
|
|
@@ -5583,14 +6889,14 @@ window.__ModuleLoader__.load({
|
|
|
5583
6889
|
out.push(h('div', {
|
|
5584
6890
|
key: entry.path,
|
|
5585
6891
|
style: Object.assign({},
|
|
5586
|
-
|
|
6892
|
+
isCurrent ? S.treeRowOn : (isMulti || isSelected ? S.treeRowMulti : S.treeRow),
|
|
5587
6893
|
{
|
|
5588
6894
|
paddingLeft: indent,
|
|
5589
6895
|
boxShadow: isDropTarget ? 'inset 0 0 0 1px #d29922' : undefined,
|
|
5590
6896
|
}),
|
|
5591
6897
|
title: entry.path + (entry.isDir === true ? '(点击:把这个目录当作文件树根 / 三角:展开折叠)' : '') + '(Ctrl+点击 多选 / 右键:新建/粘贴/复制/剪切/删除/刷新)',
|
|
5592
6898
|
'data-tree-path': entry.path,
|
|
5593
|
-
'data-tree-
|
|
6899
|
+
'data-tree-current': isCurrent ? '1' : undefined,
|
|
5594
6900
|
'data-tree-selected': isSelected ? '1' : undefined,
|
|
5595
6901
|
'data-tree-multi': isMulti ? '1' : undefined,
|
|
5596
6902
|
'data-tree-drop': isDropTarget ? '1' : undefined,
|
|
@@ -5630,8 +6936,8 @@ window.__ModuleLoader__.load({
|
|
|
5630
6936
|
var paths = dragPaths(event.dataTransfer)
|
|
5631
6937
|
if (paths.length === 0 && selectedPath !== null) paths = [selectedPath]
|
|
5632
6938
|
paths = paths.filter(function (item) { return item !== entry.path })
|
|
5633
|
-
if (paths.length > 0)
|
|
5634
|
-
setDropTarget(null)
|
|
6939
|
+
if (paths.length > 0) requestMove(paths, dropDir)
|
|
6940
|
+
else setDropTarget(null)
|
|
5635
6941
|
},
|
|
5636
6942
|
onClick: function (event) {
|
|
5637
6943
|
var additive = event.ctrlKey === true || event.metaKey === true
|
|
@@ -5995,10 +7301,46 @@ window.__ModuleLoader__.load({
|
|
|
5995
7301
|
]
|
|
5996
7302
|
}
|
|
5997
7303
|
|
|
7304
|
+
/** The move confirmation: what moves where, 取消 by default. */
|
|
7305
|
+
function renderTreeMoveConfirm() {
|
|
7306
|
+
if (pendingMove === null) return null
|
|
7307
|
+
var paths = pendingMove.paths
|
|
7308
|
+
var dir = pendingMove.dir
|
|
7309
|
+
var first = findEntry(paths[0])
|
|
7310
|
+
var isDir = first !== undefined && first !== null && first.isDir === true
|
|
7311
|
+
var label = paths.length > 1
|
|
7312
|
+
? '移动 ' + paths.length + ' 项?'
|
|
7313
|
+
: (isDir ? '移动这个文件夹?' : '移动这个文件?')
|
|
7314
|
+
var detail = paths.map(function (item) { return fileBaseName(item) + (findEntry(item) !== undefined && findEntry(item) !== null && findEntry(item).isDir === true ? '/' : '') }).join('、')
|
|
7315
|
+
var anchor = dialogAnchor(360, 176)
|
|
7316
|
+
return [
|
|
7317
|
+
h('div', { key: 'move-mask', style: { position: 'fixed', inset: 0, zIndex: 949, background: 'transparent' }, 'data-tree-move-mask': '1', onClick: function () { setPendingMove(null) } }),
|
|
7318
|
+
h('div', {
|
|
7319
|
+
key: 'move-card',
|
|
7320
|
+
style: { position: 'fixed', left: anchor.left, top: anchor.top, zIndex: 950, width: 360, maxWidth: '92vw', background: 'Canvas', color: 'inherit', border: '1px solid color-mix(in srgb, currentColor 25%, transparent)', borderRadius: 6, boxShadow: '0 18px 48px rgba(0,0,0,0.4)', padding: 10, display: 'flex', flexDirection: 'column', gap: 8, fontFamily: 'system-ui, sans-serif', fontSize: 12 },
|
|
7321
|
+
'data-tree-move-confirm': '1',
|
|
7322
|
+
},
|
|
7323
|
+
h('div', { style: { fontWeight: 600 } }, label),
|
|
7324
|
+
h('div', { style: { opacity: 0.75, wordBreak: 'break-all' } }, detail),
|
|
7325
|
+
h('div', { style: { opacity: 0.6, wordBreak: 'break-all' } }, '移动到:' + dir),
|
|
7326
|
+
h('div', { style: { opacity: 0.6 } }, '移动后可按 Ctrl+Z 撤销'),
|
|
7327
|
+
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 6 } },
|
|
7328
|
+
h('button', { type: 'button', style: S.buttonOff, ref: moveCancelRef, 'data-tree-move-cancel': '1', onClick: function () { setPendingMove(null) } }, '取消'),
|
|
7329
|
+
h('button', {
|
|
7330
|
+
type: 'button', style: S.button, 'data-tree-move-ok': '1',
|
|
7331
|
+
onClick: function () {
|
|
7332
|
+
var pending = pendingMove
|
|
7333
|
+
setPendingMove(null)
|
|
7334
|
+
if (pending !== null) void moveEntriesInto(pending.paths, pending.dir)
|
|
7335
|
+
},
|
|
7336
|
+
}, '移动'))),
|
|
7337
|
+
]
|
|
7338
|
+
}
|
|
7339
|
+
|
|
5998
7340
|
// Freeze the anchor once per dialog opening and release it when the last
|
|
5999
7341
|
// dialog closes. Assigning during render is safe here: it only pins the
|
|
6000
7342
|
// point the JSX below already reads; it never drives rendering.
|
|
6001
|
-
var anyDialogOpen = prompt !== null || pendingDelete !== null || batchConflict !== null
|
|
7343
|
+
var anyDialogOpen = prompt !== null || pendingDelete !== null || batchConflict !== null || pendingMove !== null
|
|
6002
7344
|
if (anyDialogOpen === false) dialogPointRef.current = null
|
|
6003
7345
|
else if (dialogPointRef.current === null && pointerRef.current !== null) dialogPointRef.current = pointerRef.current
|
|
6004
7346
|
|
|
@@ -6044,7 +7386,7 @@ window.__ModuleLoader__.load({
|
|
|
6044
7386
|
var paths = dragPaths(event.dataTransfer)
|
|
6045
7387
|
if (paths.length === 0 && selectedPath !== null) paths = [selectedPath]
|
|
6046
7388
|
paths = paths.filter(function (item) { return parentOf(item) !== rootDir })
|
|
6047
|
-
if (paths.length > 0)
|
|
7389
|
+
if (paths.length > 0) requestMove(paths, rootDir)
|
|
6048
7390
|
},
|
|
6049
7391
|
}, rootTrail.length > 0
|
|
6050
7392
|
? h('div', {
|
|
@@ -6058,6 +7400,7 @@ window.__ModuleLoader__.load({
|
|
|
6058
7400
|
renderTreeMenu(),
|
|
6059
7401
|
renderTreePrompt(),
|
|
6060
7402
|
renderTreeConfirm(),
|
|
7403
|
+
renderTreeMoveConfirm(),
|
|
6061
7404
|
renderBatchConflict())
|
|
6062
7405
|
}
|
|
6063
7406
|
|
|
@@ -6077,6 +7420,7 @@ window.__ModuleLoader__.load({
|
|
|
6077
7420
|
var lines = text.split('\n')
|
|
6078
7421
|
var areaRef = useRef(null)
|
|
6079
7422
|
var [findOpen, setFindOpen] = useState(false)
|
|
7423
|
+
var findInputRef = useRef(null)
|
|
6080
7424
|
var [findText, setFindText] = useState('')
|
|
6081
7425
|
var [replaceText, setReplaceText] = useState('')
|
|
6082
7426
|
var [findNote, setFindNote] = useState(undefined)
|
|
@@ -6147,6 +7491,18 @@ window.__ModuleLoader__.load({
|
|
|
6147
7491
|
}
|
|
6148
7492
|
}
|
|
6149
7493
|
setFindOpen(true)
|
|
7494
|
+
// The bar's input is `autoFocus` only on the render that MOUNTS it: with
|
|
7495
|
+
// the bar already open a second Ctrl+F must still move the caret there.
|
|
7496
|
+
var findInput = findInputRef.current
|
|
7497
|
+
if (findInput !== null && findInput !== undefined) {
|
|
7498
|
+
findInput.focus()
|
|
7499
|
+
// Caret at the END, never a selection: the bar searches on every
|
|
7500
|
+
// keystroke below, and a selected term would be replaced by the first
|
|
7501
|
+
// one (the same bug the CodeMirror panel had).
|
|
7502
|
+
if (typeof findInput.setSelectionRange === 'function') {
|
|
7503
|
+
findInput.setSelectionRange(findInput.value.length, findInput.value.length)
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
6150
7506
|
return
|
|
6151
7507
|
}
|
|
6152
7508
|
if ((event.ctrlKey || event.metaKey) && (event.key === 's' || event.key === 'S')) {
|
|
@@ -6171,7 +7527,7 @@ window.__ModuleLoader__.load({
|
|
|
6171
7527
|
}
|
|
6172
7528
|
var findBar = findOpen ? h('div', { style: S.findBar, 'data-editor-find': '1' },
|
|
6173
7529
|
h('input', {
|
|
6174
|
-
style: S.findInput, value: findText, placeholder: '在文件中查找…', autoFocus: true,
|
|
7530
|
+
ref: findInputRef, style: S.findInput, value: findText, placeholder: '在文件中查找…', autoFocus: true,
|
|
6175
7531
|
'data-action': 'find-input',
|
|
6176
7532
|
onChange: function (event) { setFindText(event.target.value); setFindNote(undefined) },
|
|
6177
7533
|
onKeyDown: function (event) {
|
|
@@ -6425,7 +7781,11 @@ window.__ModuleLoader__.load({
|
|
|
6425
7781
|
* using the same `color-mix` / inherited-colour palette as the title bars, so
|
|
6426
7782
|
* light and dark themes both follow the page instead of hard-coding colours.
|
|
6427
7783
|
*/
|
|
6428
|
-
|
|
7784
|
+
// `z-index:20` (baseTheme says 300): the panel only has to sit above the editor's
|
|
7785
|
+
// own content layers, and 300 made it cover the workspace-search dropdown — that
|
|
7786
|
+
// dropdown is anchored in the pane's header row (`editorPaneHead`, z-index 30) and
|
|
7787
|
+
// opens right over the editor's top edge. The header row therefore has to win.
|
|
7788
|
+
var SEARCH_PANEL_CSS = '[data-workbench="ris-ide"] .cm-panels{background:color-mix(in srgb, Canvas 96%, transparent) !important;color:inherit !important;border:0 !important;z-index:20 !important}'
|
|
6429
7789
|
+ '[data-workbench="ris-ide"] .cm-panels-top{border-bottom:1px solid color-mix(in srgb, currentColor 12%, transparent) !important}'
|
|
6430
7790
|
+ '[data-workbench="ris-ide"] .cm-panels-bottom{border-top:1px solid color-mix(in srgb, currentColor 12%, transparent) !important}'
|
|
6431
7791
|
// The panel is the IDE's own (`ideFindPanel` in the editor chunk): two rows,
|
|
@@ -6917,6 +8277,8 @@ window.__ModuleLoader__.load({
|
|
|
6917
8277
|
})
|
|
6918
8278
|
}
|
|
6919
8279
|
function ProgramWorkbench(props) {
|
|
8280
|
+
/** The 「代理」 dialog (address + rule table); see `ProxyDialog`. */
|
|
8281
|
+
var [proxyOpen, setProxyOpen] = useState(false)
|
|
6920
8282
|
var scope = props ? props.scope : undefined
|
|
6921
8283
|
var tab = props ? props.tab : undefined
|
|
6922
8284
|
var meta = tab !== null && tab !== undefined && tab.meta !== null && typeof tab.meta === 'object' ? tab.meta : {}
|
|
@@ -7018,6 +8380,13 @@ var [ui, setUi] = useState(function () {
|
|
|
7018
8380
|
* query (or the `git grep` output) away, so the same row can be reopened.
|
|
7019
8381
|
*/
|
|
7020
8382
|
var searchCacheRef = useRef(new Map())
|
|
8383
|
+
/**
|
|
8384
|
+
* Bumped when the cached results for the CURRENT query must be thrown away
|
|
8385
|
+
* (Ctrl+R, or a save in this window). `searchCacheRef` is keyed by query text
|
|
8386
|
+
* only, while its payload is `git grep` output captured at one moment — so
|
|
8387
|
+
* without a kick an edited file kept showing the old hits forever.
|
|
8388
|
+
*/
|
|
8389
|
+
var [searchReload, setSearchReload] = useState(0)
|
|
7021
8390
|
/** A shortcut asked for the box: focus AND select its text once mounted. */
|
|
7022
8391
|
var [searchFocusNonce, setSearchFocusNonce] = useState(0)
|
|
7023
8392
|
var searchFocusPendingRef = useRef(false)
|
|
@@ -7511,8 +8880,6 @@ var [ui, setUi] = useState(function () {
|
|
|
7511
8880
|
}
|
|
7512
8881
|
return String(logPathValue).split('/').pop().replace(/\.log$/, '')
|
|
7513
8882
|
}
|
|
7514
|
-
/** Basename of a file path. */
|
|
7515
|
-
function shortName(path) { return String(path === undefined || path === null ? '' : path).split('/').pop() }
|
|
7516
8883
|
|
|
7517
8884
|
// The debug/log target follows the SELECTED debug tab, not "the first
|
|
7518
8885
|
// program": the workbench is workspace-level, several programs coexist.
|
|
@@ -7916,7 +9283,7 @@ var [ui, setUi] = useState(function () {
|
|
|
7916
9283
|
}
|
|
7917
9284
|
var next = capOpenFiles(openFiles, path, FILE_LIMIT, isDirty)
|
|
7918
9285
|
if (next === null) {
|
|
7919
|
-
note('已打开 ' + FILE_LIMIT + ' 个文件且都有未保存修改,请先关闭一个再打开 ' +
|
|
9286
|
+
note('已打开 ' + FILE_LIMIT + ' 个文件且都有未保存修改,请先关闭一个再打开 ' + fileBaseName(path))
|
|
7920
9287
|
return
|
|
7921
9288
|
}
|
|
7922
9289
|
// A path that is NOT already open must be read from disk: a document or
|
|
@@ -7939,7 +9306,7 @@ var [ui, setUi] = useState(function () {
|
|
|
7939
9306
|
if (request === null || typeof request !== 'object') return
|
|
7940
9307
|
if (typeof request.path !== 'string' || request.path === '') return
|
|
7941
9308
|
openPath(request.path)
|
|
7942
|
-
note('已在编辑器打开 ' +
|
|
9309
|
+
note('已在编辑器打开 ' + fileBaseName(request.path) + '(改完保存即生效)')
|
|
7943
9310
|
}, [configOpenNonce])
|
|
7944
9311
|
function closePath(path) {
|
|
7945
9312
|
debugOpenedRef.current = debugOpenedRef.current.filter(function (item) { return item !== path })
|
|
@@ -7963,7 +9330,7 @@ var [ui, setUi] = useState(function () {
|
|
|
7963
9330
|
setRecentFiles(function (previous) {
|
|
7964
9331
|
return previous.filter(function (item) { return item !== path })
|
|
7965
9332
|
})
|
|
7966
|
-
note('文件不存在,已从最近历史移除:' +
|
|
9333
|
+
note('文件不存在,已从最近历史移除:' + fileBaseName(path))
|
|
7967
9334
|
return
|
|
7968
9335
|
}
|
|
7969
9336
|
openPath(path)
|
|
@@ -7991,6 +9358,9 @@ var [ui, setUi] = useState(function () {
|
|
|
7991
9358
|
if (doc === undefined || doc.kind !== 'text') return Promise.resolve(true)
|
|
7992
9359
|
setSavingPath(path)
|
|
7993
9360
|
return fsWrite(scopeRef.current, path, docTextForDisk(doc)).then(function () {
|
|
9361
|
+
// The file on disk just changed, so any cached `git grep` payload for the
|
|
9362
|
+
// query in the box is stale; refresh it (a no-op when nothing is cached).
|
|
9363
|
+
reloadWorkspaceSearch(treeQuery)
|
|
7994
9364
|
setDocs(function (prev) {
|
|
7995
9365
|
var next = Object.assign({}, prev)
|
|
7996
9366
|
var current = next[path]
|
|
@@ -8049,7 +9419,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8049
9419
|
try {
|
|
8050
9420
|
await fsWrite(scopeRef.current, path, docTextForDisk(doc))
|
|
8051
9421
|
} catch (problem) {
|
|
8052
|
-
note('保存失败:' +
|
|
9422
|
+
note('保存失败:' + fileBaseName(path) + ' ' + messageOf(problem))
|
|
8053
9423
|
return false
|
|
8054
9424
|
}
|
|
8055
9425
|
setDocs(function (previous) {
|
|
@@ -8785,7 +10155,31 @@ var [ui, setUi] = useState(function () {
|
|
|
8785
10155
|
return function () { window.removeEventListener('mousedown', onDown); window.removeEventListener('keydown', onKey) }
|
|
8786
10156
|
}, [tabMenu])
|
|
8787
10157
|
|
|
8788
|
-
/**
|
|
10158
|
+
/**
|
|
10159
|
+
* Re-reads the workspace for the current query instead of replaying the cache.
|
|
10160
|
+
*
|
|
10161
|
+
* `searchCacheRef` holds `git grep`/name-search payloads keyed by the query
|
|
10162
|
+
* TEXT, and it is what lets a picked row be reopened without re-running the
|
|
10163
|
+
* search. The price is that file contents are not part of the key: after an
|
|
10164
|
+
* edit the same query kept returning the old hits (reported bug). Any
|
|
10165
|
+
* explicit "search again" — Ctrl+R or a save in this window — drops the two
|
|
10166
|
+
* entries for the query and bumps `searchReload`, which the effects depend on.
|
|
10167
|
+
* @param {string} [text] - the query to refresh; defaults to the box's value.
|
|
10168
|
+
*/
|
|
10169
|
+
function reloadWorkspaceSearch(text) {
|
|
10170
|
+
var raw = typeof text === 'string' ? text : treeQuery
|
|
10171
|
+
var query = String(raw === undefined || raw === null ? '' : raw).trim()
|
|
10172
|
+
var dropped = false
|
|
10173
|
+
if (query !== '') {
|
|
10174
|
+
dropped = searchCacheRef.current.delete('content:' + query) || dropped
|
|
10175
|
+
dropped = searchCacheRef.current.delete('name:' + query) || dropped
|
|
10176
|
+
}
|
|
10177
|
+
// Nothing cached: whatever is on screen came from a run that is still
|
|
10178
|
+
// fresh (or is already in flight), so a second kick would only abort it.
|
|
10179
|
+
if (dropped) setSearchReload(function (value) { return value + 1 })
|
|
10180
|
+
}
|
|
10181
|
+
|
|
10182
|
+
/** Toolbar search: debounce, then stream matches page by page from the host route. */
|
|
8789
10183
|
useEffect(function () {
|
|
8790
10184
|
var text = treeQuery.trim()
|
|
8791
10185
|
if (text === '') { setSearchHits(null); setSearchBusy(false); return undefined }
|
|
@@ -8796,27 +10190,43 @@ var [ui, setUi] = useState(function () {
|
|
|
8796
10190
|
return undefined
|
|
8797
10191
|
}
|
|
8798
10192
|
var cancelled = false
|
|
10193
|
+
var controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
8799
10194
|
setSearchBusy(true)
|
|
8800
10195
|
var timer = setTimeout(function () {
|
|
8801
|
-
|
|
10196
|
+
var matches = []
|
|
10197
|
+
fsSearchStream(scopeRef.current, text, {
|
|
10198
|
+
onPage: function (page) {
|
|
10199
|
+
if (cancelled || Array.isArray(page) !== true) return
|
|
10200
|
+
for (var index = 0; index < page.length; index += 1) {
|
|
10201
|
+
if (typeof page[index] === 'string') matches.push(page[index])
|
|
10202
|
+
}
|
|
10203
|
+
// Paint the first page immediately: later roots append while the user reads.
|
|
10204
|
+
if (matches.length > 0) setSearchHits({ matches: matches.slice(), dirs: {} })
|
|
10205
|
+
},
|
|
10206
|
+
}, controller === null ? undefined : controller.signal).then(function () {
|
|
8802
10207
|
if (cancelled) return
|
|
8803
|
-
var payload = searchHitPayload(
|
|
10208
|
+
var payload = searchHitPayload({ matches: matches.slice(), dirs: {} }, cwd)
|
|
8804
10209
|
rememberSearchEntry(searchCacheRef.current, 'name:' + text, payload)
|
|
8805
10210
|
setSearchHits(payload)
|
|
8806
10211
|
setSearchBusy(false)
|
|
8807
10212
|
}).catch(function (problem) {
|
|
8808
|
-
if (cancelled) return
|
|
10213
|
+
if (cancelled || isAbortError(problem)) return
|
|
8809
10214
|
setSearchHits({ error: messageOf(problem) || '未知错误' })
|
|
8810
10215
|
setSearchBusy(false)
|
|
8811
10216
|
})
|
|
8812
10217
|
}, 250)
|
|
8813
|
-
return function () {
|
|
8814
|
-
|
|
10218
|
+
return function () {
|
|
10219
|
+
cancelled = true
|
|
10220
|
+
clearTimeout(timer)
|
|
10221
|
+
if (controller !== null) controller.abort()
|
|
10222
|
+
}
|
|
10223
|
+
}, [treeQuery, cwd, searchReload])
|
|
8815
10224
|
|
|
8816
10225
|
/**
|
|
8817
10226
|
* Content search for the same query: slower than the name search (one
|
|
8818
10227
|
* `git grep -n` per call, no index — a deliberate product promise), so it
|
|
8819
|
-
* runs on its own slightly longer debounce
|
|
10228
|
+
* runs on its own slightly longer debounce, never blocks the file list, and
|
|
10229
|
+
* streams its hits page by page like the name search.
|
|
8820
10230
|
*/
|
|
8821
10231
|
useEffect(function () {
|
|
8822
10232
|
var text = treeQuery.trim()
|
|
@@ -8828,26 +10238,44 @@ var [ui, setUi] = useState(function () {
|
|
|
8828
10238
|
return undefined
|
|
8829
10239
|
}
|
|
8830
10240
|
var cancelled = false
|
|
10241
|
+
var controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
8831
10242
|
setContentBusy(true)
|
|
8832
10243
|
var timer = setTimeout(function () {
|
|
8833
|
-
|
|
10244
|
+
var hits = []
|
|
10245
|
+
fsSearchContentStream(scopeRef.current, text, {
|
|
10246
|
+
onPage: function (page) {
|
|
10247
|
+
if (cancelled || Array.isArray(page) !== true) return
|
|
10248
|
+
for (var index = 0; index < page.length; index += 1) hits.push(page[index])
|
|
10249
|
+
if (hits.length > 0) setContentHits(hits.slice())
|
|
10250
|
+
},
|
|
10251
|
+
}, controller === null ? undefined : controller.signal).then(function () {
|
|
8834
10252
|
if (cancelled) return
|
|
8835
|
-
|
|
8836
|
-
|
|
10253
|
+
var payload = hits.slice()
|
|
10254
|
+
rememberSearchEntry(searchCacheRef.current, 'content:' + text, payload)
|
|
10255
|
+
setContentHits(payload)
|
|
8837
10256
|
setContentBusy(false)
|
|
8838
|
-
}).catch(function () {
|
|
8839
|
-
if (cancelled) return
|
|
10257
|
+
}).catch(function (problem) {
|
|
10258
|
+
if (cancelled || isAbortError(problem)) return
|
|
8840
10259
|
setContentHits([])
|
|
8841
10260
|
setContentBusy(false)
|
|
8842
10261
|
})
|
|
8843
10262
|
}, 450)
|
|
8844
|
-
return function () {
|
|
8845
|
-
|
|
10263
|
+
return function () {
|
|
10264
|
+
cancelled = true
|
|
10265
|
+
clearTimeout(timer)
|
|
10266
|
+
if (controller !== null) controller.abort()
|
|
10267
|
+
}
|
|
10268
|
+
}, [treeQuery, cwd, searchReload])
|
|
8846
10269
|
|
|
8847
10270
|
/**
|
|
8848
10271
|
* A shortcut (Ctrl+R / Ctrl+Shift+R / F3) focused the box: select its text
|
|
8849
10272
|
* once React has painted the value, otherwise the controlled update resets
|
|
8850
10273
|
* the selection to the end and the highlight the user asked for is lost.
|
|
10274
|
+
*
|
|
10275
|
+
* The same shortcut is also the user's "search again" gesture (the standalone
|
|
10276
|
+
* window never lets it reload the page), so it re-reads the workspace: the
|
|
10277
|
+
* query text did not change, and without this the cache would replay the hits
|
|
10278
|
+
* from before the file was edited.
|
|
8851
10279
|
*/
|
|
8852
10280
|
useEffect(function () {
|
|
8853
10281
|
if (searchFocusPendingRef.current !== true) return
|
|
@@ -8856,6 +10284,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8856
10284
|
searchFocusPendingRef.current = false
|
|
8857
10285
|
input.focus()
|
|
8858
10286
|
input.select()
|
|
10287
|
+
reloadWorkspaceSearch(treeQuery)
|
|
8859
10288
|
}, [searchFocusNonce, treeQuery])
|
|
8860
10289
|
|
|
8861
10290
|
/**
|
|
@@ -9497,7 +10926,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9497
10926
|
scope: scopeRef.current,
|
|
9498
10927
|
path: path,
|
|
9499
10928
|
fontRatio: fontRatio,
|
|
9500
|
-
title:
|
|
10929
|
+
title: fileBaseName(path),
|
|
9501
10930
|
text: doc.text,
|
|
9502
10931
|
savedText: doc.saved,
|
|
9503
10932
|
onEditorMenu: setEditorMenu,
|
|
@@ -9563,7 +10992,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9563
10992
|
} else if (/\.html?$/i.test(openFile)) {
|
|
9564
10993
|
content = h('iframe', {
|
|
9565
10994
|
style: S.previewFrame, sandbox: '', srcDoc: doc.text,
|
|
9566
|
-
title: 'HTML 预览:' +
|
|
10995
|
+
title: 'HTML 预览:' + fileBaseName(openFile), 'data-preview-frame': '1',
|
|
9567
10996
|
})
|
|
9568
10997
|
} else {
|
|
9569
10998
|
content = h('div', {
|
|
@@ -9592,8 +11021,8 @@ var [ui, setUi] = useState(function () {
|
|
|
9592
11021
|
type: 'button', style: Object.assign({}, S.buttonOff, { padding: '0 8px' }),
|
|
9593
11022
|
'data-action': previewing ? 'preview-exit' : 'preview-enter',
|
|
9594
11023
|
title: previewing
|
|
9595
|
-
? '返回编辑 ' +
|
|
9596
|
-
: '预览 ' +
|
|
11024
|
+
? '返回编辑 ' + fileBaseName(openFile)
|
|
11025
|
+
: '预览 ' + fileBaseName(openFile) + '(Markdown/HTML 在编辑器区域内渲染,显示当前内容)',
|
|
9597
11026
|
onClick: function () { togglePreview() },
|
|
9598
11027
|
}, previewing ? '编辑' : '预览'))
|
|
9599
11028
|
}
|
|
@@ -9619,7 +11048,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9619
11048
|
onClick: function () { setOpenFile(path) },
|
|
9620
11049
|
onContextMenu: function (event) { openTabMenu('source', event) },
|
|
9621
11050
|
},
|
|
9622
|
-
|
|
11051
|
+
fileBaseName(path) + (isDirty(path) ? '*' : ''),
|
|
9623
11052
|
h('span', {
|
|
9624
11053
|
style: S.tabClose, title: '关闭', 'data-tab-close': 'source',
|
|
9625
11054
|
onClick: function (event) { event.stopPropagation(); requestClose(path) },
|
|
@@ -9648,7 +11077,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9648
11077
|
}, '▾'))
|
|
9649
11078
|
var prompt = pendingClose !== undefined
|
|
9650
11079
|
? h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-close-prompt': '1' },
|
|
9651
|
-
h('span', { style: { flex: '1 1 auto', minWidth: 0 } }, '「' +
|
|
11080
|
+
h('span', { style: { flex: '1 1 auto', minWidth: 0 } }, '「' + fileBaseName(pendingClose) + '」有未保存的修改:'),
|
|
9652
11081
|
h('button', {
|
|
9653
11082
|
type: 'button', style: S.button, 'data-action': 'save-close', title: '保存后关闭',
|
|
9654
11083
|
onClick: function () {
|
|
@@ -9687,7 +11116,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9687
11116
|
? h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-bulk-prompt': '1' },
|
|
9688
11117
|
h('span', { style: { flex: '1 1 auto', minWidth: 0 } },
|
|
9689
11118
|
pendingBulk.dirty.length + ' 个页签有未保存的修改('
|
|
9690
|
-
+ pendingBulk.dirty.slice(0, 2).map(
|
|
11119
|
+
+ pendingBulk.dirty.slice(0, 2).map(fileBaseName).join('、')
|
|
9691
11120
|
+ (pendingBulk.dirty.length > 2 ? ' 等' : '') + '):'),
|
|
9692
11121
|
h('button', {
|
|
9693
11122
|
type: 'button', style: S.button, 'data-action': 'bulk-save-close', title: '全部保存后关闭',
|
|
@@ -9756,7 +11185,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9756
11185
|
h('span', { style: { opacity: 0.7, flex: '0 0 auto' } }, row.open === true ? '●' : '·'),
|
|
9757
11186
|
h('span', {
|
|
9758
11187
|
style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
9759
|
-
},
|
|
11188
|
+
}, fileBaseName(row.path) + (dirty ? '*' : '')),
|
|
9760
11189
|
row.open === true ? null : h('span', { style: { opacity: 0.5, fontSize: 10, flex: '0 0 auto' } }, '历史'))
|
|
9761
11190
|
return header === null ? item : [header, item]
|
|
9762
11191
|
}))
|
|
@@ -9774,7 +11203,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9774
11203
|
return h('div', { style: S.paneOverlay, 'data-editor-diff': openFile },
|
|
9775
11204
|
h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-diff-head': '1' },
|
|
9776
11205
|
h('span', { style: { flex: '1 1 auto', minWidth: 0 } },
|
|
9777
|
-
'与磁盘版本对比:' +
|
|
11206
|
+
'与磁盘版本对比:' + fileBaseName(openFile) + '(' + changed + ' 行变化;+ 新增 / − 删除)'),
|
|
9778
11207
|
h('button', {
|
|
9779
11208
|
type: 'button', style: S.button, 'data-action': 'diff-close',
|
|
9780
11209
|
onClick: function () { setDiffPath(null) },
|
|
@@ -9948,11 +11377,25 @@ var [ui, setUi] = useState(function () {
|
|
|
9948
11377
|
placeholder: '在工作空间中检索文件…',
|
|
9949
11378
|
title: '全工作空间文件名检索(结果在搜索框下方,点击直接打开/定位)',
|
|
9950
11379
|
'data-action': 'tree-search',
|
|
9951
|
-
onChange: function (event) {
|
|
11380
|
+
onChange: function (event) {
|
|
11381
|
+
var value = event.target.value
|
|
11382
|
+
setTreeQuery(value)
|
|
11383
|
+
// The dropdown is focus-gated; an edit that lands while the box is
|
|
11384
|
+
// already focused must still bring it back (no focus event fires).
|
|
11385
|
+
if (value.trim() !== '') setSearchFocused(true)
|
|
11386
|
+
},
|
|
9952
11387
|
onFocus: function () { setSearchFocused(true) },
|
|
9953
11388
|
onBlur: function () { setSearchFocused(false) },
|
|
9954
11389
|
onKeyDown: function (event) {
|
|
9955
|
-
if (event.key === 'Escape') {
|
|
11390
|
+
if (event.key === 'Escape') {
|
|
11391
|
+
event.preventDefault()
|
|
11392
|
+
// Escape only gives the caret back: the query and its results stay, so
|
|
11393
|
+
// refocusing the box shows them again. Clearing here used to throw the
|
|
11394
|
+
// typed query away for a key that reads as "leave the box".
|
|
11395
|
+
if (searchInputRef.current !== null) searchInputRef.current.blur()
|
|
11396
|
+
else setSearchFocused(false)
|
|
11397
|
+
return
|
|
11398
|
+
}
|
|
9956
11399
|
// Whichever dropdown is open is the walkable list: the recent-file list
|
|
9957
11400
|
// while the box is empty, the results once a query is typed.
|
|
9958
11401
|
var matches = searchHits !== null && searchHits !== undefined && Array.isArray(searchHits.matches) ? searchHits.matches : []
|
|
@@ -10114,6 +11557,38 @@ var [ui, setUi] = useState(function () {
|
|
|
10114
11557
|
return function () { window.removeEventListener('keydown', onKey) }
|
|
10115
11558
|
}, [visible])
|
|
10116
11559
|
|
|
11560
|
+
// Ctrl/Cmd+F is the editor's find chord and, in the standalone IDE window, it
|
|
11561
|
+
// must never fall through to the browser's own find bar. CodeMirror handles it
|
|
11562
|
+
// while the caret sits in the document, and the panel handles keys pressed
|
|
11563
|
+
// inside itself (both mark the event handled — see `defaultPrevented`); this
|
|
11564
|
+
// listener is the last line for every other focus: the tabs bar, the tree, or
|
|
11565
|
+
// the workspace search box. There it opens the open file's find panel, and the
|
|
11566
|
+
// workspace search box when the open file has no editor (images, "no file").
|
|
11567
|
+
useEffect(function () {
|
|
11568
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
11569
|
+
if (visible === false) return undefined
|
|
11570
|
+
function onFindKey(event) {
|
|
11571
|
+
if (event.defaultPrevented === true) return
|
|
11572
|
+
if (event.ctrlKey !== true && event.metaKey !== true) return
|
|
11573
|
+
if (event.altKey === true || event.shiftKey === true) return
|
|
11574
|
+
var key = String(event.key === undefined || event.key === null ? '' : event.key).toLowerCase()
|
|
11575
|
+
if (key !== 'f') return
|
|
11576
|
+
if (!ownsKeyTarget(event.target)) return
|
|
11577
|
+
event.preventDefault()
|
|
11578
|
+
event.stopPropagation()
|
|
11579
|
+
var controls = typeof openFile === 'string' ? viewerControlsRef.current[openFile] : undefined
|
|
11580
|
+
if (controls !== undefined && controls !== null && typeof controls.find === 'function') {
|
|
11581
|
+
controls.find()
|
|
11582
|
+
return
|
|
11583
|
+
}
|
|
11584
|
+
if (searchInputRef.current === null) return
|
|
11585
|
+
searchFocusPendingRef.current = true
|
|
11586
|
+
setSearchFocusNonce(function (value) { return value + 1 })
|
|
11587
|
+
}
|
|
11588
|
+
window.addEventListener('keydown', onFindKey)
|
|
11589
|
+
return function () { window.removeEventListener('keydown', onFindKey) }
|
|
11590
|
+
}, [visible, openFile])
|
|
11591
|
+
|
|
10117
11592
|
/** Bottom-right help: every shortcut group plus a short how-to. */
|
|
10118
11593
|
function renderHelpPanel() {
|
|
10119
11594
|
return h('div', {
|
|
@@ -10172,6 +11647,9 @@ var [ui, setUi] = useState(function () {
|
|
|
10172
11647
|
if (paneConfig !== null && typeof paneConfig.generate === 'function') {
|
|
10173
11648
|
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' }))
|
|
10174
11649
|
}
|
|
11650
|
+
// 「代理」: the same dialog as the sidebar console's 🌐 — the engine config
|
|
11651
|
+
// lives per workspace (cwd), so the standalone window must offer it too.
|
|
11652
|
+
consoleConfigActions.push(button('🌐', function () { setProxyOpen(true) }, { key: 'proxy-open', icon: true, height: 20, action: 'proxy-open', title: '代理:SOCKS 地址 + 按程序/IP/端口的规则(与侧边栏控制台共用同一份配置)' }))
|
|
10175
11653
|
paneActions.push(button('⟲', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态)' }))
|
|
10176
11654
|
|
|
10177
11655
|
/** Load the visual debug settings from the host (⚙ opens on a fresh read). */
|
|
@@ -10285,6 +11763,9 @@ var [ui, setUi] = useState(function () {
|
|
|
10285
11763
|
'data-theme': themePreference || 'page',
|
|
10286
11764
|
onContextMenu: function (event) { event.preventDefault() },
|
|
10287
11765
|
},
|
|
11766
|
+
proxyOpen === true
|
|
11767
|
+
? h(ProxyDialog, { scope: { sessionId: sessionId, cwd: cwd }, onClose: function () { setProxyOpen(false) } })
|
|
11768
|
+
: null,
|
|
10288
11769
|
// The sidebar's CodeMirror theme pins 13px, so the embedded viewer needs
|
|
10289
11770
|
// this rule, not inheritance, to follow A−/A+.
|
|
10290
11771
|
h('style', { key: 'ide-font' }, viewerFontCss(uiFont) + viewerThemeCss(pageDark) + DEBUG_LINE_CSS + PREVIEW_CSS + SELECTION_CSS + SCROLLBAR_CSS + SEARCH_PANEL_CSS + TOAST_CSS + PROGRAM_LOADING_CSS),
|
|
@@ -11141,12 +12622,20 @@ var [ui, setUi] = useState(function () {
|
|
|
11141
12622
|
*
|
|
11142
12623
|
* Registered in `conversation.session.header.utilities` with order -8, i.e.
|
|
11143
12624
|
* immediately to the RIGHT of DSH's own "open in app" action (-10) and left of
|
|
11144
|
-
* the schedule / log buttons. `sessionId`
|
|
11145
|
-
*
|
|
12625
|
+
* the schedule / log buttons. `sessionId` and `useSessions` arrive as standard
|
|
12626
|
+
* slot props.
|
|
12627
|
+
*
|
|
12628
|
+
* The window follows THIS SESSION's workspace, never the remembered one: after
|
|
12629
|
+
* a session switch `knownWorkspaceCwd()` still names the previous session's
|
|
12630
|
+
* workspace (and its single-instance window name), so the button used to bring
|
|
12631
|
+
* back the previous workspace's IDE. The store the slot hands us has the
|
|
12632
|
+
* current session's `cwd`; the fallback only matters on hosts without it.
|
|
12633
|
+
* @param {{sessionId?: string, useSessions?: Function}} props - standard slot props.
|
|
11146
12634
|
* @returns {object} the button element.
|
|
11147
12635
|
*/
|
|
11148
12636
|
function RisIdeWindowAction(props) {
|
|
11149
12637
|
var sessionId = props !== null && props !== undefined && typeof props.sessionId === 'string' ? props.sessionId : ''
|
|
12638
|
+
var sessionCwd = sessionWorkspaceCwd(props !== null && props !== undefined ? props.useSessions : undefined, sessionId)
|
|
11150
12639
|
var [blocked, setBlocked] = useState(false)
|
|
11151
12640
|
useEffect(function () {
|
|
11152
12641
|
if (blocked !== true) return undefined
|
|
@@ -11159,7 +12648,7 @@ var [ui, setUi] = useState(function () {
|
|
|
11159
12648
|
async function onClick(event) {
|
|
11160
12649
|
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
11161
12650
|
try {
|
|
11162
|
-
var handle = await openStandaloneWindow({ sessionId: sessionId })
|
|
12651
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: sessionCwd, windowCwd: sessionCwd })
|
|
11163
12652
|
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
11164
12653
|
} catch (error) {
|
|
11165
12654
|
console.warn('dsh-ris-ide: 独立窗口打开失败:' + messageOf(error))
|
|
@@ -11872,6 +13361,12 @@ var [ui, setUi] = useState(function () {
|
|
|
11872
13361
|
return parsed
|
|
11873
13362
|
}
|
|
11874
13363
|
|
|
13364
|
+
/**
|
|
13365
|
+
* Bytes per upload chunk for a save too large for one request. The host stages
|
|
13366
|
+
* the chunks in a sibling temp file and renames it on the last one, so a big
|
|
13367
|
+
* document is saved without a body-size ceiling (and never half-written).
|
|
13368
|
+
*/
|
|
13369
|
+
var SAVE_CHUNK_BYTES = 512 * 1024
|
|
11875
13370
|
/**
|
|
11876
13371
|
* Write a text file back.
|
|
11877
13372
|
*
|
|
@@ -11885,23 +13380,50 @@ var [ui, setUi] = useState(function () {
|
|
|
11885
13380
|
* @returns {Promise<{mtimeMs?: number}>} the fresh baseline.
|
|
11886
13381
|
*/
|
|
11887
13382
|
async function fsWrite(scope, path, content) {
|
|
11888
|
-
var
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
13383
|
+
var payload = {
|
|
13384
|
+
sessionId: scope.sessionId,
|
|
13385
|
+
...(typeof scope.cwd === 'string' && scope.cwd !== '' ? { cwd: scope.cwd } : {}),
|
|
13386
|
+
path: path,
|
|
13387
|
+
}
|
|
13388
|
+
/** POST one body and return the host's answer, or throw its message. */
|
|
13389
|
+
async function postWrite(body) {
|
|
13390
|
+
var url = routeUrl('dsh-ris-ide/fs/write')
|
|
13391
|
+
var response = await fetch(url.href, {
|
|
13392
|
+
method: 'POST',
|
|
13393
|
+
headers: { 'content-type': 'application/json' },
|
|
13394
|
+
body: JSON.stringify(body),
|
|
13395
|
+
})
|
|
13396
|
+
var parsed = await response.json().catch(function () { return null })
|
|
13397
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
13398
|
+
if (parsed !== null && parsed.message !== undefined) throw new Error(parsed.message)
|
|
13399
|
+
throw new Error('HTTP ' + response.status)
|
|
13400
|
+
}
|
|
13401
|
+
return parsed
|
|
13402
|
+
}
|
|
13403
|
+
// A save is chunked only when it would be a big body: a normal file must
|
|
13404
|
+
// stay ONE request (the host writes the whole document and answers once).
|
|
13405
|
+
var bytes = typeof TextEncoder === 'function' ? new TextEncoder().encode(content) : null
|
|
13406
|
+
if (bytes === null || bytes.length <= SAVE_CHUNK_BYTES) {
|
|
13407
|
+
var single = await postWrite(Object.assign({}, payload, { content: content }))
|
|
13408
|
+
return { mtimeMs: single.mtimeMs }
|
|
13409
|
+
}
|
|
13410
|
+
// Chunked save: utf8-safe slices, byte offsets, staged rename on the host.
|
|
13411
|
+
var decoder = typeof TextDecoder === 'function' ? new TextDecoder() : null
|
|
13412
|
+
var offset = 0
|
|
13413
|
+
var answer = null
|
|
13414
|
+
while (offset < bytes.length) {
|
|
13415
|
+
var end = Math.min(offset + SAVE_CHUNK_BYTES, bytes.length)
|
|
13416
|
+
// Never cut a multi-byte code point: back off to its leading byte.
|
|
13417
|
+
while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) end -= 1
|
|
13418
|
+
var piece = decoder === null ? content : decoder.decode(bytes.subarray(offset, end))
|
|
13419
|
+
answer = await postWrite(Object.assign({}, payload, {
|
|
13420
|
+
content: piece,
|
|
13421
|
+
offset: offset,
|
|
13422
|
+
final: end >= bytes.length,
|
|
13423
|
+
}))
|
|
13424
|
+
offset = end
|
|
11903
13425
|
}
|
|
11904
|
-
return { mtimeMs:
|
|
13426
|
+
return { mtimeMs: answer === null ? undefined : answer.mtimeMs }
|
|
11905
13427
|
}
|
|
11906
13428
|
/**
|
|
11907
13429
|
* Workspace filename search — through THIS plugin's host route, which runs
|
|
@@ -11960,6 +13482,147 @@ var [ui, setUi] = useState(function () {
|
|
|
11960
13482
|
})
|
|
11961
13483
|
}
|
|
11962
13484
|
|
|
13485
|
+
/**
|
|
13486
|
+
* Whether `problem` is the AbortController's own rejection; the search effects
|
|
13487
|
+
* abort on every keystroke, so that is expected and must never surface as an
|
|
13488
|
+
* error line in the dropdown.
|
|
13489
|
+
* @param {unknown} problem - the caught value.
|
|
13490
|
+
* @returns {boolean} true for an abort.
|
|
13491
|
+
*/
|
|
13492
|
+
function isAbortError(problem) {
|
|
13493
|
+
return problem !== null && problem !== undefined && problem.name === 'AbortError'
|
|
13494
|
+
}
|
|
13495
|
+
|
|
13496
|
+
/**
|
|
13497
|
+
* Read one NDJSON search answer frame by frame.
|
|
13498
|
+
*
|
|
13499
|
+
* The host streams `start`, then one `page` per page of matches (in tree
|
|
13500
|
+
* order), then `done`. Rendering each page as it lands is the whole point:
|
|
13501
|
+
* the dropdown paints the first matches while the remaining repo roots are
|
|
13502
|
+
* still being listed (the batch route made the user wait for all of them).
|
|
13503
|
+
* @param {Response} response - the fetch answer (its body is a stream).
|
|
13504
|
+
* @param {(items: Array) => void} onPage - called with each page.
|
|
13505
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} the `done` frame.
|
|
13506
|
+
*/
|
|
13507
|
+
async function readSearchStream(response, onPage) {
|
|
13508
|
+
var body = response.body
|
|
13509
|
+
if (body === null || body === undefined || typeof body.getReader !== 'function') {
|
|
13510
|
+
throw new Error('这个浏览器不支持流式读取')
|
|
13511
|
+
}
|
|
13512
|
+
var reader = body.getReader()
|
|
13513
|
+
var decoder = new TextDecoder()
|
|
13514
|
+
var buffer = ''
|
|
13515
|
+
var done = null
|
|
13516
|
+
function handleLine(line) {
|
|
13517
|
+
var text = line.trim()
|
|
13518
|
+
if (text === '') return
|
|
13519
|
+
var frame = null
|
|
13520
|
+
try { frame = JSON.parse(text) } catch (problem) { return }
|
|
13521
|
+
if (frame === null || typeof frame !== 'object') return
|
|
13522
|
+
if (frame.type === 'page' && Array.isArray(frame.items)) { onPage(frame.items); return }
|
|
13523
|
+
if (frame.type === 'error') throw new Error(typeof frame.message === 'string' ? frame.message : '检索失败')
|
|
13524
|
+
if (frame.type === 'done') {
|
|
13525
|
+
done = {
|
|
13526
|
+
matches: typeof frame.matches === 'number' ? frame.matches : 0,
|
|
13527
|
+
files: typeof frame.files === 'number' ? frame.files : 0,
|
|
13528
|
+
truncated: frame.truncated === true,
|
|
13529
|
+
}
|
|
13530
|
+
}
|
|
13531
|
+
}
|
|
13532
|
+
for (;;) {
|
|
13533
|
+
var chunk = await reader.read()
|
|
13534
|
+
if (chunk.done === true) break
|
|
13535
|
+
buffer += decoder.decode(chunk.value, { stream: true })
|
|
13536
|
+
var index = buffer.indexOf('\n')
|
|
13537
|
+
while (index !== -1) {
|
|
13538
|
+
handleLine(buffer.slice(0, index))
|
|
13539
|
+
buffer = buffer.slice(index + 1)
|
|
13540
|
+
index = buffer.indexOf('\n')
|
|
13541
|
+
}
|
|
13542
|
+
}
|
|
13543
|
+
buffer += decoder.decode()
|
|
13544
|
+
if (buffer !== '') handleLine(buffer)
|
|
13545
|
+
if (done === null) throw new Error('检索连接中断')
|
|
13546
|
+
return done
|
|
13547
|
+
}
|
|
13548
|
+
|
|
13549
|
+
/**
|
|
13550
|
+
* Streamed workspace filename search — pages arrive while the remaining repo
|
|
13551
|
+
* roots are still being listed, so the dropdown can paint the first hit long
|
|
13552
|
+
* before the batch route would have answered.
|
|
13553
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
13554
|
+
* @param {string} query - case-insensitive path/basename substring.
|
|
13555
|
+
* @param {{onPage?: Function}} handlers - receives each page of absolute paths.
|
|
13556
|
+
* @param {AbortSignal} [signal] - aborts the request when the query changes.
|
|
13557
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} totals.
|
|
13558
|
+
*/
|
|
13559
|
+
async function fsSearchStream(scope, query, handlers, signal) {
|
|
13560
|
+
var url = routeUrl('dsh-ris-ide/search/stream')
|
|
13561
|
+
url.searchParams.set('sessionId', scope.sessionId)
|
|
13562
|
+
var routeCwd = scopeCwd(scope)
|
|
13563
|
+
if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
|
|
13564
|
+
url.searchParams.set('q', query)
|
|
13565
|
+
url.searchParams.set('limit', '300')
|
|
13566
|
+
url.searchParams.set('pageSize', String(SEARCH_STREAM_PAGE_SIZE))
|
|
13567
|
+
var onPage = handlers !== undefined && handlers !== null && typeof handlers.onPage === 'function'
|
|
13568
|
+
? handlers.onPage
|
|
13569
|
+
: function () {}
|
|
13570
|
+
var response = await fetch(url.href, { headers: { accept: 'application/x-ndjson' }, signal: signal })
|
|
13571
|
+
if (response.status === 404) {
|
|
13572
|
+
// A host older than 1.7.3 has no stream route yet (the client half reloads
|
|
13573
|
+
// with a page refresh, the host half only on `dsh web` restart). Answer the
|
|
13574
|
+
// batch route as ONE page instead of showing "HTTP 404" in the dropdown.
|
|
13575
|
+
var batch = await fsSearch(scope, query)
|
|
13576
|
+
onPage(batch.matches)
|
|
13577
|
+
return { matches: batch.matches.length, files: 0, truncated: false }
|
|
13578
|
+
}
|
|
13579
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
13580
|
+
return readSearchStream(response, onPage)
|
|
13581
|
+
}
|
|
13582
|
+
|
|
13583
|
+
/**
|
|
13584
|
+
* Streamed workspace CONTENT search (`git grep` hits), same page-by-page
|
|
13585
|
+
* contract as {@link fsSearchStream}.
|
|
13586
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
13587
|
+
* @param {string} query - literal text to find.
|
|
13588
|
+
* @param {{onPage?: Function}} handlers - receives each page of hits.
|
|
13589
|
+
* @param {AbortSignal} [signal] - aborts the request when the query changes.
|
|
13590
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} totals.
|
|
13591
|
+
*/
|
|
13592
|
+
async function fsSearchContentStream(scope, query, handlers, signal) {
|
|
13593
|
+
var url = routeUrl('dsh-ris-ide/search-content/stream')
|
|
13594
|
+
url.searchParams.set('sessionId', scope.sessionId)
|
|
13595
|
+
var routeCwd = scopeCwd(scope)
|
|
13596
|
+
if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
|
|
13597
|
+
url.searchParams.set('q', query)
|
|
13598
|
+
url.searchParams.set('limit', '200')
|
|
13599
|
+
url.searchParams.set('pageSize', String(SEARCH_STREAM_PAGE_SIZE))
|
|
13600
|
+
var onPage = handlers !== undefined && handlers !== null && typeof handlers.onPage === 'function'
|
|
13601
|
+
? handlers.onPage
|
|
13602
|
+
: function () {}
|
|
13603
|
+
var response = await fetch(url.href, { headers: { accept: 'application/x-ndjson' }, signal: signal })
|
|
13604
|
+
if (response.status === 404) {
|
|
13605
|
+
// Pre-1.7.3 host: stream the batch route's hits as a single page.
|
|
13606
|
+
var hits = await fsSearchContent(scope, query)
|
|
13607
|
+
onPage(hits)
|
|
13608
|
+
return { matches: hits.length, files: 0, truncated: false }
|
|
13609
|
+
}
|
|
13610
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
13611
|
+
return readSearchStream(response, function (items) {
|
|
13612
|
+
var hits = []
|
|
13613
|
+
for (var index = 0; index < items.length; index += 1) {
|
|
13614
|
+
var hit = items[index]
|
|
13615
|
+
if (hit === null || hit === undefined || typeof hit.path !== 'string') continue
|
|
13616
|
+
hits.push({
|
|
13617
|
+
path: hit.path,
|
|
13618
|
+
line: typeof hit.line === 'number' ? hit.line : Number(hit.line) || 0,
|
|
13619
|
+
text: typeof hit.text === 'string' ? hit.text : '',
|
|
13620
|
+
})
|
|
13621
|
+
}
|
|
13622
|
+
onPage(hits)
|
|
13623
|
+
})
|
|
13624
|
+
}
|
|
13625
|
+
|
|
11963
13626
|
/**
|
|
11964
13627
|
* Work out what `mvn test` call would run one Java test FILE (PM gap #6).
|
|
11965
13628
|
*
|
|
@@ -12120,6 +13783,12 @@ var [ui, setUi] = useState(function () {
|
|
|
12120
13783
|
*/
|
|
12121
13784
|
/** How many query → results pairs the search dropdown keeps warm. */
|
|
12122
13785
|
var SEARCH_CACHE_LIMIT = 40
|
|
13786
|
+
/**
|
|
13787
|
+
* Matches per streamed page. The host flushes a page as soon as it fills, so
|
|
13788
|
+
* a small page is what makes the first hits visible while the remaining repo
|
|
13789
|
+
* roots are still being listed (the batch route had to finish all of them).
|
|
13790
|
+
*/
|
|
13791
|
+
var SEARCH_STREAM_PAGE_SIZE = 40
|
|
12123
13792
|
|
|
12124
13793
|
/**
|
|
12125
13794
|
* Remember one search result set (or refresh an existing key's position).
|
|
@@ -12670,6 +14339,8 @@ var [ui, setUi] = useState(function () {
|
|
|
12670
14339
|
* already delivered: the log viewer re-reads the tail once (see `reloadNonce`).
|
|
12671
14340
|
*/
|
|
12672
14341
|
var [compactLogNonce, setCompactLogNonce] = useState(0)
|
|
14342
|
+
/** The 「代理」 dialog: address + rule table, shared by both console shapes. */
|
|
14343
|
+
var [compactProxyOpen, setCompactProxyOpen] = useState(false)
|
|
12673
14344
|
useEffect(function () {
|
|
12674
14345
|
if (pendingProgram === null) return undefined
|
|
12675
14346
|
setActive(pendingProgram)
|
|
@@ -12680,9 +14351,59 @@ var [ui, setUi] = useState(function () {
|
|
|
12680
14351
|
// call sites pass the whole scope object.
|
|
12681
14352
|
var scope = props ? props.scope : undefined
|
|
12682
14353
|
var sessionId = scope !== undefined && scope !== null ? scope.sessionId : (props ? props.sessionId : undefined)
|
|
14354
|
+
// The tab body outlives Session switches, so its `sessionId` can name the
|
|
14355
|
+
// Session it was opened in. The sidebar's own marker is the live answer.
|
|
14356
|
+
var rootRef = useRef(null)
|
|
14357
|
+
var [liveSessionId, setLiveSessionId] = useState(function () { return liveSidebarSessionId() })
|
|
14358
|
+
useEffect(function () {
|
|
14359
|
+
function sync() {
|
|
14360
|
+
var live = liveSidebarSessionId(rootRef.current)
|
|
14361
|
+
// A collapsed sidebar renders no visible marker: keep the last good
|
|
14362
|
+
// answer instead of falling back to the stale injected session.
|
|
14363
|
+
if (typeof live !== 'string' || live === '') return
|
|
14364
|
+
setLiveSessionId(function (prev) { return prev === live ? prev : live })
|
|
14365
|
+
}
|
|
14366
|
+
sync()
|
|
14367
|
+
var cleanups = []
|
|
14368
|
+
// A Session switch rewrites the sidebar's markers, so attribute mutations
|
|
14369
|
+
// catch it; `hidden` flips catch the retained wrappers being shown.
|
|
14370
|
+
if (typeof MutationObserver === 'function' && typeof document !== 'undefined') {
|
|
14371
|
+
var observer = new MutationObserver(sync)
|
|
14372
|
+
observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['data-sidebar-right-session', 'data-sidebar-right-panel', 'hidden'] })
|
|
14373
|
+
cleanups.push(function () { observer.disconnect() })
|
|
14374
|
+
}
|
|
14375
|
+
// Belt and braces: some switches only repaint, and returning to the window
|
|
14376
|
+
// is the moment a stale panel is most visible.
|
|
14377
|
+
if (typeof setInterval === 'function') {
|
|
14378
|
+
var timer = setInterval(sync, 1500)
|
|
14379
|
+
cleanups.push(function () { clearInterval(timer) })
|
|
14380
|
+
}
|
|
14381
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
14382
|
+
window.addEventListener('focus', sync)
|
|
14383
|
+
cleanups.push(function () { window.removeEventListener('focus', sync) })
|
|
14384
|
+
if (typeof document !== 'undefined') {
|
|
14385
|
+
document.addEventListener('visibilitychange', sync)
|
|
14386
|
+
cleanups.push(function () { document.removeEventListener('visibilitychange', sync) })
|
|
14387
|
+
}
|
|
14388
|
+
}
|
|
14389
|
+
return function () { for (var i = 0; i < cleanups.length; i += 1) cleanups[i]() }
|
|
14390
|
+
}, [])
|
|
14391
|
+
if (typeof liveSessionId === 'string' && liveSessionId !== '') sessionId = liveSessionId
|
|
12683
14392
|
var cwd = scope !== undefined && scope !== null ? scope.cwd : (props ? props.cwd : undefined)
|
|
14393
|
+
// The tab outlives session switches (`keepMounted`): the remembered workspace
|
|
14394
|
+
// can still name the PREVIOUS session, so the store's value wins when the
|
|
14395
|
+
// slot hands us `useSessions`.
|
|
14396
|
+
var storeCwd = sessionWorkspaceCwd(props ? props.useSessions : undefined, sessionId)
|
|
14397
|
+
if (typeof storeCwd === 'string' && storeCwd !== '') cwd = storeCwd
|
|
12684
14398
|
// A stale session id must not blank the panel: the host still accepts a cwd.
|
|
12685
14399
|
if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
|
|
14400
|
+
// Selections and the followed log belong to the workspace they were made in,
|
|
14401
|
+
// so a Session switch drops them instead of showing another project's log.
|
|
14402
|
+
var sessionIdentity = typeof sessionId === 'string' ? sessionId : ''
|
|
14403
|
+
useEffect(function () {
|
|
14404
|
+
setCompactPick(undefined)
|
|
14405
|
+
setActive(undefined)
|
|
14406
|
+
}, [sessionIdentity])
|
|
12686
14407
|
// COMPACT mode is the sidebar panel: console rows on top, ONE program's
|
|
12687
14408
|
// live log below. The full IDE (tree/editor/debug) lives only in the
|
|
12688
14409
|
// standalone window, so the sidebar stays cheap and readable.
|
|
@@ -12979,7 +14700,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12979
14700
|
if (sidebar !== undefined && sidebar !== null && typeof sidebar.openResource === 'function') {
|
|
12980
14701
|
try {
|
|
12981
14702
|
sidebar.openResource(officialPreviewAddress({ sessionId: sessionId, cwd: cwd }, path))
|
|
12982
|
-
setState(function (prev) { return Object.assign({}, prev, { note: '已在右侧栏打开 ' +
|
|
14703
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '已在右侧栏打开 ' + fileBaseName(path) + '(改完保存即生效)' }) })
|
|
12983
14704
|
} catch (error) {
|
|
12984
14705
|
setState(function (prev) { return Object.assign({}, prev, { note: '打开配置失败:' + messageOf(error) }) })
|
|
12985
14706
|
}
|
|
@@ -13271,8 +14992,11 @@ var [ui, setUi] = useState(function () {
|
|
|
13271
14992
|
onClick: function () { toggleCompactMax(section) },
|
|
13272
14993
|
}, isMaxed ? '⤡' : '⤢')
|
|
13273
14994
|
}
|
|
13274
|
-
return h('div', { style: S.root, 'data-panel': 'compact' },
|
|
14995
|
+
return h('div', { ref: rootRef, style: S.root, 'data-panel': 'compact' },
|
|
13275
14996
|
h('style', { key: 'compact-loading-css' }, PROGRAM_LOADING_CSS),
|
|
14997
|
+
compactProxyOpen === true
|
|
14998
|
+
? h(ProxyDialog, { scope: { sessionId: sessionId, cwd: cwd }, onClose: function () { setCompactProxyOpen(false) } })
|
|
14999
|
+
: null,
|
|
13276
15000
|
h('div', { style: S.bar, 'data-compact-bar': '1' },
|
|
13277
15001
|
h('span', { style: S.status }, state.loading ? '扫描中…' : (state.programs.length + ' 个项目')),
|
|
13278
15002
|
h('span', { style: S.meta, title: state.root }, state.root || ''),
|
|
@@ -13280,6 +15004,11 @@ var [ui, setUi] = useState(function () {
|
|
|
13280
15004
|
// The config actions live on the CONSOLE title bar in both shapes: the
|
|
13281
15005
|
// sidebar's title bar is this top bar, so it gets the same two icons
|
|
13282
15006
|
// the standalone window puts next to its program list.
|
|
15007
|
+
h('button', {
|
|
15008
|
+
type: 'button', style: S.paneIcon, 'data-action': 'compact-proxy',
|
|
15009
|
+
title: '代理:上游 SOCKS 地址 + 规则(程序 · IP 允许 · 端口)。整机生效;能配代理的程序由 ProxyBridge 按进程拦截,只能填 host:port 的客户端自动用 127.0.0.1 同端口映射',
|
|
15010
|
+
onClick: function () { setCompactProxyOpen(true) },
|
|
15011
|
+
}, '🌐'),
|
|
13283
15012
|
configExists === true
|
|
13284
15013
|
? h('button', {
|
|
13285
15014
|
type: 'button', style: S.paneIcon, 'data-action': 'compact-config-open',
|
|
@@ -13614,6 +15343,8 @@ var [ui, setUi] = useState(function () {
|
|
|
13614
15343
|
// The standalone window: the header button, the popup helper and the
|
|
13615
15344
|
// mount entry the window's own page calls (none of them needs DSH's ctx).
|
|
13616
15345
|
RisIdeWindowAction: RisIdeWindowAction,
|
|
15346
|
+
/** The header button's cwd source: the session store, never the remembered one. */
|
|
15347
|
+
sessionWorkspaceCwd: sessionWorkspaceCwd,
|
|
13617
15348
|
openStandaloneWindow: openStandaloneWindow,
|
|
13618
15349
|
mountStandalone: mountStandalone,
|
|
13619
15350
|
StandaloneWindow: StandaloneWindow,
|
|
@@ -13629,6 +15360,8 @@ var [ui, setUi] = useState(function () {
|
|
|
13629
15360
|
drainOpenRequests: drainOpenRequests,
|
|
13630
15361
|
ProgramWorkbench: ProgramWorkbench,
|
|
13631
15362
|
ProgramsPanel: ProgramsPanel,
|
|
15363
|
+
// Proxy dialog (address + rule table), rendered from both console shapes.
|
|
15364
|
+
ProxyDialog: ProxyDialog,
|
|
13632
15365
|
IdeErrorBoundary: IdeErrorBoundary,
|
|
13633
15366
|
PROGRAM_TAB_ID: PROGRAM_TAB_ID,
|
|
13634
15367
|
// The compact sidebar shape: its default log-pane height (240px) and the
|
|
@@ -13664,6 +15397,11 @@ var [ui, setUi] = useState(function () {
|
|
|
13664
15397
|
searchHitActiveIndex: searchHitActiveIndex,
|
|
13665
15398
|
rememberSearchEntry: rememberSearchEntry,
|
|
13666
15399
|
fsSearchContent: fsSearchContent,
|
|
15400
|
+
fsSearchStream: fsSearchStream,
|
|
15401
|
+
fsSearchContentStream: fsSearchContentStream,
|
|
15402
|
+
readSearchStream: readSearchStream,
|
|
15403
|
+
isAbortError: isAbortError,
|
|
15404
|
+
SEARCH_STREAM_PAGE_SIZE: SEARCH_STREAM_PAGE_SIZE,
|
|
13667
15405
|
runTestStart: runTestStart,
|
|
13668
15406
|
runTestStatus: runTestStatus,
|
|
13669
15407
|
/**
|
|
@@ -13686,6 +15424,7 @@ var [ui, setUi] = useState(function () {
|
|
|
13686
15424
|
readSavedUi: readSavedUi,
|
|
13687
15425
|
treeLabel: treeLabel,
|
|
13688
15426
|
childEntryFor: childEntryFor,
|
|
15427
|
+
pathWithin: pathWithin,
|
|
13689
15428
|
sourceRelativeSuffix: sourceRelativeSuffix,
|
|
13690
15429
|
parseGutterLine: parseGutterLine,
|
|
13691
15430
|
// Log level filter (PM gap #4) and the "what did I change" diff (#5): both
|