Skip to content

Commit

Permalink
feat: adjust the delay display interval and color, close zzzgydi#836
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Oct 29, 2023
1 parent 5fe2be0 commit 510a0c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
10 changes: 2 additions & 8 deletions src/components/proxy/proxy-item-mini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)}

Expand Down
10 changes: 2 additions & 8 deletions src/components/proxy/proxy-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)}

Expand Down
15 changes: 15 additions & 0 deletions src/services/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 510a0c5

Please sign in to comment.