forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ping display view in pause menu!
- Loading branch information
Showing
7 changed files
with
135 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.container { | ||
scale: 0.8; | ||
transform-origin: left; | ||
display: grid; | ||
grid-template-columns: auto auto auto auto auto; | ||
gap: 2px 4px; | ||
font-size: 8px; | ||
color: #fff; | ||
opacity: 0.8; | ||
align-items: center; | ||
justify-content: center; | ||
text-align: center; | ||
justify-items: center; | ||
} | ||
|
||
.iconRow { | ||
display: block; | ||
} | ||
.arrowRow { | ||
scale: 1.5 1; | ||
} | ||
|
||
.dataRow { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
max-width: 70px; | ||
font-size: 5px; | ||
} | ||
|
||
.ping { | ||
font-size: 6px; | ||
} | ||
|
||
/* .dataRow > span:nth-child(3) { | ||
max-width: 120px; | ||
} */ | ||
|
||
.totalRow { | ||
grid-column: span 3; | ||
font-size: 7px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
interface CssExports { | ||
arrowRow: string; | ||
container: string; | ||
dataRow: string; | ||
iconRow: string; | ||
ping: string; | ||
totalRow: string; | ||
} | ||
declare const cssExports: CssExports; | ||
export default cssExports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useEffect, useState } from 'react' | ||
import { lastConnectOptions } from './AppStatusProvider' | ||
import PixelartIcon, { pixelartIcons } from './PixelartIcon' | ||
import styles from './NetworkStatus.module.css' | ||
|
||
export default () => { | ||
const [proxyPing, setProxyPing] = useState<number | null>(null) | ||
const [serverPing, setServerPing] = useState<number | null>(null) | ||
|
||
useEffect(() => { | ||
if (!lastConnectOptions.value?.proxy) return | ||
|
||
let update = 0 | ||
|
||
const updatePing = async () => { | ||
const currentUpdate = ++update | ||
|
||
const updateServerPing = async () => { | ||
const ping = await bot.pingServer() | ||
if (ping) setServerPing(ping) | ||
} | ||
|
||
const updateProxyPing = async () => { | ||
const ping = await bot.pingProxy() | ||
setProxyPing(ping) | ||
} | ||
|
||
try { | ||
await Promise.all([updateServerPing(), updateProxyPing()]) | ||
} catch (err) { | ||
console.error('Failed to ping:', err) | ||
} | ||
} | ||
|
||
void updatePing() | ||
const interval = setInterval(updatePing, 1000) | ||
return () => clearInterval(interval) | ||
}, []) | ||
|
||
// if (!lastConnectOptions.value?.proxy) return null | ||
|
||
const { username } = bot.player | ||
const { proxy: proxyUrl, server: serverIp } = lastConnectOptions.value! | ||
const pingTotal = serverPing | ||
|
||
const ICON_SIZE = 18 | ||
return ( | ||
<div className={styles.container}> | ||
<PixelartIcon className={styles.iconRow} iconName={pixelartIcons.monitor} width={ICON_SIZE} /> | ||
<PixelartIcon className={`${styles.iconRow} ${styles.arrowRow}`} iconName={pixelartIcons['arrow-right']} width={16} /> | ||
<PixelartIcon className={styles.iconRow} iconName={pixelartIcons.server} width={ICON_SIZE} /> | ||
<PixelartIcon className={`${styles.iconRow} ${styles.arrowRow}`} iconName={pixelartIcons['arrow-right']} width={16} /> | ||
<PixelartIcon className={styles.iconRow} iconName={pixelartIcons['list-box']} width={ICON_SIZE} /> | ||
|
||
<span className={styles.dataRow}>{username}</span> | ||
<span className={`${styles.dataRow} ${styles.ping}`}>{proxyPing}ms</span> | ||
<span className={styles.dataRow}>{proxyUrl}</span> | ||
<span className={`${styles.dataRow} ${styles.ping}`}>{pingTotal ? pingTotal - (proxyPing ?? 0) : '...'}ms</span> | ||
<span className={styles.dataRow}>{serverIp}</span> | ||
|
||
<span className={styles.totalRow}>Ping: {pingTotal}ms</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters