Files
CHOMPStation2/tgui/packages/tgui-panel/reconnect.tsx
CHOMPStation2 eebf92d66f [MIRROR] TGUI 5.0 Patch 1 (#7701)
Co-authored-by: Selis <sirlionfur@hotmail.de>
2024-02-08 15:31:06 +01:00

49 lines
1.0 KiB
TypeScript

import { useDispatch } from 'tgui/backend';
import { Button } from 'tgui/components';
import { dismissWarning } from './game/actions';
let url: string | null = null;
setInterval(() => {
Byond.winget('', 'url').then((currentUrl) => {
// Sometimes, for whatever reason, BYOND will give an IP with a :0 port.
if (currentUrl && !currentUrl.match(/:0$/)) {
url = currentUrl;
}
});
}, 5000);
export const ReconnectButton = (props) => {
if (!url) {
return null;
}
const dispatch = useDispatch();
return (
<>
<Button
color="white"
onClick={() => {
Byond.command('.reconnect');
}}>
Reconnect
</Button>
<Button
color="white"
onClick={() => {
location.href = `byond://${url}`;
Byond.command('.quit');
}}>
Relaunch game
</Button>
<Button
color="white"
onClick={() => {
dispatch(dismissWarning());
}}>
Dismiss
</Button>
</>
);
};