feat: adjust the delay display interval and color, close #836

This commit is contained in:
GyDi 2023-10-29 23:01:05 +08:00
parent 5fe2be031f
commit 510a0c5e70
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
3 changed files with 19 additions and 16 deletions

View File

@ -137,20 +137,14 @@ export const ProxyItemMini = (props: Props) => {
e.stopPropagation();
onDelay();
}}
color={
delay > 500
? "error.main"
: delay < 100
? "success.main"
: "text.secondary"
}
color={delayManager.formatDelayColor(delay)}
sx={({ palette }) =>
!proxy.provider
? { ":hover": { bgcolor: alpha(palette.primary.main, 0.15) } }
: {}
}
>
{delay > 1e5 ? "Error" : delay > 3000 ? "Timeout" : `${delay}`}
{delayManager.formatDelay(delay)}
</Widget>
)}

View File

@ -145,20 +145,14 @@ export const ProxyItem = (props: Props) => {
e.stopPropagation();
onDelay();
}}
color={
delay > 500
? "error.main"
: delay < 100
? "success.main"
: "text.secondary"
}
color={delayManager.formatDelayColor(delay)}
sx={({ palette }) =>
!proxy.provider
? { ":hover": { bgcolor: alpha(palette.primary.main, 0.15) } }
: {}
}
>
{delay > 1e5 ? "Error" : delay > 3000 ? "Timeout" : `${delay}ms`}
{delayManager.formatDelay(delay)}
</Widget>
)}

View File

@ -107,6 +107,21 @@ class DelayManager {
for (let i = 0; i < concurrency; ++i) help();
});
}
formatDelay(delay: number) {
if (delay < 0) return "-";
if (delay > 1e5) return "Error";
if (delay >= 10000) return "Timeout"; // 10s
return `${delay}`;
}
formatDelayColor(delay: number) {
if (delay <= 0) return "text.secondary";
if (delay >= 10000) return "error.main";
if (delay > 500) return "warning.main";
if (delay > 100) return "text.secondary";
return "success.main";
}
}
export default new DelayManager();