diff --git a/src/components/Controller.tsx b/src/components/Controller.tsx index f35f9c9..bdb6415 100644 --- a/src/components/Controller.tsx +++ b/src/components/Controller.tsx @@ -21,9 +21,13 @@ export const Controller: React.FC = (props) => { wsc.updateWSCStatus() } updateStatus() - const id = setInterval(updateStatus, 1000) + const id = setInterval(updateStatus, 500) wsc.onWSCMessage((req: { connected: boolean }) => { + if (req['connected'] === undefined) { + return + } + setConnected(req.connected) setTimeout(() => { setInit(true) @@ -35,11 +39,7 @@ export const Controller: React.FC = (props) => { }, []) useEffect(() => { - if (!init) { - return - } - - if (connected) { + if (!init || connected) { return } @@ -47,12 +47,12 @@ export const Controller: React.FC = (props) => { const ws = new WebSocket(`ws://127.0.0.1:${port}`) ws.onclose = (e: CloseEvent) => { if (e.reason !== `FoundYakitWebSocketController` && (port + 1 <= max)) { - setTimeout(() => findPort(port + 1, max), 1000) + setTimeout(() => findPort(port + 1, max), 300) } if (port + 1 > max) { setFindingPort(false) - setAutoFindFailedReason("Yakit 未启动或无法监测到 WebSocket Controller 端口") + setAutoFindFailedReason("Cannot found Yakit or Yakit WebSocket Controller Port is not right") } } ws.onopen = () => { @@ -67,21 +67,29 @@ export const Controller: React.FC = (props) => { const freeze = findingPort || (!init); const safeConnected = connected && init; - return - 断开链接 - : }> - {connected && init ? :
{ - e.preventDefault() + return { + wsc.disconnect() + }}> + Disconnect + : undefined}> + {connected && init ? + : + { + e.preventDefault() - wsc.connect(port) - }}> - {autoFindFailedReason !== '' ? : undefined} - - setPort(e)}/> - - - - - } + wsc.connect(port) + }} + size={"small"} + > + {autoFindFailedReason !== '' ? : undefined} + + setPort(e)}/> + + + + + }
}; \ No newline at end of file diff --git a/src/components/Proxifier.tsx b/src/components/Proxifier.tsx index 2b32a48..80d8724 100644 --- a/src/components/Proxifier.tsx +++ b/src/components/Proxifier.tsx @@ -30,6 +30,10 @@ export const Proxifier: React.FC = (props) => { } wsc.onProxyStatusMessage(msg => { + if (msg['proxy'] === undefined || msg['enable'] === undefined) { + return + } + setInit(true) setProxyEnable(msg.enable) setCurrentProxy(msg.proxy) @@ -42,19 +46,23 @@ export const Proxifier: React.FC = (props) => { wsc.updateProxyStatus() } update() - const id = setInterval(update, 1000) + const id = setInterval(update, 500) return () => { clearInterval(id) } }, []) - return + return { + proxyEnable ? : undefined + }}>
{ e.preventDefault() setInit(false) wsc.setproxy(config.scheme, config.host, config.port) - }} disabled={!init}> - + }} disabled={!init || proxyEnable}> +