.refine ip info

This commit is contained in:
afkarxyz
2026-04-13 22:57:34 +07:00
parent eda188d4b0
commit d85d3174e9
+15 -7
View File
@@ -1,4 +1,4 @@
import { X, Minus, Maximize, SlidersHorizontal, Globe } from "lucide-react"; import { X, Minus, Maximize, SlidersHorizontal, Globe, Eye, EyeOff } from "lucide-react";
import { WindowMinimise, WindowToggleMaximise, Quit } from "../../wailsjs/runtime/runtime"; import { WindowMinimise, WindowToggleMaximise, Quit } from "../../wailsjs/runtime/runtime";
import { Menubar, MenubarContent, MenubarMenu, MenubarItem, MenubarTrigger, MenubarLabel, MenubarSeparator } from "@/components/ui/menubar"; import { Menubar, MenubarContent, MenubarMenu, MenubarItem, MenubarTrigger, MenubarLabel, MenubarSeparator } from "@/components/ui/menubar";
import { fetchCurrentIPInfo } from "@/lib/api"; import { fetchCurrentIPInfo } from "@/lib/api";
@@ -30,6 +30,7 @@ export function TitleBar() {
const [currentIPInfo, setCurrentIPInfo] = useState<CurrentIPInfo | null>(null); const [currentIPInfo, setCurrentIPInfo] = useState<CurrentIPInfo | null>(null);
const [isLoadingCurrentIPInfo, setIsLoadingCurrentIPInfo] = useState(false); const [isLoadingCurrentIPInfo, setIsLoadingCurrentIPInfo] = useState(false);
const [currentIPInfoError, setCurrentIPInfoError] = useState(""); const [currentIPInfoError, setCurrentIPInfoError] = useState("");
const [showIPAddress, setShowIPAddress] = useState(false);
const currentIPInfoRef = useRef<CurrentIPInfo | null>(null); const currentIPInfoRef = useRef<CurrentIPInfo | null>(null);
useEffect(() => { useEffect(() => {
currentIPInfoRef.current = currentIPInfo; currentIPInfoRef.current = currentIPInfo;
@@ -111,21 +112,28 @@ export function TitleBar() {
<MenubarSeparator /> <MenubarSeparator />
<div className="flex items-center gap-1.5 px-2 py-1.5"> <div className="flex items-center gap-1.5 px-2 py-1.5">
<MenubarLabel className="p-0">Network</MenubarLabel> <MenubarLabel className="p-0">Network</MenubarLabel>
{isSpotifyBlockedCountry && (<span className="text-xs font-medium text-destructive">
(Blocked by Spotify)
</span>)}
</div> </div>
<div className="px-2 py-1.5 space-y-1"> <div className="px-2 py-1.5 space-y-1">
<div className="flex items-center gap-2"> <div className="flex items-center justify-between gap-3">
<div className="flex items-center gap-2 min-w-0">
{detectedFlagPath ? (<img src={detectedFlagPath} alt={detectedCountryCode} className="h-3.5 w-[18px] rounded-[2px] border object-cover bg-muted"/>) : (<Globe className="w-4 h-4 opacity-70"/>)} {detectedFlagPath ? (<img src={detectedFlagPath} alt={detectedCountryCode} className="h-3.5 w-[18px] rounded-[2px] border object-cover bg-muted"/>) : (<Globe className="w-4 h-4 opacity-70"/>)}
<span className="font-mono text-xs"> <span className="font-mono text-xs truncate">
{isLoadingCurrentIPInfo {isLoadingCurrentIPInfo
? "Detecting..." ? "Detecting..."
: currentIPInfo : currentIPInfo
? `${currentIPInfo.ip} - ${currentIPInfo.country}${detectedCountryCode ? ` (${detectedCountryCode})` : ""}` ? showIPAddress
? `${currentIPInfo.ip} - ${currentIPInfo.country}${detectedCountryCode ? ` (${detectedCountryCode})` : ""}`
: `${currentIPInfo.country}${detectedCountryCode ? ` (${detectedCountryCode})` : ""}`
: "Unavailable"} : "Unavailable"}
</span> </span>
</div>
{currentIPInfo && !isLoadingCurrentIPInfo && (<button type="button" onClick={() => setShowIPAddress((prev) => !prev)} className="inline-flex h-6 w-6 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground transition-colors" aria-label={showIPAddress ? "Hide IP" : "Show IP"}>
{showIPAddress ? <EyeOff className="h-3.5 w-3.5"/> : <Eye className="h-3.5 w-3.5"/>}
</button>)}
</div> </div>
{isSpotifyBlockedCountry && (<div className="text-xs font-medium text-destructive">
Your Country Blocked by Spotify
</div>)}
{!isLoadingCurrentIPInfo && !currentIPInfo && currentIPInfoError && (<div className="text-xs text-muted-foreground"> {!isLoadingCurrentIPInfo && !currentIPInfo && currentIPInfoError && (<div className="text-xs text-muted-foreground">
IP detection unavailable IP detection unavailable
</div>)} </div>)}