clash-verge-rev/src/components/layout/update-button.tsx
Tunglies e414b49879
Refactor imports across multiple components for consistency and clarity
- Reorganized import statements in various components to ensure consistent ordering and grouping.
- Removed unnecessary imports and added missing ones where applicable.
- Improved readability and maintainability of the codebase by standardizing import styles.
2025-09-19 00:01:04 +08:00

50 lines
1.1 KiB
TypeScript

import { Button } from "@mui/material";
import { check } from "@tauri-apps/plugin-updater";
import { useRef } from "react";
import useSWR from "swr";
import { useVerge } from "@/hooks/use-verge";
import { DialogRef } from "../base";
import { UpdateViewer } from "../setting/mods/update-viewer";
interface Props {
className?: string;
}
export const UpdateButton = (props: Props) => {
const { className } = props;
const { verge } = useVerge();
const { auto_check_update } = verge || {};
const viewerRef = useRef<DialogRef>(null);
const { data: updateInfo } = useSWR(
auto_check_update || auto_check_update === null ? "checkUpdate" : null,
check,
{
errorRetryCount: 2,
revalidateIfStale: false,
focusThrottleInterval: 36e5, // 1 hour
},
);
if (!updateInfo?.available) return null;
return (
<>
<UpdateViewer ref={viewerRef} />
<Button
color="error"
variant="contained"
size="small"
className={className}
onClick={() => viewerRef.current?.open()}
>
New
</Button>
</>
);
};