From 650e017b723b5eef759edbb2577011d31139d8b3 Mon Sep 17 00:00:00 2001 From: GyDi Date: Fri, 4 Mar 2022 02:10:27 +0800 Subject: [PATCH] fix: when updater failed --- src/components/layout/update-dialog.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/layout/update-dialog.tsx b/src/components/layout/update-dialog.tsx index 3111982..e45383a 100644 --- a/src/components/layout/update-dialog.tsx +++ b/src/components/layout/update-dialog.tsx @@ -1,7 +1,5 @@ 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, @@ -10,7 +8,10 @@ import { DialogContentText, DialogTitle, } from "@mui/material"; -import { killSidecars } from "../../services/cmds"; +import { relaunch } from "@tauri-apps/api/process"; +import { checkUpdate, installUpdate } from "@tauri-apps/api/updater"; +import { killSidecars, restartSidecar } from "../../services/cmds"; +import Notice from "../base/base-notice"; interface Props { open: boolean; @@ -29,18 +30,19 @@ const UpdateDialog = (props: Props) => { const [uploading, setUploading] = useState(uploadingState); const onUpdate = async () => { + setUploading(true); + uploadingState = true; + try { - setUploading(true); - uploadingState = true; await killSidecars(); await installUpdate(); await relaunch(); - } catch (error) { - console.log(error); - window.alert("Failed to upload, please try again."); + } catch (err: any) { + await restartSidecar(); + Notice.error(err?.message || err.toString()); } finally { - setUploading(true); - uploadingState = true; + setUploading(false); + uploadingState = false; } };