mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: support update checker
This commit is contained in:
@@ -7,15 +7,15 @@ import {
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import {
|
||||
setSysProxy,
|
||||
getVergeConfig,
|
||||
patchVergeConfig,
|
||||
setSysProxy,
|
||||
} from "../services/cmds";
|
||||
import { CmdType } from "../services/types";
|
||||
import { version } from "../../package.json";
|
||||
import GuardState from "./guard-state";
|
||||
import SettingItem from "./setting-item";
|
||||
import PaletteSwitch from "./palette-switch";
|
||||
import { version } from "../../package.json";
|
||||
|
||||
interface Props {
|
||||
onError?: (err: Error) => void;
|
||||
@@ -32,7 +32,6 @@ const SettingVerge = ({ onError }: Props) => {
|
||||
} = vergeConfig ?? {};
|
||||
|
||||
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||
|
||||
const onChangeData = (patch: Partial<CmdType.VergeConfig>) => {
|
||||
mutate("getVergeConfig", { ...vergeConfig, ...patch }, false);
|
||||
};
|
||||
|
||||
66
src/components/update-dialog.tsx
Normal file
66
src/components/update-dialog.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import useSWR from "swr";
|
||||
import { useState } from "react";
|
||||
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
DialogTitle,
|
||||
} from "@mui/material";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
let uploadingState = false;
|
||||
|
||||
const UpdateDialog = (props: Props) => {
|
||||
const { open, onClose } = props;
|
||||
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
||||
errorRetryCount: 2,
|
||||
revalidateIfStale: false,
|
||||
focusThrottleInterval: 36e5, // 1 hour
|
||||
});
|
||||
const [uploading, setUploading] = useState(uploadingState);
|
||||
|
||||
const onUpdate = async () => {
|
||||
try {
|
||||
setUploading(true);
|
||||
uploadingState = true;
|
||||
await installUpdate();
|
||||
await relaunch();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
window.alert("Failed to upload, please try again.");
|
||||
} finally {
|
||||
setUploading(true);
|
||||
uploadingState = true;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose}>
|
||||
<DialogTitle>New Version v{updateInfo?.manifest?.version}</DialogTitle>
|
||||
<DialogContent sx={{ minWidth: 360, maxWidth: 400, maxHeight: "50vh" }}>
|
||||
<DialogContentText>{updateInfo?.manifest?.body}</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={onClose}>Cancel</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
autoFocus
|
||||
onClick={onUpdate}
|
||||
disabled={uploading}
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateDialog;
|
||||
Reference in New Issue
Block a user