From 204bfa36e53a5df8d5064a1391132d4b31efe35d Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 10 Nov 2025 02:12:16 +0800 Subject: [PATCH] refactor: reorganize imports and remove unused axios instance code --- src/components/home/ip-info-card.tsx | 6 ++-- src/pages/_layout/useLayoutEvents.ts | 2 -- src/services/api.ts | 41 +--------------------------- 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/src/components/home/ip-info-card.tsx b/src/components/home/ip-info-card.tsx index a8f81d381..18360e550 100644 --- a/src/components/home/ip-info-card.tsx +++ b/src/components/home/ip-info-card.tsx @@ -1,11 +1,11 @@ import { LocationOnOutlined, RefreshOutlined, - VisibilityOutlined, VisibilityOffOutlined, + VisibilityOutlined, } from "@mui/icons-material"; -import { Box, Typography, Button, Skeleton, IconButton } from "@mui/material"; -import { useState, useEffect, useCallback, memo } from "react"; +import { Box, Button, IconButton, Skeleton, Typography } from "@mui/material"; +import { memo, useCallback, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { getIpInfo } from "@/services/api"; diff --git a/src/pages/_layout/useLayoutEvents.ts b/src/pages/_layout/useLayoutEvents.ts index c26084a3f..0b7955b30 100644 --- a/src/pages/_layout/useLayoutEvents.ts +++ b/src/pages/_layout/useLayoutEvents.ts @@ -4,7 +4,6 @@ import { useEffect } from "react"; import { mutate } from "swr"; import { useListen } from "@/hooks/use-listen"; -import { getAxios } from "@/services/api"; export const useLayoutEvents = ( handleNotice: (payload: [string, string]) => void, @@ -39,7 +38,6 @@ export const useLayoutEvents = ( register( addListener("verge://refresh-clash-config", async () => { - await getAxios(true); mutate("getProxies"); mutate("getVersion"); mutate("getClashConfig"); diff --git a/src/services/api.ts b/src/services/api.ts index a5508509f..2ad41c272 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,44 +1,4 @@ import { fetch } from "@tauri-apps/plugin-http"; -import axios, { AxiosInstance } from "axios"; - -import { getClashInfo } from "./cmds"; - -let instancePromise: Promise = null!; - -async function getInstancePromise() { - let server = ""; - let secret = ""; - - try { - const info = await getClashInfo(); - - if (info?.server) { - server = info.server; - - // compatible width `external-controller` - if (server.startsWith(":")) server = `127.0.0.1${server}`; - else if (/^\d+$/.test(server)) server = `127.0.0.1:${server}`; - } - if (info?.secret) secret = info?.secret; - } catch {} - - const axiosIns = axios.create({ - baseURL: `http://${server}`, - headers: secret ? { Authorization: `Bearer ${secret}` } : {}, - timeout: 15000, - }); - axiosIns.interceptors.response.use((r) => r.data); - return axiosIns; -} - -/// initialize some information -/// enable force update axiosIns -export const getAxios = async (force: boolean = false) => { - if (!instancePromise || force) { - instancePromise = getInstancePromise(); - } - return instancePromise; -}; // Get current IP and geolocation information (refactored IP detection with service-specific mappings) interface IpInfo { @@ -213,6 +173,7 @@ export const getIpInfo = async (): Promise => { timeoutId = setTimeout(() => { timeoutController.abort(); }, service.timeout || serviceTimeout); + console.debug("Fetching IP information..."); const response = await fetch(service.url, { method: "GET",