dsh-ris-ide 1.7.3 → 1.8.0
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 +19 -7
- package/bin/proxy-janitor.mjs +106 -11
- package/bin/risd.mjs +287 -0
- package/bin/run-with-log.ps1 +43 -5
- package/lib/client.js +515 -1152
- package/lib/index.js +1124 -55
- package/lib/janitor.js +106 -15
- package/lib/proxy.js +86 -7
- package/lib/proxybridge-bundle.js +798 -0
- package/lib/redirector.js +484 -35
- package/lib/risd/build.js +91 -0
- package/lib/risd/debug.js +374 -0
- package/lib/risd/git.js +207 -0
- package/lib/risd/leases.js +124 -0
- package/lib/risd/lifecycle.js +148 -0
- package/lib/risd/log.js +59 -0
- package/lib/risd/ping.js +94 -0
- package/lib/risd/programs.js +348 -0
- package/lib/risd/server.js +1478 -0
- package/lib/risd/state.js +137 -0
- package/lib/risd/ui.js +1705 -0
- package/lib/risd/view.js +79 -0
- package/lib/risd-client.js +282 -0
- package/lib/standalone/window.html +14 -16
- package/lib/startup.js +114 -0
- package/package.json +4 -1
- package/test/client-build.test.mjs +113 -0
- package/test/client-viewer.test.mjs +166 -200
- package/test/dsh-origin.test.mjs +140 -0
- package/test/dsh-window-refresh.test.mjs +100 -0
- package/test/harness.test.mjs +9 -0
- package/test/host-noloop.test.mjs +74 -0
- package/test/host-tail.test.mjs +21 -4
- package/test/host-window.test.mjs +4 -4
- package/test/janitor.test.mjs +29 -1
- package/test/lifecycle.test.mjs +26 -5
- package/test/merge-owners.test.mjs +155 -0
- package/test/proxy-restart.test.mjs +37 -0
- package/test/proxy-window.test.mjs +45 -0
- package/test/proxy.test.mjs +41 -0
- package/test/proxybridge-bundle.test.mjs +687 -0
- package/test/redirector-bundle.test.mjs +391 -0
- package/test/redirector.test.mjs +59 -9
- package/test/risd-api.test.mjs +470 -0
- package/test/risd-bridge-degrade.test.mjs +101 -0
- package/test/risd-build.test.mjs +20 -0
- package/test/risd-cli-home.test.mjs +50 -0
- package/test/risd-client.test.mjs +130 -0
- package/test/risd-debug.test.mjs +261 -0
- package/test/risd-election.test.mjs +104 -0
- package/test/risd-engine.test.mjs +132 -0
- package/test/risd-entry.test.mjs +118 -0
- package/test/risd-git.test.mjs +109 -0
- package/test/risd-handoff.test.mjs +116 -0
- package/test/risd-heal.test.mjs +50 -0
- package/test/risd-helpers.mjs +108 -0
- package/test/risd-host-p2.test.mjs +147 -0
- package/test/risd-janitor-guard.test.mjs +46 -0
- package/test/risd-lease.test.mjs +83 -0
- package/test/risd-lifecycle.test.mjs +210 -0
- package/test/risd-log-follow.test.mjs +227 -0
- package/test/risd-mode.test.mjs +161 -0
- package/test/risd-ping.test.mjs +99 -0
- package/test/risd-programs.test.mjs +169 -0
- package/test/risd-review-p2.test.mjs +217 -0
- package/test/risd-shutdown.test.mjs +97 -0
- package/test/risd-teardown.test.mjs +87 -0
- package/test/risd-tools.test.mjs +211 -0
- package/test/risd-ui.test.mjs +445 -0
- package/test/risd-write.test.mjs +170 -0
- package/test/startup-reconcile.test.mjs +100 -0
- package/test/windows.test.mjs +37 -2
package/lib/client.js
CHANGED
|
@@ -110,6 +110,123 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
return typeof window !== 'undefined' && window.__dshRisIdeWindow === true
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* The client bundle this page is running, as the host told us when the page
|
|
115
|
+
* booted. `null` until the first hello/build answer (see `watchClientBuild`).
|
|
116
|
+
*/
|
|
117
|
+
var pageBuildId = null
|
|
118
|
+
var buildWatcherInstalled = false
|
|
119
|
+
/** How often an open page re-asks the host which bundle it serves. */
|
|
120
|
+
var BUILD_POLL_MS = 30000
|
|
121
|
+
/** The build a hint was raised for, and the one the user closed it for. */
|
|
122
|
+
var staleNoticeBuild = null
|
|
123
|
+
var staleNoticeDismissedFor = null
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Tell the user that the IDE code changed under the open page.
|
|
127
|
+
*
|
|
128
|
+
* Neither page shape reloads itself: the standalone window owns an editor that
|
|
129
|
+
* can hold unsaved buffers, and a DSH page would drop the conversation view. The
|
|
130
|
+
* bar carries the refresh button and is idempotent — later hellos/focus polls
|
|
131
|
+
* reuse the same node instead of stacking bars.
|
|
132
|
+
* @param {string} build - the build id the hint is for.
|
|
133
|
+
*/
|
|
134
|
+
function showStaleBuildNotice(build) {
|
|
135
|
+
staleNoticeBuild = typeof build === 'string' ? build : null
|
|
136
|
+
if (typeof document === 'undefined') return
|
|
137
|
+
var existing = document.getElementById('dsh-ris-ide-build-stale')
|
|
138
|
+
if (existing !== null) { existing.hidden = false; return }
|
|
139
|
+
var bar = document.createElement('div')
|
|
140
|
+
bar.id = 'dsh-ris-ide-build-stale'
|
|
141
|
+
bar.setAttribute('role', 'status')
|
|
142
|
+
bar.style.cssText = 'position:fixed;right:16px;bottom:16px;z-index:2147483000;display:flex;align-items:center;gap:10px;'
|
|
143
|
+
+ 'padding:8px 12px;border-radius:8px;background:#eef4ff;border:1px solid #d7e4ff;color:#1d4ed8;'
|
|
144
|
+
+ 'font:13px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;'
|
|
145
|
+
+ 'box-shadow:0 6px 20px rgba(15,23,42,.12)'
|
|
146
|
+
var text = document.createElement('span')
|
|
147
|
+
text.textContent = 'IDE 界面已更新:刷新页面后生效'
|
|
148
|
+
var reload = document.createElement('button')
|
|
149
|
+
reload.type = 'button'
|
|
150
|
+
reload.textContent = '刷新'
|
|
151
|
+
reload.style.cssText = 'border:1px solid #bcd3ff;background:#fff;color:#1d4ed8;border-radius:6px;padding:2px 10px;cursor:pointer;font:inherit'
|
|
152
|
+
reload.addEventListener('click', function () { location.reload() })
|
|
153
|
+
var close = document.createElement('button')
|
|
154
|
+
close.type = 'button'
|
|
155
|
+
close.textContent = '×'
|
|
156
|
+
close.title = '关闭提示'
|
|
157
|
+
close.setAttribute('aria-label', '关闭提示')
|
|
158
|
+
close.style.cssText = 'border:0;background:transparent;color:inherit;cursor:pointer;font:inherit;padding:0 2px'
|
|
159
|
+
close.addEventListener('click', function () {
|
|
160
|
+
// Remember which build was dismissed: the 30s poll must not re-open the bar
|
|
161
|
+
// for the same stale bundle, but a NEWER build still has to warn.
|
|
162
|
+
staleNoticeDismissedFor = staleNoticeBuild
|
|
163
|
+
bar.hidden = true
|
|
164
|
+
})
|
|
165
|
+
bar.appendChild(text)
|
|
166
|
+
bar.appendChild(reload)
|
|
167
|
+
bar.appendChild(close)
|
|
168
|
+
document.body.appendChild(bar)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Keep this page on the client bundle the host is serving.
|
|
173
|
+
*
|
|
174
|
+
* Plugin bundles are served with `immutable` caching and a revision-baked URL,
|
|
175
|
+
* so a reload already gets the new build — the stale thing is the ALREADY OPEN
|
|
176
|
+
* page, which keeps executing the bundle it booted. The host stamps the build
|
|
177
|
+
* into the stream's hello and serves it at `/dsh-ris-ide/build`; this watcher
|
|
178
|
+
* takes the first answer as "what this page runs" and, when a later answer
|
|
179
|
+
* differs, raises the refresh hint. It never reloads by itself, and it keeps
|
|
180
|
+
* `pageBuildId` on the bundle this page actually runs, so a cancelled or missed
|
|
181
|
+
* reload keeps the hint up (review C3-P1-2).
|
|
182
|
+
*
|
|
183
|
+
* Rides the existing stream hub for the push case, plus a slow visibility-aware
|
|
184
|
+
* poll for pages that stay in the foreground (a hello only arrives when the
|
|
185
|
+
* stream (re)connects). A hub that is not connected yet is fine — the first
|
|
186
|
+
* answer becomes the baseline.
|
|
187
|
+
*/
|
|
188
|
+
function watchClientBuild() {
|
|
189
|
+
if (buildWatcherInstalled || typeof window === 'undefined') return
|
|
190
|
+
// A real browser page always has EventSource; a Node test harness that imports
|
|
191
|
+
// this file does not, and must not start a stream (or a fetch to a relative
|
|
192
|
+
// URL, or a timer) just because `apply` ran — that surfaced as an async
|
|
193
|
+
// "EventSource is not defined" after the test had already ended.
|
|
194
|
+
if (typeof EventSource !== 'function') return
|
|
195
|
+
buildWatcherInstalled = true
|
|
196
|
+
function note(build) {
|
|
197
|
+
if (typeof build !== 'string' || build === '') return
|
|
198
|
+
if (pageBuildId === null) { pageBuildId = build; return }
|
|
199
|
+
if (build === pageBuildId) return
|
|
200
|
+
// A dismissed hint stays dismissed for THAT build; a newer bundle re-warns.
|
|
201
|
+
if (build === staleNoticeDismissedFor) return
|
|
202
|
+
showStaleBuildNotice(build)
|
|
203
|
+
}
|
|
204
|
+
function pollBuild() {
|
|
205
|
+
if (typeof document !== 'undefined' && document.hidden === true) return
|
|
206
|
+
void fetch(routeUrl('dsh-ris-ide/build').href, { headers: { accept: 'application/json' } })
|
|
207
|
+
.then(function (response) { return response.ok === true ? response.json() : null })
|
|
208
|
+
.then(function (body) { if (body !== null && body !== undefined) note(body.build) })
|
|
209
|
+
.catch(function () { /* host unreachable: keep the build we already know */ })
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
var hub = risStreamHub()
|
|
213
|
+
hub.subscribe({
|
|
214
|
+
topics: ['hello'],
|
|
215
|
+
handlers: {
|
|
216
|
+
hello: function (payload) {
|
|
217
|
+
if (payload === null || payload === undefined || payload.ok !== true) return
|
|
218
|
+
note(payload.build)
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
} catch { /* no hub (old host): the fetch below still seeds the baseline */ }
|
|
223
|
+
// Seed the baseline even when the stream is not up yet, so a page opened
|
|
224
|
+
// before the first hello can still notice the change.
|
|
225
|
+
pollBuild()
|
|
226
|
+
setInterval(pollBuild, BUILD_POLL_MS)
|
|
227
|
+
if (typeof window.addEventListener === 'function') window.addEventListener('focus', pollBuild)
|
|
228
|
+
}
|
|
229
|
+
|
|
113
230
|
/** Point the RIS-IDE tab at one program (consumed by the panel). */
|
|
114
231
|
function selectProgram(program) {
|
|
115
232
|
pendingProgram = program === null || program === undefined ? null : program
|
|
@@ -1906,1074 +2023,6 @@ window.__ModuleLoader__.load({
|
|
|
1906
2023
|
* Editing is local until 保存: the engine keeps its listeners until restarted,
|
|
1907
2024
|
* so the dialog says so out loud instead of pretending a save took effect.
|
|
1908
2025
|
*/
|
|
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
|
-
|
|
2977
2026
|
/** Scaled CSS for viewers that paint their own font (CodeMirror pins 13px). */
|
|
2978
2027
|
function viewerFontCss(size) {
|
|
2979
2028
|
return '[data-workbench="ris-ide"] .cm-editor{font-size:' + size + 'px !important}'
|
|
@@ -4306,32 +3355,68 @@ window.__ModuleLoader__.load({
|
|
|
4306
3355
|
]
|
|
4307
3356
|
}
|
|
4308
3357
|
|
|
4309
|
-
/**
|
|
3358
|
+
/**
|
|
3359
|
+
* Copy text through the async clipboard API, with a legacy fallback.
|
|
3360
|
+
*
|
|
3361
|
+
* `writeText` can REJECT even in a click handler: when the workbench page is
|
|
3362
|
+
* embedded in the risd maintenance iframe, the parent's permissions policy may
|
|
3363
|
+
* block clipboard-write, and an unhandled rejection here used to surface as
|
|
3364
|
+
* 「后台任务出错」 with the copy silently lost (m09396 ③). So every failure —
|
|
3365
|
+
* missing API, rejected promise, denied permission — falls back to the
|
|
3366
|
+
* textarea + execCommand trick, which only needs the click's user activation.
|
|
3367
|
+
* @param {string} text - the text to copy.
|
|
3368
|
+
* @returns {Promise<boolean>} true when the clipboard (or the fallback) took it.
|
|
3369
|
+
*/
|
|
4310
3370
|
function copyText(text) {
|
|
4311
3371
|
var value = String(text === undefined || text === null ? '' : text)
|
|
3372
|
+
function legacy() {
|
|
3373
|
+
var previousFocus = null
|
|
3374
|
+
var previousRange = null
|
|
3375
|
+
try {
|
|
3376
|
+
previousFocus = document.activeElement
|
|
3377
|
+
var selection = typeof window.getSelection === 'function' ? window.getSelection() : null
|
|
3378
|
+
if (selection !== null && selection.rangeCount > 0) previousRange = selection.getRangeAt(0).cloneRange()
|
|
3379
|
+
} catch { /* no selection API: nothing to restore */ }
|
|
3380
|
+
try {
|
|
3381
|
+
var area = document.createElement('textarea')
|
|
3382
|
+
area.value = value
|
|
3383
|
+
area.setAttribute('readonly', '1')
|
|
3384
|
+
area.style.position = 'fixed'
|
|
3385
|
+
area.style.opacity = '0'
|
|
3386
|
+
document.body.appendChild(area)
|
|
3387
|
+
area.select()
|
|
3388
|
+
var ok = document.execCommand('copy')
|
|
3389
|
+
document.body.removeChild(area)
|
|
3390
|
+
return ok === true
|
|
3391
|
+
} catch {
|
|
3392
|
+
return false
|
|
3393
|
+
} finally {
|
|
3394
|
+
// The textarea stole focus (and the selection): put the user back where
|
|
3395
|
+
// they were, or the next keystroke lands on the body (review C3-P2-13).
|
|
3396
|
+
try {
|
|
3397
|
+
if (previousFocus !== null && typeof previousFocus.focus === 'function') {
|
|
3398
|
+
previousFocus.focus({ preventScroll: true })
|
|
3399
|
+
}
|
|
3400
|
+
if (previousRange !== null) {
|
|
3401
|
+
var restored = window.getSelection()
|
|
3402
|
+
restored.removeAllRanges()
|
|
3403
|
+
restored.addRange(previousRange)
|
|
3404
|
+
}
|
|
3405
|
+
} catch { /* best effort */ }
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
4312
3408
|
try {
|
|
4313
3409
|
if (typeof navigator !== 'undefined' && navigator !== null
|
|
4314
3410
|
&& navigator.clipboard !== undefined && typeof navigator.clipboard.writeText === 'function') {
|
|
4315
|
-
|
|
4316
|
-
|
|
3411
|
+
return Promise.resolve(navigator.clipboard.writeText(value)).then(
|
|
3412
|
+
function () { return true },
|
|
3413
|
+
function () { return legacy() },
|
|
3414
|
+
)
|
|
4317
3415
|
}
|
|
4318
3416
|
} catch {
|
|
4319
3417
|
// fall through to the textarea trick
|
|
4320
3418
|
}
|
|
4321
|
-
|
|
4322
|
-
var area = document.createElement('textarea')
|
|
4323
|
-
area.value = value
|
|
4324
|
-
area.setAttribute('readonly', '1')
|
|
4325
|
-
area.style.position = 'fixed'
|
|
4326
|
-
area.style.opacity = '0'
|
|
4327
|
-
document.body.appendChild(area)
|
|
4328
|
-
area.select()
|
|
4329
|
-
var ok = document.execCommand('copy')
|
|
4330
|
-
document.body.removeChild(area)
|
|
4331
|
-
return ok === true
|
|
4332
|
-
} catch {
|
|
4333
|
-
return false
|
|
4334
|
-
}
|
|
3419
|
+
return Promise.resolve(legacy())
|
|
4335
3420
|
}
|
|
4336
3421
|
|
|
4337
3422
|
/** Basename of a slash path ('' when empty). */
|
|
@@ -7111,7 +6196,9 @@ window.__ModuleLoader__.load({
|
|
|
7111
6196
|
onClick: function () {
|
|
7112
6197
|
var entry = treeMenu.entry
|
|
7113
6198
|
setTreeMenu(null)
|
|
7114
|
-
|
|
6199
|
+
void copyText(fileBaseName(entry.path)).then(function (ok) {
|
|
6200
|
+
notify(ok ? '已复制文件名:' + fileBaseName(entry.path) : '复制失败:剪贴板不可用')
|
|
6201
|
+
})
|
|
7115
6202
|
},
|
|
7116
6203
|
}, '复制文件名'),
|
|
7117
6204
|
h('button', {
|
|
@@ -7119,7 +6206,9 @@ window.__ModuleLoader__.load({
|
|
|
7119
6206
|
onClick: function () {
|
|
7120
6207
|
var entry = treeMenu.entry
|
|
7121
6208
|
setTreeMenu(null)
|
|
7122
|
-
|
|
6209
|
+
void copyText(entry.path).then(function (ok) {
|
|
6210
|
+
notify(ok ? '已复制路径:' + entry.path : '复制失败:剪贴板不可用')
|
|
6211
|
+
})
|
|
7123
6212
|
},
|
|
7124
6213
|
}, '复制文件路径'),
|
|
7125
6214
|
h('button', {
|
|
@@ -7773,6 +6862,21 @@ window.__ModuleLoader__.load({
|
|
|
7773
6862
|
+ '@supports not selector(::-webkit-scrollbar){'
|
|
7774
6863
|
+ '[data-workbench="ris-ide"] *{scrollbar-width:thin;scrollbar-color:rgba(140,140,140,0.55) rgba(127,127,127,0.10)}}'
|
|
7775
6864
|
|
|
6865
|
+
/**
|
|
6866
|
+
* File-tree hover affordance: a faint grey row background under the pointer.
|
|
6867
|
+
*
|
|
6868
|
+
* A background changes no metrics, so the row and every sibling stay put —
|
|
6869
|
+
* padding/height hacks would make the tree jump under the mouse. The selected
|
|
6870
|
+
* rows (S.treeRowOn / treeRowMulti) carry their tint as an INLINE style, so
|
|
6871
|
+
* this stylesheet-level hover always loses to them: 「优先级低于选中后的背景色」
|
|
6872
|
+
* holds without extra rules (user口径: hover 用浅灰背景,别比选中色重). Underline
|
|
6873
|
+
* was tried first and was too subtle at a 14px row height.
|
|
6874
|
+
*/
|
|
6875
|
+
var TREE_HOVER_CSS = '[data-workbench="ris-ide"] [data-tree-path]:hover'
|
|
6876
|
+
// The plain rgba line is the fallback for engines without `color-mix`
|
|
6877
|
+
// (Chromium < 111): without it the hover rule would be dropped entirely.
|
|
6878
|
+
+ '{background:rgba(0,0,0,0.05);background:color-mix(in srgb, currentColor 7%, transparent)}'
|
|
6879
|
+
|
|
7776
6880
|
/**
|
|
7777
6881
|
* The editor's find panel, restyled to belong to the IDE (user口径: 美化一下
|
|
7778
6882
|
* 编辑器的搜索面板,风格和整体不一致). CodeMirror ships a 2018-looking strip:
|
|
@@ -8277,8 +7381,6 @@ window.__ModuleLoader__.load({
|
|
|
8277
7381
|
})
|
|
8278
7382
|
}
|
|
8279
7383
|
function ProgramWorkbench(props) {
|
|
8280
|
-
/** The 「代理」 dialog (address + rule table); see `ProxyDialog`. */
|
|
8281
|
-
var [proxyOpen, setProxyOpen] = useState(false)
|
|
8282
7384
|
var scope = props ? props.scope : undefined
|
|
8283
7385
|
var tab = props ? props.tab : undefined
|
|
8284
7386
|
var meta = tab !== null && tab !== undefined && tab.meta !== null && typeof tab.meta === 'object' ? tab.meta : {}
|
|
@@ -9431,6 +8533,46 @@ var [ui, setUi] = useState(function () {
|
|
|
9431
8533
|
}
|
|
9432
8534
|
return true
|
|
9433
8535
|
}
|
|
8536
|
+
/**
|
|
8537
|
+
* Answer the maintenance page's questions about unsaved buffers, and save
|
|
8538
|
+
* them all on request (m10900).
|
|
8539
|
+
*
|
|
8540
|
+
* The page embeds this window in an iframe on a different origin (daemon
|
|
8541
|
+
* port vs the dsh web port), so it cannot read `docs`; it asks over
|
|
8542
|
+
* postMessage before it reloads itself. Only the immediate parent is served,
|
|
8543
|
+
* and only these two message shapes, so another opener cannot drive the
|
|
8544
|
+
* editor. A page that predates the bridge simply never asks.
|
|
8545
|
+
*/
|
|
8546
|
+
useEffect(function () {
|
|
8547
|
+
var reply = function (payload) {
|
|
8548
|
+
try { window.parent.postMessage(payload, '*') } catch { /* parent gone */ }
|
|
8549
|
+
}
|
|
8550
|
+
var onMessage = function (event) {
|
|
8551
|
+
if (event.source !== window.parent) return
|
|
8552
|
+
var data = event.data
|
|
8553
|
+
if (data === null || typeof data !== 'object') return
|
|
8554
|
+
if (data.type === 'dsh-ris-ide:probe-dirty') {
|
|
8555
|
+
var dirty = openFiles.filter(function (path) { return isDirty(path) === true })
|
|
8556
|
+
reply({
|
|
8557
|
+
type: 'dsh-ris-ide:dirty-report',
|
|
8558
|
+
requestId: data.requestId,
|
|
8559
|
+
count: dirty.length,
|
|
8560
|
+
names: dirty.slice(0, 5).map(fileBaseName),
|
|
8561
|
+
})
|
|
8562
|
+
return
|
|
8563
|
+
}
|
|
8564
|
+
if (data.type === 'dsh-ris-ide:save-all') {
|
|
8565
|
+
var pending = openFiles.filter(function (path) { return isDirty(path) === true })
|
|
8566
|
+
Promise.resolve(saveBulk(pending)).then(function (ok) {
|
|
8567
|
+
reply({ type: 'dsh-ris-ide:save-all-done', requestId: data.requestId, ok: ok === true })
|
|
8568
|
+
}, function () {
|
|
8569
|
+
reply({ type: 'dsh-ris-ide:save-all-done', requestId: data.requestId, ok: false })
|
|
8570
|
+
})
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
window.addEventListener('message', onMessage)
|
|
8574
|
+
return function () { window.removeEventListener('message', onMessage) }
|
|
8575
|
+
}, [openFiles, docs, viewerStates])
|
|
9434
8576
|
/**
|
|
9435
8577
|
* Bulk close (right-click → 关闭其他/全部关闭). Dirty tabs are never dropped
|
|
9436
8578
|
* silently: one prompt offers save-all / discard-all / cancel for the batch.
|
|
@@ -10349,24 +9491,9 @@ var [ui, setUi] = useState(function () {
|
|
|
10349
9491
|
applyFind(0)
|
|
10350
9492
|
}
|
|
10351
9493
|
}
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
// First load with no explicit target: pick the first RUNNING service (else the
|
|
10356
|
-
// first program) so both panes show something instead of a blank placeholder.
|
|
10357
|
-
useEffect(function () {
|
|
10358
|
-
var running = programs.filter(function (program) {
|
|
10359
|
-
return program.running !== null && program.running !== undefined && program.running.alive === true
|
|
10360
|
-
})
|
|
10361
|
-
if (running.length === 0) return
|
|
10362
|
-
if (activePathRef.current !== '') return
|
|
10363
|
-
var preferred = running.filter(function (program) { return program.kind === 'spring' })[0] || running[0]
|
|
10364
|
-
if (preferred !== undefined) {
|
|
10365
|
-
setActivePath(preferred.logPath)
|
|
10366
|
-
activePathRef.current = preferred.logPath
|
|
10367
|
-
}
|
|
10368
|
-
}, [runningSignature, sessionId])
|
|
10369
|
-
|
|
9494
|
+
// No auto-pick on first load (m07431): the console starts with no selected row,
|
|
9495
|
+
// so the log pane must stay parked on its placeholder instead of loading and
|
|
9496
|
+
// locating a file the user never asked for. A click on a row is the only way in.
|
|
10370
9497
|
/** Finish a "save then close": the viewer's saveState is the signal. */
|
|
10371
9498
|
useEffect(function () {
|
|
10372
9499
|
if (pendingSaveClose === undefined) return
|
|
@@ -10592,6 +9719,7 @@ var [ui, setUi] = useState(function () {
|
|
|
10592
9719
|
var style = Object.assign({}, base)
|
|
10593
9720
|
if (opts.icon === true) Object.assign(style, { width: 22, minWidth: 22, padding: '1px 0', textAlign: 'center' })
|
|
10594
9721
|
if (typeof opts.width === 'number') Object.assign(style, { width: opts.width, minWidth: opts.width })
|
|
9722
|
+
if (typeof opts.color === 'string') Object.assign(style, { color: opts.color })
|
|
10595
9723
|
if (typeof opts.height === 'number') {
|
|
10596
9724
|
// One fixed row height: the top bar mixes glyph buttons (📄 ⚙ ⟲) with
|
|
10597
9725
|
// two-character ones (A- A+), and padding-only sizing made them differ
|
|
@@ -11647,9 +10775,6 @@ var [ui, setUi] = useState(function () {
|
|
|
11647
10775
|
if (paneConfig !== null && typeof paneConfig.generate === 'function') {
|
|
11648
10776
|
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' }))
|
|
11649
10777
|
}
|
|
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/端口的规则(与侧边栏控制台共用同一份配置)' }))
|
|
11653
10778
|
paneActions.push(button('⟲', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态)' }))
|
|
11654
10779
|
|
|
11655
10780
|
/** Load the visual debug settings from the host (⚙ opens on a fresh read). */
|
|
@@ -11763,12 +10888,9 @@ var [ui, setUi] = useState(function () {
|
|
|
11763
10888
|
'data-theme': themePreference || 'page',
|
|
11764
10889
|
onContextMenu: function (event) { event.preventDefault() },
|
|
11765
10890
|
},
|
|
11766
|
-
proxyOpen === true
|
|
11767
|
-
? h(ProxyDialog, { scope: { sessionId: sessionId, cwd: cwd }, onClose: function () { setProxyOpen(false) } })
|
|
11768
|
-
: null,
|
|
11769
10891
|
// The sidebar's CodeMirror theme pins 13px, so the embedded viewer needs
|
|
11770
10892
|
// this rule, not inheritance, to follow A−/A+.
|
|
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),
|
|
10893
|
+
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 + TREE_HOVER_CSS),
|
|
11772
10894
|
(function () {
|
|
11773
10895
|
var panes = {
|
|
11774
10896
|
tree: h(IdeTree, {
|
|
@@ -12228,6 +11350,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12228
11350
|
*/
|
|
12229
11351
|
function apply(ctx) {
|
|
12230
11352
|
guardWindowErrors(false)
|
|
11353
|
+
watchClientBuild()
|
|
12231
11354
|
if (typeof window !== 'undefined') window.__dshRisIdeWindow = false
|
|
12232
11355
|
// The IDE is a DSH right-Sidebar tab: a tab TYPE (stage one) plus its body
|
|
12233
11356
|
// and chip title (stage two), all through the official registry — no other
|
|
@@ -12275,16 +11398,16 @@ var [ui, setUi] = useState(function () {
|
|
|
12275
11398
|
}, 'dsh-ris-ide: right-sidebar tab title')
|
|
12276
11399
|
// A SECOND entry point for the same panel: a header button in the Session
|
|
12277
11400
|
// header, immediately to the right of DSH's own "open in app" action
|
|
12278
|
-
// (order -10), so it reads as "open this workspace's IDE". It opens the
|
|
12279
|
-
//
|
|
12280
|
-
//
|
|
11401
|
+
// (order -10), so it reads as "open this workspace's IDE". It opens the risd
|
|
11402
|
+
// maintenance page (which embeds the IDE and can switch workspace); when no
|
|
11403
|
+
// daemon is leased it falls back to the plugin's standalone window.
|
|
12281
11404
|
ctx.effect(function () {
|
|
12282
11405
|
return ctx.slots.inject('conversation.session.header.utilities', function () {
|
|
12283
11406
|
return ctx.slots.register({
|
|
12284
11407
|
name: 'conversation.session.header.utilities',
|
|
12285
11408
|
id: 'ris-ide-window',
|
|
12286
11409
|
order: -8,
|
|
12287
|
-
label: function () { return '
|
|
11410
|
+
label: function () { return '打开 risd 维护页(IDE 内嵌)' },
|
|
12288
11411
|
}, RisIdeWindowAction)
|
|
12289
11412
|
})
|
|
12290
11413
|
}, 'dsh-ris-ide: session-header window button')
|
|
@@ -12428,14 +11551,11 @@ var [ui, setUi] = useState(function () {
|
|
|
12428
11551
|
// the single-window notice with a manual choice.
|
|
12429
11552
|
await requestStandaloneWindowClose(windowName)
|
|
12430
11553
|
}
|
|
12431
|
-
// A browser
|
|
12432
|
-
//
|
|
12433
|
-
//
|
|
12434
|
-
|
|
12435
|
-
var
|
|
12436
|
-
var workHeight = screenInfo !== null && typeof screenInfo.availHeight === 'number' && screenInfo.availHeight > 0 ? screenInfo.availHeight : 960
|
|
12437
|
-
var features = 'popup=yes,width=' + workWidth + ',height=' + workHeight + ',left=0,top=0'
|
|
12438
|
-
var handle = window.open(url.href, windowName, features)
|
|
11554
|
+
// A normal browser window/tab: no `popup=…` feature string. Asking for a popup
|
|
11555
|
+
// produced a chromeless window the user could not tab through or maximise like
|
|
11556
|
+
// every other page, and browsers ignore size hints in tabs anyway. The NAME
|
|
11557
|
+
// still keeps one window per workspace: re-opening the same name reuses it.
|
|
11558
|
+
var handle = window.open(url.href, windowName)
|
|
12439
11559
|
if (handle === null || handle === undefined) {
|
|
12440
11560
|
throw new Error('独立窗口被拦截:请允许本站弹窗后重试')
|
|
12441
11561
|
}
|
|
@@ -12521,6 +11641,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12521
11641
|
* @param {{sessionId: string, cwd: string}} props - scope taken from the URL.
|
|
12522
11642
|
* @returns {object} the panel tree.
|
|
12523
11643
|
*/
|
|
11644
|
+
|
|
12524
11645
|
function StandaloneWindow(props) {
|
|
12525
11646
|
var initial = props.sessionId
|
|
12526
11647
|
var scopeState = useState(initial)
|
|
@@ -12564,6 +11685,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12564
11685
|
// instead of letting the browser/dsh treat them as a fatal load failure.
|
|
12565
11686
|
guardWindowErrors(true)
|
|
12566
11687
|
if (typeof window !== 'undefined') window.__dshRisIdeWindow = true
|
|
11688
|
+
watchClientBuild()
|
|
12567
11689
|
var opts = options === null || options === undefined ? {} : options
|
|
12568
11690
|
var sessionId = typeof opts.sessionId === 'string' && opts.sessionId !== '' ? opts.sessionId : STANDALONE_SESSION
|
|
12569
11691
|
var cwd = typeof opts.cwd === 'string' && opts.cwd !== '' ? opts.cwd : knownWorkspaceCwd()
|
|
@@ -12617,6 +11739,193 @@ var [ui, setUi] = useState(function () {
|
|
|
12617
11739
|
}
|
|
12618
11740
|
}
|
|
12619
11741
|
|
|
11742
|
+
/** How long a prefetched daemon address stays fresh (ms). */
|
|
11743
|
+
var RISD_PREFETCH_TTL_MS = 20000
|
|
11744
|
+
|
|
11745
|
+
/**
|
|
11746
|
+
* Warm cache for the daemon address behind ⧉. The header button and the
|
|
11747
|
+
* sidebar console prefetch it on mount, so the click path usually only has to
|
|
11748
|
+
* call `window.open` — the visible delay was the on-demand spawn, but the host
|
|
11749
|
+
* view read is not free either and it sat in front of every click.
|
|
11750
|
+
*
|
|
11751
|
+
* A failed prefetch stays silent: the click then pays one round trip and can
|
|
11752
|
+
* still ask for `ensure`.
|
|
11753
|
+
* @type {{at: number, risd: {available: boolean, url: string}|null, pending: Promise|null}}
|
|
11754
|
+
*/
|
|
11755
|
+
var risdPrefetch = { at: 0, risd: null, pending: null }
|
|
11756
|
+
/** The ⧉ open in flight, so a double click cannot open two tabs. */
|
|
11757
|
+
var risdOpenPending = null
|
|
11758
|
+
|
|
11759
|
+
/** Test seam: forget the warm cache and any open in flight. */
|
|
11760
|
+
function resetRisdPrefetch() {
|
|
11761
|
+
risdPrefetch.at = 0
|
|
11762
|
+
risdPrefetch.risd = null
|
|
11763
|
+
risdPrefetch.pending = null
|
|
11764
|
+
risdOpenPending = null
|
|
11765
|
+
}
|
|
11766
|
+
|
|
11767
|
+
/**
|
|
11768
|
+
* The daemon address inside a host reply, or null when it is unavailable.
|
|
11769
|
+
* @param {object|null} body - parsed reply from the host (`{risd: {...}}`).
|
|
11770
|
+
* @returns {{available: boolean, url: string}|null} the address, or null.
|
|
11771
|
+
*/
|
|
11772
|
+
function risdAddressOf(body) {
|
|
11773
|
+
var risd = body !== null && body !== undefined ? body.risd : null
|
|
11774
|
+
if (risd !== null && risd !== undefined && risd.available === true && typeof risd.url === 'string' && risd.url !== '') {
|
|
11775
|
+
return { available: true, url: risd.url }
|
|
11776
|
+
}
|
|
11777
|
+
return null
|
|
11778
|
+
}
|
|
11779
|
+
|
|
11780
|
+
/**
|
|
11781
|
+
* The cached address while it is younger than the TTL.
|
|
11782
|
+
* @returns {{available: boolean, url: string}|null} the address, or null.
|
|
11783
|
+
*/
|
|
11784
|
+
function risdCachedAddress() {
|
|
11785
|
+
if (risdPrefetch.risd === null) return null
|
|
11786
|
+
if (Date.now() - risdPrefetch.at >= RISD_PREFETCH_TTL_MS) return null
|
|
11787
|
+
return risdPrefetch.risd
|
|
11788
|
+
}
|
|
11789
|
+
|
|
11790
|
+
/**
|
|
11791
|
+
* Remember a fresh answer; the empty one is never cached.
|
|
11792
|
+
* @param {{available: boolean, url: string}|null} risd - the address, or null.
|
|
11793
|
+
* @returns {{available: boolean, url: string}|null} the same value.
|
|
11794
|
+
*/
|
|
11795
|
+
function rememberRisdAddress(risd) {
|
|
11796
|
+
if (risd === null || risd === undefined) return null
|
|
11797
|
+
risdPrefetch.risd = risd
|
|
11798
|
+
risdPrefetch.at = Date.now()
|
|
11799
|
+
return risd
|
|
11800
|
+
}
|
|
11801
|
+
|
|
11802
|
+
/**
|
|
11803
|
+
* `GET /dsh-ris-ide/proxy`, reduced to the daemon address.
|
|
11804
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11805
|
+
* @returns {Promise<{available: boolean, url: string}|null>} the address, or null.
|
|
11806
|
+
*/
|
|
11807
|
+
async function fetchRisdAddress(scope) {
|
|
11808
|
+
var url = routeUrl('dsh-ris-ide/proxy')
|
|
11809
|
+
var sessionId = scope !== null && scope !== undefined && typeof scope.sessionId === 'string' ? scope.sessionId : ''
|
|
11810
|
+
var cwd = scope !== null && scope !== undefined && typeof scope.cwd === 'string' ? scope.cwd : ''
|
|
11811
|
+
if (sessionId !== '') url.searchParams.set('sessionId', sessionId)
|
|
11812
|
+
if (cwd !== '') url.searchParams.set('cwd', cwd)
|
|
11813
|
+
var response = await fetch(url.href, { headers: { accept: 'application/json' } })
|
|
11814
|
+
var body = await response.json().catch(function () { return null })
|
|
11815
|
+
return risdAddressOf(body)
|
|
11816
|
+
}
|
|
11817
|
+
|
|
11818
|
+
/**
|
|
11819
|
+
* The daemon address, from the warm cache when possible.
|
|
11820
|
+
*
|
|
11821
|
+
* In-flight requests are shared, so two mounts (header + console) cost one
|
|
11822
|
+
* request. Failures are silent: the click path falls back to `ensure`.
|
|
11823
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11824
|
+
* @returns {Promise<{available: boolean, url: string}|null>} the address, or null.
|
|
11825
|
+
*/
|
|
11826
|
+
function prefetchRisd(scope) {
|
|
11827
|
+
var cached = risdCachedAddress()
|
|
11828
|
+
if (cached !== null) return Promise.resolve(cached)
|
|
11829
|
+
if (risdPrefetch.pending !== null) return risdPrefetch.pending
|
|
11830
|
+
var pending = fetchRisdAddress(scope).then(function (risd) {
|
|
11831
|
+
risdPrefetch.pending = null
|
|
11832
|
+
return rememberRisdAddress(risd)
|
|
11833
|
+
}, function () {
|
|
11834
|
+
risdPrefetch.pending = null
|
|
11835
|
+
return null
|
|
11836
|
+
})
|
|
11837
|
+
risdPrefetch.pending = pending
|
|
11838
|
+
return pending
|
|
11839
|
+
}
|
|
11840
|
+
|
|
11841
|
+
/**
|
|
11842
|
+
* Put the maintenance page in its tab, on the IDE view, then focus it.
|
|
11843
|
+
*
|
|
11844
|
+
* Called synchronously from the click when the address is already cached, so
|
|
11845
|
+
* the popup stays inside the user gesture (browsers only allow it there).
|
|
11846
|
+
* @param {{url: string}} risd - the daemon address.
|
|
11847
|
+
* @param {string} cwd - workspace to preselect ('' = the daemon's own choice).
|
|
11848
|
+
* @returns {Window} the opened tab.
|
|
11849
|
+
* @throws {Error} when the browser blocked the popup.
|
|
11850
|
+
*/
|
|
11851
|
+
function openRisdTab(risd, cwd) {
|
|
11852
|
+
// Preselect this workspace but keep the user's own tab: ⧉ says "open the
|
|
11853
|
+
// maintenance page for this workspace", not "switch me to 开发环境" (m11345).
|
|
11854
|
+
// The page remembers the last tab, so an explicit `tab=` here would override
|
|
11855
|
+
// that choice and feel like a menu switch.
|
|
11856
|
+
var query = cwd !== '' ? '?cwd=' + encodeURIComponent(cwd) : ''
|
|
11857
|
+
var target = risd.url + '/ui' + query
|
|
11858
|
+
var handle = window.open(target, 'dsh-risd-ui')
|
|
11859
|
+
if (handle === null) throw new Error('维护页被拦截:请允许本站弹窗后重试')
|
|
11860
|
+
if (typeof handle.focus === 'function') handle.focus()
|
|
11861
|
+
return handle
|
|
11862
|
+
}
|
|
11863
|
+
|
|
11864
|
+
/**
|
|
11865
|
+
* Open the risd maintenance page, which embeds the IDE (and can switch
|
|
11866
|
+
* workspace), instead of spawning one window per workspace.
|
|
11867
|
+
*
|
|
11868
|
+
* The page lives on the daemon origin, so the client cannot guess it: the
|
|
11869
|
+
* host view (`GET /dsh-ris-ide/proxy`) reports `risd.url` while a daemon is
|
|
11870
|
+
* leased — prefetched on mount (see `prefetchRisd`), so ⧉ normally opens
|
|
11871
|
+
* without waiting. A cold click asks the host once and then `ensure`s the
|
|
11872
|
+
* daemon; when daemonMode is off (or the daemon stays unreachable) the
|
|
11873
|
+
* fallback keeps today's behaviour — the standalone window.
|
|
11874
|
+
*
|
|
11875
|
+
* One open at a time: a second click joins the promise in flight instead of
|
|
11876
|
+
* opening a second tab.
|
|
11877
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11878
|
+
* @param {Function} fallback - opens the standalone window when no daemon.
|
|
11879
|
+
* @returns {Promise<'risd'|'window'>} which entry point was used.
|
|
11880
|
+
*/
|
|
11881
|
+
async function openRisdPage(scope, fallback) {
|
|
11882
|
+
var cwd = scope !== null && scope !== undefined && typeof scope.cwd === 'string' ? scope.cwd : ''
|
|
11883
|
+
var sessionId = scope !== null && scope !== undefined && typeof scope.sessionId === 'string' ? scope.sessionId : ''
|
|
11884
|
+
if (risdOpenPending !== null) return risdOpenPending
|
|
11885
|
+
var cached = risdCachedAddress()
|
|
11886
|
+
if (cached !== null) {
|
|
11887
|
+
// No await before the popup: the cached address is the whole answer.
|
|
11888
|
+
openRisdTab(cached, cwd)
|
|
11889
|
+
return 'risd'
|
|
11890
|
+
}
|
|
11891
|
+
var pending = openRisdPageSlow({ sessionId: sessionId, cwd: cwd }, fallback).then(function (result) {
|
|
11892
|
+
risdOpenPending = null
|
|
11893
|
+
return result
|
|
11894
|
+
}, function (error) {
|
|
11895
|
+
risdOpenPending = null
|
|
11896
|
+
throw error
|
|
11897
|
+
})
|
|
11898
|
+
risdOpenPending = pending
|
|
11899
|
+
return pending
|
|
11900
|
+
}
|
|
11901
|
+
|
|
11902
|
+
/**
|
|
11903
|
+
* The cold half of `openRisdPage`: one host round trip, then `ensure`.
|
|
11904
|
+
* @param {{sessionId: string, cwd: string}} scope - owning session.
|
|
11905
|
+
* @param {Function} fallback - opens the standalone window when no daemon.
|
|
11906
|
+
* @returns {Promise<'risd'|'window'>} which entry point was used.
|
|
11907
|
+
*/
|
|
11908
|
+
async function openRisdPageSlow(scope, fallback) {
|
|
11909
|
+
var risd = null
|
|
11910
|
+
try {
|
|
11911
|
+
risd = await prefetchRisd(scope)
|
|
11912
|
+
if (risd === null) {
|
|
11913
|
+
// Stopped or crashed: clicking ⧉ is also the "bring it back" gesture, so
|
|
11914
|
+
// ask the host to spawn the daemon on demand instead of silently falling
|
|
11915
|
+
// back to the old standalone window.
|
|
11916
|
+
var response = await fetch(routeUrl('dsh-ris-ide/risd/ensure').href, { method: 'POST' })
|
|
11917
|
+
var body = await response.json().catch(function () { return null })
|
|
11918
|
+
risd = rememberRisdAddress(risdAddressOf(body))
|
|
11919
|
+
}
|
|
11920
|
+
} catch { /* daemonMode=off or host unreachable: fall back to the window */ }
|
|
11921
|
+
if (risd !== null) {
|
|
11922
|
+
openRisdTab(risd, scope.cwd)
|
|
11923
|
+
return 'risd'
|
|
11924
|
+
}
|
|
11925
|
+
if (typeof fallback === 'function') await fallback()
|
|
11926
|
+
return 'window'
|
|
11927
|
+
}
|
|
11928
|
+
|
|
12620
11929
|
/**
|
|
12621
11930
|
* Session-header action: open the IDE in its own window.
|
|
12622
11931
|
*
|
|
@@ -12637,34 +11946,56 @@ var [ui, setUi] = useState(function () {
|
|
|
12637
11946
|
var sessionId = props !== null && props !== undefined && typeof props.sessionId === 'string' ? props.sessionId : ''
|
|
12638
11947
|
var sessionCwd = sessionWorkspaceCwd(props !== null && props !== undefined ? props.useSessions : undefined, sessionId)
|
|
12639
11948
|
var [blocked, setBlocked] = useState(false)
|
|
11949
|
+
var [opening, setOpening] = useState(false)
|
|
12640
11950
|
useEffect(function () {
|
|
12641
11951
|
if (blocked !== true) return undefined
|
|
12642
11952
|
var timer = setTimeout(function () { setBlocked(false) }, 4000)
|
|
12643
11953
|
return function () { clearTimeout(timer) }
|
|
12644
11954
|
}, [blocked])
|
|
11955
|
+
/** Warm the daemon address; `prefetchRisd` is a no-op while the cache is fresh. */
|
|
11956
|
+
function warmRisdAddress() {
|
|
11957
|
+
void prefetchRisd({ sessionId: sessionId, cwd: sessionCwd })
|
|
11958
|
+
}
|
|
11959
|
+
useEffect(function () {
|
|
11960
|
+
// Warm the daemon address before the click; ⧉ then opens without a wait.
|
|
11961
|
+
warmRisdAddress()
|
|
11962
|
+
}, [sessionId, sessionCwd])
|
|
12645
11963
|
if (blocked === true) {
|
|
12646
11964
|
return h('span', { style: S.windowButtonError, role: 'status', title: '允许本站弹窗后重试' }, '窗口被拦截')
|
|
12647
11965
|
}
|
|
12648
11966
|
async function onClick(event) {
|
|
12649
11967
|
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
11968
|
+
if (opening === true) return
|
|
11969
|
+
setOpening(true)
|
|
12650
11970
|
try {
|
|
12651
|
-
|
|
12652
|
-
|
|
11971
|
+
await openRisdPage({ sessionId: sessionId, cwd: sessionCwd }, async function () {
|
|
11972
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: sessionCwd, windowCwd: sessionCwd })
|
|
11973
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
11974
|
+
})
|
|
12653
11975
|
} catch (error) {
|
|
12654
11976
|
console.warn('dsh-ris-ide: 独立窗口打开失败:' + messageOf(error))
|
|
12655
11977
|
setBlocked(true)
|
|
11978
|
+
} finally {
|
|
11979
|
+
setOpening(false)
|
|
12656
11980
|
}
|
|
12657
11981
|
}
|
|
12658
11982
|
return h('button', {
|
|
12659
11983
|
type: 'button',
|
|
12660
|
-
style: S.windowButton,
|
|
12661
|
-
|
|
12662
|
-
'aria-
|
|
11984
|
+
style: opening === true ? Object.assign({}, S.windowButton, { opacity: 0.62, cursor: 'default' }) : S.windowButton,
|
|
11985
|
+
disabled: opening === true,
|
|
11986
|
+
'aria-busy': opening === true ? 'true' : 'false',
|
|
11987
|
+
title: opening === true ? '正在打开 risd 维护页…' : '打开 risd 维护页(概览 / 代理 / IDE):IDE 内嵌其中,可按工作区切换',
|
|
11988
|
+
'aria-label': opening === true ? '正在打开 risd 维护页' : '打开 risd 维护页(IDE 内嵌,可按工作区切换)',
|
|
12663
11989
|
'data-action': 'ris-ide-window',
|
|
11990
|
+
// Pointer intent is the earliest reliable "about to click" signal: the
|
|
11991
|
+
// address is usually already cached from mount, and this covers a stale
|
|
11992
|
+
// 20 s window without waiting for the click itself.
|
|
11993
|
+
onPointerEnter: warmRisdAddress,
|
|
11994
|
+
onFocus: warmRisdAddress,
|
|
12664
11995
|
onClick: onClick,
|
|
12665
11996
|
},
|
|
12666
|
-
h('span', { style: S.windowButtonIcon, 'aria-hidden': 'true' }, '⧉'),
|
|
12667
|
-
h('span', null, 'RIS-IDE'))
|
|
11997
|
+
h('span', { style: S.windowButtonIcon, 'aria-hidden': 'true' }, opening === true ? '…' : '⧉'),
|
|
11998
|
+
h('span', null, opening === true ? '打开中' : 'RIS-IDE'))
|
|
12668
11999
|
}
|
|
12669
12000
|
|
|
12670
12001
|
/**
|
|
@@ -14339,8 +13670,6 @@ var [ui, setUi] = useState(function () {
|
|
|
14339
13670
|
* already delivered: the log viewer re-reads the tail once (see `reloadNonce`).
|
|
14340
13671
|
*/
|
|
14341
13672
|
var [compactLogNonce, setCompactLogNonce] = useState(0)
|
|
14342
|
-
/** The 「代理」 dialog: address + rule table, shared by both console shapes. */
|
|
14343
|
-
var [compactProxyOpen, setCompactProxyOpen] = useState(false)
|
|
14344
13673
|
useEffect(function () {
|
|
14345
13674
|
if (pendingProgram === null) return undefined
|
|
14346
13675
|
setActive(pendingProgram)
|
|
@@ -14404,6 +13733,19 @@ var [ui, setUi] = useState(function () {
|
|
|
14404
13733
|
setCompactPick(undefined)
|
|
14405
13734
|
setActive(undefined)
|
|
14406
13735
|
}, [sessionIdentity])
|
|
13736
|
+
/** Warm the compact ⧉'s address; a fresh cache makes the click synchronous. */
|
|
13737
|
+
function warmCompactRisd() {
|
|
13738
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
13739
|
+
void prefetchRisd({ sessionId: sessionId, cwd: cwd })
|
|
13740
|
+
}
|
|
13741
|
+
useEffect(function () {
|
|
13742
|
+
// The compact ⧉ shares the header button's warm cache: prefetch while the
|
|
13743
|
+
// user is reading the panel, so the click only has to open the tab. The
|
|
13744
|
+
// host view needs a session id, so a tab whose session is not known yet
|
|
13745
|
+
// waits for the live one instead of earning a 400.
|
|
13746
|
+
warmCompactRisd()
|
|
13747
|
+
return undefined
|
|
13748
|
+
}, [sessionIdentity])
|
|
14407
13749
|
// COMPACT mode is the sidebar panel: console rows on top, ONE program's
|
|
14408
13750
|
// live log below. The full IDE (tree/editor/debug) lives only in the
|
|
14409
13751
|
// standalone window, so the sidebar stays cheap and readable.
|
|
@@ -14452,6 +13794,8 @@ var [ui, setUi] = useState(function () {
|
|
|
14452
13794
|
}, [state.note])
|
|
14453
13795
|
|
|
14454
13796
|
var [busyId, setBusyId] = useState(undefined)
|
|
13797
|
+
/** The compact ⧉ is opening the page: disable it and show progress. */
|
|
13798
|
+
var [openingIde, setOpeningIde] = useState(false)
|
|
14455
13799
|
/** Which action `busyId` is running, for the row mask's wording. */
|
|
14456
13800
|
var [busyKind, setBusyKind] = useState('')
|
|
14457
13801
|
var busyRef = useRef(false)
|
|
@@ -14818,16 +14162,22 @@ var [ui, setUi] = useState(function () {
|
|
|
14818
14162
|
|
|
14819
14163
|
/** Open the standalone window on the picked program (or on the workspace). */
|
|
14820
14164
|
function openCompactWindow() {
|
|
14165
|
+
if (openingIde === true) return
|
|
14821
14166
|
var picked = compactProgram()
|
|
14167
|
+
setOpeningIde(true)
|
|
14822
14168
|
void (async function () {
|
|
14823
14169
|
try {
|
|
14824
|
-
//
|
|
14825
|
-
//
|
|
14826
|
-
|
|
14827
|
-
|
|
14828
|
-
|
|
14170
|
+
// Prefer the risd maintenance page (one tab, all workspaces). Without a
|
|
14171
|
+
// daemon, keep the one-window-per-workspace behaviour.
|
|
14172
|
+
await openRisdPage({ sessionId: sessionId, cwd: cwd }, async function () {
|
|
14173
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: picked !== undefined ? picked.id : undefined })
|
|
14174
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
14175
|
+
else setState(function (prev) { return Object.assign({}, prev, { note: '已切到本工作空间的 IDE 窗口' }) })
|
|
14176
|
+
})
|
|
14829
14177
|
} catch (error) {
|
|
14830
14178
|
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
14179
|
+
} finally {
|
|
14180
|
+
setOpeningIde(false)
|
|
14831
14181
|
}
|
|
14832
14182
|
})()
|
|
14833
14183
|
}
|
|
@@ -14994,9 +14344,6 @@ var [ui, setUi] = useState(function () {
|
|
|
14994
14344
|
}
|
|
14995
14345
|
return h('div', { ref: rootRef, style: S.root, 'data-panel': 'compact' },
|
|
14996
14346
|
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,
|
|
15000
14347
|
h('div', { style: S.bar, 'data-compact-bar': '1' },
|
|
15001
14348
|
h('span', { style: S.status }, state.loading ? '扫描中…' : (state.programs.length + ' 个项目')),
|
|
15002
14349
|
h('span', { style: S.meta, title: state.root }, state.root || ''),
|
|
@@ -15004,11 +14351,6 @@ var [ui, setUi] = useState(function () {
|
|
|
15004
14351
|
// The config actions live on the CONSOLE title bar in both shapes: the
|
|
15005
14352
|
// sidebar's title bar is this top bar, so it gets the same two icons
|
|
15006
14353
|
// 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
|
-
}, '🌐'),
|
|
15012
14354
|
configExists === true
|
|
15013
14355
|
? h('button', {
|
|
15014
14356
|
type: 'button', style: S.paneIcon, 'data-action': 'compact-config-open',
|
|
@@ -15025,10 +14367,23 @@ var [ui, setUi] = useState(function () {
|
|
|
15025
14367
|
onClick: function () { generateConfigFile(configExists ? 'update' : undefined) },
|
|
15026
14368
|
}, busyId === '__config__' ? '…' : '⚙'),
|
|
15027
14369
|
h('button', {
|
|
15028
|
-
type: 'button',
|
|
15029
|
-
|
|
14370
|
+
type: 'button',
|
|
14371
|
+
style: openingIde === true ? Object.assign({}, S.paneButton, { opacity: 0.62, cursor: 'default' }) : S.paneButton,
|
|
14372
|
+
disabled: openingIde === true,
|
|
14373
|
+
'aria-busy': openingIde === true ? 'true' : 'false',
|
|
14374
|
+
'data-action': 'ide-window',
|
|
14375
|
+
title: openingIde === true
|
|
14376
|
+
? '正在打开 risd 维护页…'
|
|
14377
|
+
: '打开 risd 维护页(IDE 内嵌,可按工作区切换)' + (picked !== undefined ? ':' + picked.name : ''),
|
|
14378
|
+
// Icon only: the console title bar is tight, and the ⧉ is already the
|
|
14379
|
+
// IDE's mark everywhere else in the panel (aria-label keeps the text).
|
|
14380
|
+
'aria-label': openingIde === true
|
|
14381
|
+
? '正在打开 risd 维护页'
|
|
14382
|
+
: '打开 risd 维护页(IDE 内嵌)' + (picked !== undefined ? ':' + picked.name : ''),
|
|
14383
|
+
onPointerEnter: warmCompactRisd,
|
|
14384
|
+
onFocus: warmCompactRisd,
|
|
15030
14385
|
onClick: openCompactWindow,
|
|
15031
|
-
}, '
|
|
14386
|
+
}, openingIde === true ? '…' : '⧉'),
|
|
15032
14387
|
h('button', {
|
|
15033
14388
|
type: 'button', style: state.loading ? S.paneIconOff : S.paneIcon,
|
|
15034
14389
|
disabled: state.loading, 'data-action': 'compact-rescan',
|
|
@@ -15355,13 +14710,21 @@ var [ui, setUi] = useState(function () {
|
|
|
15355
14710
|
standaloneWindowName: standaloneWindowName,
|
|
15356
14711
|
STANDALONE_SESSION: STANDALONE_SESSION,
|
|
15357
14712
|
openInstanceLog: openInstanceLog,
|
|
14713
|
+
// The risd page opener: the prefetch cache, the address picker and the
|
|
14714
|
+
// open-at-most-once guard are what keep ⧉ from waiting (and from opening
|
|
14715
|
+
// two tabs); the tests drive them against a fake fetch/window.
|
|
14716
|
+
openRisdPage: openRisdPage,
|
|
14717
|
+
prefetchRisd: prefetchRisd,
|
|
14718
|
+
risdCachedAddress: risdCachedAddress,
|
|
14719
|
+
risdAddressOf: risdAddressOf,
|
|
14720
|
+
resetRisdPrefetch: resetRisdPrefetch,
|
|
14721
|
+
RISD_PREFETCH_TTL_MS: RISD_PREFETCH_TTL_MS,
|
|
15358
14722
|
requestStart: requestStart,
|
|
15359
14723
|
generateConfig: generateConfig,
|
|
15360
14724
|
drainOpenRequests: drainOpenRequests,
|
|
15361
14725
|
ProgramWorkbench: ProgramWorkbench,
|
|
15362
14726
|
ProgramsPanel: ProgramsPanel,
|
|
15363
14727
|
// Proxy dialog (address + rule table), rendered from both console shapes.
|
|
15364
|
-
ProxyDialog: ProxyDialog,
|
|
15365
14728
|
IdeErrorBoundary: IdeErrorBoundary,
|
|
15366
14729
|
PROGRAM_TAB_ID: PROGRAM_TAB_ID,
|
|
15367
14730
|
// The compact sidebar shape: its default log-pane height (240px) and the
|