dsh-ris-ide 1.8.6 → 1.8.7
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/bin/run-with-log.sh +28 -10
- package/lib/client.js +391 -103
- package/lib/index.js +117 -29
- package/lib/proxy-lifecycle.js +502 -0
- package/lib/proxy.js +50 -0
- package/lib/risd/server.js +144 -38
- package/lib/risd/ui.js +114 -23
- package/package.json +2 -2
- package/test/client-viewer.test.mjs +223 -26
- package/test/clipboard.test.mjs +41 -2
- package/test/host-tail.test.mjs +64 -1
- package/test/proxy-lifecycle.test.mjs +251 -0
- package/test/proxy.test.mjs +48 -0
- package/test/risd-api.test.mjs +4 -1
- package/test/risd-engine.test.mjs +45 -3
- package/test/risd-follow-start.test.mjs +3 -2
- package/test/risd-handoff.test.mjs +4 -2
- package/test/risd-helpers.mjs +23 -2
- package/test/risd-teardown.test.mjs +4 -2
- package/test/risd-ui.test.mjs +21 -2
package/lib/risd/server.js
CHANGED
|
@@ -24,6 +24,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
24
24
|
import { DEFAULT_RISD_PORT, RISD_API_VERSION, newRisdToken, readRisdState, removeRisdState, writeRisdState } from './state.js'
|
|
25
25
|
import { createLeaseRegistry } from './leases.js'
|
|
26
26
|
import { injectionFor, mergeConfigs, pidAlive, proxyHomeDir, proxyLogPath, proxyPid, proxyStatus, readProxyConfig, readTail, startProxy, stopProxy, writeProxyConfig } from '../proxy.js'
|
|
27
|
+
import { proxyServiceSnapshot, releaseProxyLifecycle, setProxyPhaseListener, startProxyService, stopProxyService } from '../proxy-lifecycle.js'
|
|
27
28
|
import { BUNDLE_URLS, MAX_TGZ_BYTES, ensureBundle, installDir, installFromTgz, isInstalled, readManifest, resolveBundleUrls } from '../proxybridge-bundle.js'
|
|
28
29
|
// The digest helpers are part of the bundle module's contract for this release but
|
|
29
30
|
// arrive with the download/upload work; access them through the namespace so this
|
|
@@ -681,6 +682,9 @@ export async function startRisd({ home, port = DEFAULT_RISD_PORT, version = '0.0
|
|
|
681
682
|
if (cwd !== null) {
|
|
682
683
|
try { await stopProxy(cwd) } catch { /* best effort */ }
|
|
683
684
|
}
|
|
685
|
+
// Whatever the phase was (running, or 待启动 with nothing spawned), the network
|
|
686
|
+
// is down now: drop a pending wait and record `stopped`.
|
|
687
|
+
try { releaseProxyLifecycle() } catch { /* best effort */ }
|
|
684
688
|
}
|
|
685
689
|
// Promise of the in-flight 「跟随 dsh」 start (null when idle). Declared here because
|
|
686
690
|
// scheduleTeardown reads it; the start half is defined further down, next to the
|
|
@@ -820,6 +824,30 @@ export async function startRisd({ home, port = DEFAULT_RISD_PORT, version = '0.0
|
|
|
820
824
|
// (a restart re-discovers the engine by pidfile and reports owned:false until
|
|
821
825
|
// someone starts/stops it again).
|
|
822
826
|
let engineCwd = null
|
|
827
|
+
// 待启动/running/stopped changes arrive from the lifecycle watcher (which may fire
|
|
828
|
+
// long after the request that armed it). The daemon keeps itself resident while a
|
|
829
|
+
// wait or an engine exists, adopts an engine the watcher brought up, and lets the
|
|
830
|
+
// usual idle rule apply once everything is down.
|
|
831
|
+
setProxyPhaseListener((snapshot) => {
|
|
832
|
+
try {
|
|
833
|
+
if (snapshot.phase === 'running') {
|
|
834
|
+
if (typeof snapshot.cwd === 'string' && snapshot.cwd !== '') engineCwd = snapshot.cwd
|
|
835
|
+
cancelIdleExit()
|
|
836
|
+
return
|
|
837
|
+
}
|
|
838
|
+
if (snapshot.phase === 'pending') {
|
|
839
|
+
engineCwd = null
|
|
840
|
+
cancelIdleExit()
|
|
841
|
+
return
|
|
842
|
+
}
|
|
843
|
+
// stopped: the watcher stopped the engine and the bridge by itself.
|
|
844
|
+
if (snapshot.reason !== '' && snapshot.reason !== '已停止') lastBridgeStart = null
|
|
845
|
+
engineCwd = null
|
|
846
|
+
if (leases.count() === 0) scheduleIdleExit()
|
|
847
|
+
} catch {
|
|
848
|
+
/* a listener must never break the watcher */
|
|
849
|
+
}
|
|
850
|
+
})
|
|
823
851
|
// Last background enforcement reload (POST /v1/proxy hands the slow part off, so a
|
|
824
852
|
// save returns in milliseconds instead of waiting ~8s for two PowerShell probes).
|
|
825
853
|
let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
@@ -852,6 +880,9 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
852
880
|
if (lifecycle.proxy.startWithDsh !== true) return Promise.resolve({ action: 'skipped', reason: 'not-following-dsh' })
|
|
853
881
|
if (followStarting !== null) return Promise.resolve({ action: 'skipped', reason: 'starting' })
|
|
854
882
|
if (engineSummary().state === 'running') return Promise.resolve({ action: 'skipped', reason: 'running' })
|
|
883
|
+
// A 待启动 wait is already armed and will start the engine on its own: another
|
|
884
|
+
// lease must not restart the probe loop (or replace its cwd).
|
|
885
|
+
if (proxyServiceSnapshot().phase === 'pending') return Promise.resolve({ action: 'skipped', reason: 'pending' })
|
|
855
886
|
// The in-flight promise stays reachable: teardown must be able to wait for a
|
|
856
887
|
// start that the departing lease itself kicked off (see scheduleTeardown).
|
|
857
888
|
const work = (async () => {
|
|
@@ -865,20 +896,38 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
865
896
|
if (buildProfile(status.config).rules.length === 0) return { action: 'skipped', reason: 'no-rules' }
|
|
866
897
|
if (leases.count() === 0) return { action: 'skipped', reason: 'no-lease' }
|
|
867
898
|
const result = await serializeEngine(async () => {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
899
|
+
// Same gate as a click (the user asked for 「跟随 dsh」, not for a half-up
|
|
900
|
+
// engine): an unreachable SOCKS parks in 待启动 and the watcher retries.
|
|
901
|
+
const outcome = await startProxyService({
|
|
902
|
+
cwd: where,
|
|
903
|
+
interactive: false,
|
|
904
|
+
syncGit: (plan) => syncGitProxy(plan),
|
|
905
|
+
startBridge: (options) => serializeBridge(() => startRedirectors(options)),
|
|
906
|
+
stopBridge: () => serializeBridge(() => stopRedirector()),
|
|
907
|
+
})
|
|
908
|
+
const redirector = outcome.redirector
|
|
909
|
+
if (redirector !== null && typeof redirector === 'object') {
|
|
910
|
+
noteBridgeStart(redirector)
|
|
911
|
+
if (redirector.running === true || (Array.isArray(redirector.started) && redirector.started.length > 0)) {
|
|
912
|
+
bridgeReloadState = { at: Date.now(), ok: true, note: '' }
|
|
913
|
+
}
|
|
873
914
|
}
|
|
874
|
-
|
|
875
|
-
if (engine.ok === true) {
|
|
915
|
+
if (outcome.phase === 'running') {
|
|
876
916
|
engineCwd = where
|
|
877
|
-
|
|
917
|
+
} else {
|
|
918
|
+
engineCwd = null
|
|
878
919
|
}
|
|
879
|
-
|
|
920
|
+
// Both running and 待启动 need the daemon present.
|
|
921
|
+
cancelIdleExit()
|
|
922
|
+
return Object.assign({}, outcome.engine, {
|
|
923
|
+
redirector,
|
|
924
|
+
git: outcome.git,
|
|
925
|
+
phase: outcome.phase,
|
|
926
|
+
waiting: outcome.waiting === true,
|
|
927
|
+
})
|
|
880
928
|
})
|
|
881
|
-
|
|
929
|
+
const settled = result.phase === 'pending' ? 'waiting' : (result.ok === true ? 'started' : 'failed')
|
|
930
|
+
return { action: settled, result }
|
|
882
931
|
})()
|
|
883
932
|
followStarting = work.finally(() => {
|
|
884
933
|
followStarting = null
|
|
@@ -1500,36 +1549,63 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
1500
1549
|
let result
|
|
1501
1550
|
if (action === 'start') {
|
|
1502
1551
|
result = await serializeEngine(async () => {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1552
|
+
// The lifecycle probes SOCKS first: an unreachable upstream parks in
|
|
1553
|
+
// 待启动 instead of spawning an engine that would fail every tunnel.
|
|
1554
|
+
const outcome = await startProxyService({
|
|
1555
|
+
cwd,
|
|
1556
|
+
gitHost,
|
|
1557
|
+
interactive,
|
|
1558
|
+
syncGit: (plan) => syncGitProxy(plan),
|
|
1559
|
+
startBridge: (options) => serializeBridge(() => startRedirectors(options)),
|
|
1560
|
+
stopBridge: () => serializeBridge(() => stopRedirector()),
|
|
1561
|
+
})
|
|
1562
|
+
const redirector = outcome.redirector
|
|
1563
|
+
if (redirector !== null && typeof redirector === 'object') {
|
|
1564
|
+
noteBridgeStart(redirector)
|
|
1565
|
+
if (redirector.running === true || (Array.isArray(redirector.started) && redirector.started.length > 0)) clearBridgeNote()
|
|
1566
|
+
}
|
|
1567
|
+
if (outcome.phase === 'running') {
|
|
1509
1568
|
engineCwd = cwd
|
|
1510
1569
|
cancelIdleExit()
|
|
1570
|
+
} else {
|
|
1571
|
+
// 待启动 is still work this daemon owes the user (the watcher will start
|
|
1572
|
+
// the engine), so it must not idle out from under the wait.
|
|
1573
|
+
engineCwd = null
|
|
1574
|
+
cancelIdleExit()
|
|
1511
1575
|
}
|
|
1512
|
-
return Object.assign({}, engine, {
|
|
1576
|
+
return Object.assign({}, outcome.engine, {
|
|
1577
|
+
redirector,
|
|
1578
|
+
git: outcome.git,
|
|
1579
|
+
phase: outcome.phase,
|
|
1580
|
+
waiting: outcome.waiting === true,
|
|
1581
|
+
reason: outcome.reason ?? '',
|
|
1582
|
+
})
|
|
1513
1583
|
})
|
|
1514
1584
|
} else if (action === 'stop') {
|
|
1515
1585
|
result = await serializeEngine(async () => {
|
|
1516
|
-
const
|
|
1517
|
-
|
|
1586
|
+
const outcome = await stopProxyService({
|
|
1587
|
+
cwd,
|
|
1588
|
+
gitHost,
|
|
1589
|
+
syncGit: (plan) => syncGitProxy(plan),
|
|
1590
|
+
startBridge: (options) => serializeBridge(() => startRedirectors(options)),
|
|
1591
|
+
stopBridge: () => serializeBridge(() => stopRedirector()),
|
|
1592
|
+
})
|
|
1518
1593
|
// The card must not keep describing a component we just stopped
|
|
1519
1594
|
// (review A4-P2-8).
|
|
1520
1595
|
lastBridgeStart = null
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1596
|
+
engineCwd = null
|
|
1597
|
+
// Nothing holds the daemon open after an explicit 停止; without this
|
|
1598
|
+
// it stayed resident until the next lease event even though the page
|
|
1599
|
+
// was the only owner (review A3-P2-4).
|
|
1600
|
+
if (leases.count() === 0) scheduleIdleExit()
|
|
1601
|
+
return Object.assign({}, outcome.engine, {
|
|
1602
|
+
redirector: outcome.redirector,
|
|
1603
|
+
git: outcome.git,
|
|
1604
|
+
phase: outcome.phase,
|
|
1605
|
+
})
|
|
1530
1606
|
})
|
|
1531
1607
|
} else if (action === 'status') {
|
|
1532
|
-
result = { engine: engineSummary(), redirector: redirectorStatusCached() }
|
|
1608
|
+
result = { engine: engineSummary(), redirector: redirectorStatusCached(), service: proxyServiceSnapshot() }
|
|
1533
1609
|
} else if (action === 'git-on' || action === 'git-off') {
|
|
1534
1610
|
// The git table changes the machine config through exactly one helper,
|
|
1535
1611
|
// syncGitProxy, which records key+value so cleanup only removes our own
|
|
@@ -1710,6 +1786,7 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
1710
1786
|
logPath: status.logPath,
|
|
1711
1787
|
socksUrl: status.socksUrl,
|
|
1712
1788
|
},
|
|
1789
|
+
service: proxyServiceSnapshot(),
|
|
1713
1790
|
})
|
|
1714
1791
|
}
|
|
1715
1792
|
if (method !== 'POST') return fail(res, 405, 'method-not-allowed', 'GET or POST')
|
|
@@ -1725,15 +1802,40 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
1725
1802
|
if (!existsSync(cwd)) return fail(res, 400, 'bad-request', `cwd does not exist: ${cwd}`)
|
|
1726
1803
|
const result = await serializeEngine(async () => {
|
|
1727
1804
|
if (action === 'start') {
|
|
1728
|
-
const
|
|
1729
|
-
|
|
1730
|
-
|
|
1805
|
+
const outcome = await startProxyService({
|
|
1806
|
+
cwd,
|
|
1807
|
+
interactive: false,
|
|
1808
|
+
syncGit: (plan) => syncGitProxy(plan),
|
|
1809
|
+
startBridge: (options) => serializeBridge(() => startRedirectors(options)),
|
|
1810
|
+
stopBridge: () => serializeBridge(() => stopRedirector()),
|
|
1811
|
+
})
|
|
1812
|
+
// 待启动 keeps the daemon resident: the watcher will start the engine.
|
|
1813
|
+
if (outcome.phase === 'running') engineCwd = cwd
|
|
1814
|
+
else engineCwd = null
|
|
1815
|
+
cancelIdleExit()
|
|
1816
|
+
return Object.assign({}, outcome.engine, {
|
|
1817
|
+
redirector: outcome.redirector,
|
|
1818
|
+
git: outcome.git,
|
|
1819
|
+
phase: outcome.phase,
|
|
1820
|
+
waiting: outcome.waiting === true,
|
|
1821
|
+
reason: outcome.reason ?? '',
|
|
1822
|
+
})
|
|
1731
1823
|
}
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1824
|
+
const outcome = await stopProxyService({
|
|
1825
|
+
cwd,
|
|
1826
|
+
syncGit: (plan) => syncGitProxy(plan),
|
|
1827
|
+
startBridge: (options) => serializeBridge(() => startRedirectors(options)),
|
|
1828
|
+
stopBridge: () => serializeBridge(() => stopRedirector()),
|
|
1829
|
+
})
|
|
1830
|
+
engineCwd = null
|
|
1831
|
+
if (leases.count() === 0) scheduleIdleExit()
|
|
1832
|
+
return Object.assign({}, outcome.engine, {
|
|
1833
|
+
redirector: outcome.redirector,
|
|
1834
|
+
git: outcome.git,
|
|
1835
|
+
phase: outcome.phase,
|
|
1836
|
+
})
|
|
1735
1837
|
})
|
|
1736
|
-
return json(res, 200, { ok: true, cwd, action, result })
|
|
1838
|
+
return json(res, 200, { ok: true, cwd, action, result, service: proxyServiceSnapshot() })
|
|
1737
1839
|
}
|
|
1738
1840
|
|
|
1739
1841
|
if (path === '/v1/leases') {
|
|
@@ -1979,11 +2081,15 @@ let bridgeReloadState = { at: 0, ok: true, note: '' }
|
|
|
1979
2081
|
// `owned` means "this daemon has started the engine during its lifetime"; a
|
|
1980
2082
|
// pidfile found at startup is reported as owned:false so the plugin can still
|
|
1981
2083
|
// show the inherited banner and offer to stop it (Phase 1a behaviour).
|
|
2084
|
+
const service = proxyServiceSnapshot()
|
|
1982
2085
|
try {
|
|
1983
2086
|
const pid = proxyPid()
|
|
1984
|
-
|
|
2087
|
+
// A 待启动 wait is a third state: nothing runs, yet the service is not "off" —
|
|
2088
|
+
// reporting `stopped` made 「跟随 dsh」 start a second watcher on every lease.
|
|
2089
|
+
const state = pid !== null ? 'running' : (service.phase === 'pending' ? 'pending' : 'stopped')
|
|
2090
|
+
return { owned: engineCwd !== null, inherited: engineInherited, pid: pid ?? 0, state, cwd: engineCwd, phase: service.phase }
|
|
1985
2091
|
} catch {
|
|
1986
|
-
return { owned: false, inherited: engineInherited, pid: 0, state: 'unknown', cwd: engineCwd }
|
|
2092
|
+
return { owned: false, inherited: engineInherited, pid: 0, state: 'unknown', cwd: engineCwd, phase: service.phase }
|
|
1987
2093
|
}
|
|
1988
2094
|
}
|
|
1989
2095
|
|
package/lib/risd/ui.js
CHANGED
|
@@ -664,35 +664,112 @@ export function risdUiHtml(options) {
|
|
|
664
664
|
function renderProxyTab(view) {
|
|
665
665
|
state.view = view;
|
|
666
666
|
state.proxyRunning = view.running === true;
|
|
667
|
+
// The service phase is the authoritative story: view.running only says the
|
|
668
|
+
// process exists, while pending(待启动)means "we are waiting for SOCKS and will
|
|
669
|
+
// start by ourselves". It comes from the daemon's shared state file, so a wait
|
|
670
|
+
// started by another process shows here too.
|
|
671
|
+
var service = view.service || {};
|
|
672
|
+
state.proxyPhase = service.phase === 'running' || service.phase === 'pending' || service.phase === 'stopped'
|
|
673
|
+
? service.phase
|
|
674
|
+
: (state.proxyRunning ? 'running' : 'stopped');
|
|
675
|
+
state.proxyWait = state.proxyPhase === 'pending' ? service : null;
|
|
667
676
|
setBridgeStale(state.lastReloadNote || '');
|
|
668
677
|
el('proxy-socks-host').value = view.socks ? view.socks.host : '';
|
|
669
678
|
el('proxy-socks-port').value = view.socks ? view.socks.port : '';
|
|
670
679
|
el('proxy-listen').value = view.listenPort;
|
|
671
680
|
el('proxy-revision').textContent = 'revision ' + view.revision;
|
|
681
|
+
paintProxyPhase();
|
|
682
|
+
var rules = view.rules || [];
|
|
683
|
+
el('proxy-rules').innerHTML = rules.length === 0
|
|
684
|
+
? '<tr><td colspan="7" class="empty">没有规则。系统代理至少需要一条启用且带程序/IP/端口的规则。</td></tr>'
|
|
685
|
+
: rules.map(ruleRow).join('');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Repaint only the engine pill and its button from state (phase/running). Rules,
|
|
690
|
+
* socks inputs and the banner are left alone: a 4 s phase poll must not wipe text
|
|
691
|
+
* the user is typing or a warning written by an earlier click.
|
|
692
|
+
*/
|
|
693
|
+
function paintProxyPhase() {
|
|
672
694
|
var enginePill = el('proxy-engine-pill');
|
|
673
695
|
if (enginePill) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
enginePill.
|
|
696
|
+
var wait = state.proxyWait;
|
|
697
|
+
var waitSeconds = wait && typeof wait.waitingMs === 'number' ? Math.round(wait.waitingMs / 1000) : 0;
|
|
698
|
+
enginePill.className = 'pill ' + (state.proxyPhase === 'running' ? 'on' : (state.proxyPhase === 'pending' ? 'warn' : 'off'));
|
|
699
|
+
enginePill.textContent = state.proxyPhase === 'running'
|
|
700
|
+
? '代理运行中'
|
|
701
|
+
: (state.proxyPhase === 'pending' ? '待启动(等待 SOCKS)' : '代理未运行');
|
|
702
|
+
enginePill.title = state.proxyPhase === 'running'
|
|
703
|
+
? '引擎在跑:合规的行已经生效'
|
|
704
|
+
: (state.proxyPhase === 'pending'
|
|
705
|
+
? ('上游 SOCKS 暂不可达,正在等待' + (waitSeconds > 0 ? '(已等 ' + waitSeconds + ' 秒)' : '') +
|
|
706
|
+
':' + ((wait && wait.socksError) || '未配置') + ';连通后会自动启动' +
|
|
707
|
+
(wait && wait.socksOk === false ? '。代理与系统层拦截都不会启动。' : ''))
|
|
708
|
+
: '保存后如果规则完整会自动启动');
|
|
677
709
|
}
|
|
678
710
|
if (engineBusy) {
|
|
679
711
|
paintEngineButtons();
|
|
680
|
-
|
|
681
|
-
var engineToggle = el('proxy-engine-toggle');
|
|
682
|
-
if (engineToggle) {
|
|
683
|
-
engineToggle.disabled = false;
|
|
684
|
-
engineToggle.removeAttribute('aria-busy');
|
|
685
|
-
engineToggle.textContent = state.proxyRunning ? '停止' : '启动';
|
|
686
|
-
engineToggle.className = state.proxyRunning ? 'danger' : '';
|
|
687
|
-
engineToggle.title = state.proxyRunning
|
|
688
|
-
? '停止引擎、系统层拦截与 git 代理'
|
|
689
|
-
: '按当前规则表启动(保存后规则完整会自动启动;系统层拦截可能需要提权)';
|
|
690
|
-
}
|
|
712
|
+
return;
|
|
691
713
|
}
|
|
692
|
-
var
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
714
|
+
var engineToggle = el('proxy-engine-toggle');
|
|
715
|
+
if (!engineToggle) return;
|
|
716
|
+
engineToggle.disabled = false;
|
|
717
|
+
engineToggle.removeAttribute('aria-busy');
|
|
718
|
+
engineToggle.textContent = state.proxyPhase === 'running' ? '停止' : (state.proxyPhase === 'pending' ? '取消等待' : '启动');
|
|
719
|
+
engineToggle.className = state.proxyPhase === 'running' ? 'danger' : '';
|
|
720
|
+
engineToggle.title = state.proxyPhase === 'running'
|
|
721
|
+
? '停止引擎、系统层拦截与 git 代理'
|
|
722
|
+
: (state.proxyPhase === 'pending'
|
|
723
|
+
? '取消这次(未启动的)代理服务请求'
|
|
724
|
+
: '按当前规则表启动(保存后规则完整会自动启动;系统层拦截可能需要提权)');
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* The waiting phase can turn into running (or stop by itself) without any click
|
|
729
|
+
* here, so the tab needs a cheap heartbeat. Repaint only when the phase or the
|
|
730
|
+
* process state actually changed, and touch just the pills/buttons, never the
|
|
731
|
+
* rule inputs.
|
|
732
|
+
*/
|
|
733
|
+
function refreshProxyPhase() {
|
|
734
|
+
var cwd = state.cwd || '';
|
|
735
|
+
return api('/v1/proxy' + (cwd ? '?cwd=' + encodeURIComponent(cwd) : '')).then(function (view) {
|
|
736
|
+
var service = view.service || {};
|
|
737
|
+
var phase = service.phase === 'running' || service.phase === 'pending' || service.phase === 'stopped'
|
|
738
|
+
? service.phase
|
|
739
|
+
: (view.running === true ? 'running' : 'stopped');
|
|
740
|
+
var running = view.running === true;
|
|
741
|
+
if (phase === state.proxyPhase && running === state.proxyRunning) return;
|
|
742
|
+
state.view = view;
|
|
743
|
+
state.proxyPhase = phase;
|
|
744
|
+
state.proxyRunning = running;
|
|
745
|
+
state.proxyWait = phase === 'pending' ? service : null;
|
|
746
|
+
paintProxyPhase();
|
|
747
|
+
paintRuleStatus();
|
|
748
|
+
}).catch(function () { /* daemon busy/restarting: the next tick retries */ });
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Rule status is derived from the row inputs plus "is the engine running", so it
|
|
753
|
+
* must be recomputed when that flag flips — without re-rendering the inputs.
|
|
754
|
+
*/
|
|
755
|
+
function paintRuleStatus() {
|
|
756
|
+
var table = el('proxy-rules');
|
|
757
|
+
if (!table) return;
|
|
758
|
+
table.querySelectorAll('tr[data-index]').forEach(function (tr) {
|
|
759
|
+
var cell = tr.children[4];
|
|
760
|
+
var enabled = tr.querySelector('[data-field="enabled"]');
|
|
761
|
+
var program = tr.querySelector('[data-field="program"]');
|
|
762
|
+
var hosts = tr.querySelector('[data-field="hosts"]');
|
|
763
|
+
var ports = tr.querySelector('[data-field="ports"]');
|
|
764
|
+
if (!cell || !enabled || !program || !hosts || !ports) return;
|
|
765
|
+
var status = ruleStatus({
|
|
766
|
+
enabled: enabled.checked,
|
|
767
|
+
program: program.value,
|
|
768
|
+
hosts: hosts.value,
|
|
769
|
+
ports: ports.value,
|
|
770
|
+
});
|
|
771
|
+
cell.innerHTML = pill(status.text, status.cls);
|
|
772
|
+
});
|
|
696
773
|
}
|
|
697
774
|
|
|
698
775
|
function rulesFromTable() {
|
|
@@ -1676,6 +1753,7 @@ export function risdUiHtml(options) {
|
|
|
1676
1753
|
var engineBusyAction = '';
|
|
1677
1754
|
function paintEngineButtons() {
|
|
1678
1755
|
var running = state.summary.proxyRunning === true || state.proxyRunning === true;
|
|
1756
|
+
var pending = state.proxyPhase === 'pending' && running !== true;
|
|
1679
1757
|
[el('engine-toggle'), el('proxy-engine-toggle')].forEach(function (button) {
|
|
1680
1758
|
if (!button) return;
|
|
1681
1759
|
if (engineBusy) {
|
|
@@ -1686,7 +1764,7 @@ export function risdUiHtml(options) {
|
|
|
1686
1764
|
}
|
|
1687
1765
|
button.removeAttribute('aria-busy');
|
|
1688
1766
|
button.disabled = false;
|
|
1689
|
-
button.textContent = running ? '停止' : '启动引擎';
|
|
1767
|
+
button.textContent = running ? '停止' : (pending ? '取消等待' : '启动引擎');
|
|
1690
1768
|
button.className = running ? 'danger' : '';
|
|
1691
1769
|
// m05590: starting the engine never asks for a password. The system-layer
|
|
1692
1770
|
// component is a separate click (bridge-fix), so a dialog can only appear
|
|
@@ -1699,7 +1777,9 @@ export function risdUiHtml(options) {
|
|
|
1699
1777
|
function toggleProxyEngine() {
|
|
1700
1778
|
if (engineBusy) return;
|
|
1701
1779
|
var running = state.summary.proxyRunning === true || state.proxyRunning === true;
|
|
1702
|
-
|
|
1780
|
+
// A 待启动 service is not running, but "启动" would only re-arm the same wait:
|
|
1781
|
+
// the button means "取消等待" there, which is the stop action.
|
|
1782
|
+
var action = running || state.proxyPhase === 'pending' ? 'stop' : 'start';
|
|
1703
1783
|
var host = state.tab === 'proxy' ? el('proxy-banner') : el('overview-banner');
|
|
1704
1784
|
host.innerHTML = '';
|
|
1705
1785
|
engineBusy = true;
|
|
@@ -1721,8 +1801,16 @@ export function risdUiHtml(options) {
|
|
|
1721
1801
|
// (评审 20261109-2326 客户端 P2).
|
|
1722
1802
|
// A stop that the OS refused (root-owned CLI) or that lost a race with
|
|
1723
1803
|
// an in-flight start must not look like a clean stop (review B-P1-2/B-P1-5).
|
|
1724
|
-
var
|
|
1725
|
-
|
|
1804
|
+
var pendingStart = action === 'start' && result.phase === 'pending'
|
|
1805
|
+
// A refused start (no upstream configured, engine failed to spawn) still answers
|
|
1806
|
+
// 200 with ok:false: it must not look like a click that did nothing.
|
|
1807
|
+
var failedStart = action === 'start' && result.ok === false && pendingStart !== true
|
|
1808
|
+
var stopBlocked = action === 'stop' && redirector.stopped === false && pendingStart !== true
|
|
1809
|
+
var warn = failedStart
|
|
1810
|
+
? ('启动代理引擎失败:' + (result.error || result.reason || '未知原因'))
|
|
1811
|
+
: pendingStart
|
|
1812
|
+
? (result.reason || '上游 SOCKS 暂不可达,已进入待启动:连通后会自动启动')
|
|
1813
|
+
: stopBlocked
|
|
1726
1814
|
? '系统层拦截未完全停止:' + (redirector.reason || '未知原因') +
|
|
1727
1815
|
(redirector.command ? ';请执行:' + redirector.command : '')
|
|
1728
1816
|
: skipped.length > 0
|
|
@@ -1732,7 +1820,7 @@ export function risdUiHtml(options) {
|
|
|
1732
1820
|
? loadProxyTab().then(function () { return loadHealth(true); })
|
|
1733
1821
|
: refreshOverview().then(function () { return loadHealth(true); })
|
|
1734
1822
|
).then(function () {
|
|
1735
|
-
if (warn !== '') host.innerHTML = banner('warn', warn);
|
|
1823
|
+
if (warn !== '') host.innerHTML = banner(failedStart ? 'err' : 'warn', warn);
|
|
1736
1824
|
});
|
|
1737
1825
|
})
|
|
1738
1826
|
.catch(function (error) {
|
|
@@ -2070,6 +2158,9 @@ export function risdUiHtml(options) {
|
|
|
2070
2158
|
// from the proxy tab was wasted work (review C-P2-3).
|
|
2071
2159
|
if (state.tab === 'ide' || state.tab === 'overview') syncDshTab();
|
|
2072
2160
|
if (state.tab === 'overview') refreshOverview();
|
|
2161
|
+
// 待启动 flips to running on its own once SOCKS comes back: keep the pill honest
|
|
2162
|
+
// without reloading the rule table under the user's cursor.
|
|
2163
|
+
if (state.tab === 'proxy') refreshProxyPhase();
|
|
2073
2164
|
}, 4000);
|
|
2074
2165
|
})();
|
|
2075
2166
|
</script>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ris-ide",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "RIS-IDE local dev panel for the DSH web GUI: live log tail, one-click start/stop of workspace programs, JDWP debugging, file tree + editor, and a standalone IDE window that carries no session history.
|
|
5
|
+
"description": "RIS-IDE local dev panel for the DSH web GUI: live log tail, one-click start/stop of workspace programs, JDWP debugging, file tree + editor, and a standalone IDE window that carries no session history. · DSH 右侧栏本地开发面板:日志实时跟随、一键启停本地程序、Java 断点调试、文件树与编辑器、独立 IDE 窗口。",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"dsh",
|
|
8
8
|
"dsh-plugin",
|