fix: update state
This commit is contained in:
parent
9910f6b817
commit
dd605e2610
@ -1,6 +1,7 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import snarkdown from "snarkdown";
|
import snarkdown from "snarkdown";
|
||||||
import { useState, useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import { useRecoilState } from "recoil";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
import { relaunch } from "@tauri-apps/api/process";
|
import { relaunch } from "@tauri-apps/api/process";
|
||||||
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
||||||
import { killSidecars, restartSidecar } from "../../services/cmds";
|
import { killSidecars, restartSidecar } from "../../services/cmds";
|
||||||
|
import { atomUpdateState } from "../../services/states";
|
||||||
import Notice from "../base/base-notice";
|
import Notice from "../base/base-notice";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -24,8 +26,6 @@ const UpdateLog = styled(Box)(() => ({
|
|||||||
"h1,h2,h3,ul,ol,p": { margin: "0.5em 0", color: "inherit" },
|
"h1,h2,h3,ul,ol,p": { margin: "0.5em 0", color: "inherit" },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let uploadingState = false;
|
|
||||||
|
|
||||||
const UpdateDialog = (props: Props) => {
|
const UpdateDialog = (props: Props) => {
|
||||||
const { open, onClose } = props;
|
const { open, onClose } = props;
|
||||||
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
||||||
@ -33,22 +33,22 @@ const UpdateDialog = (props: Props) => {
|
|||||||
revalidateIfStale: false,
|
revalidateIfStale: false,
|
||||||
focusThrottleInterval: 36e5, // 1 hour
|
focusThrottleInterval: 36e5, // 1 hour
|
||||||
});
|
});
|
||||||
const [uploading, setUploading] = useState(uploadingState);
|
|
||||||
|
const [updateState, setUpdateState] = useRecoilState(atomUpdateState);
|
||||||
|
|
||||||
const onUpdate = async () => {
|
const onUpdate = async () => {
|
||||||
setUploading(true);
|
if (updateState) return;
|
||||||
uploadingState = true;
|
setUpdateState(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await installUpdate();
|
|
||||||
await killSidecars();
|
await killSidecars();
|
||||||
|
await installUpdate();
|
||||||
await relaunch();
|
await relaunch();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
await restartSidecar();
|
await restartSidecar();
|
||||||
Notice.error(err?.message || err.toString());
|
Notice.error(err?.message || err.toString());
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false);
|
setUpdateState(false);
|
||||||
uploadingState = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ const UpdateDialog = (props: Props) => {
|
|||||||
<Button
|
<Button
|
||||||
autoFocus
|
autoFocus
|
||||||
variant="contained"
|
variant="contained"
|
||||||
disabled={uploading}
|
disabled={updateState}
|
||||||
onClick={onUpdate}
|
onClick={onUpdate}
|
||||||
>
|
>
|
||||||
Update
|
Update
|
||||||
|
@ -16,3 +16,9 @@ export const atomLoadingCache = atom<Record<string, boolean>>({
|
|||||||
key: "atomLoadingCache",
|
key: "atomLoadingCache",
|
||||||
default: {},
|
default: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// save update state
|
||||||
|
export const atomUpdateState = atom<boolean>({
|
||||||
|
key: "atomUpdateState",
|
||||||
|
default: false,
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user