From ec7b68321e34dbf04a2ae0656112948bd1448e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Papie=C5=BC?= Date: Fri, 6 Dec 2024 11:19:46 +0100 Subject: [PATCH] Remove unused hook --- src/hooks/app/useUpdateStatus.ts | 90 -------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 src/hooks/app/useUpdateStatus.ts diff --git a/src/hooks/app/useUpdateStatus.ts b/src/hooks/app/useUpdateStatus.ts deleted file mode 100644 index af53e6811..000000000 --- a/src/hooks/app/useUpdateStatus.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { useCallback, useState } from 'react'; -import { check, Update } from '@tauri-apps/plugin-updater'; -import { relaunch } from '@tauri-apps/plugin-process'; - -import { useAppStateStore } from '@app/store/appStateStore'; -import { useAppConfigStore } from '@app/store/useAppConfigStore'; -import { useUIStore } from '@app/store/useUIStore'; - -export const useHandleUpdate = () => { - const setIsAfterAutoUpdate = useAppStateStore((s) => s.setIsAfterAutoUpdate); - const setError = useAppStateStore((s) => s.setError); - const auto_update = useAppConfigStore((s) => s.auto_update); - const [updateData, setUpdateData] = useState(); - const [isLoading, setIsLoading] = useState(false); - const [contentLength, setContentLength] = useState(0); - const [downloaded, setDownloaded] = useState(0); - const setDialogToShow = useUIStore((s) => s.setDialogToShow); - - const handleClose = useCallback(() => { - setDialogToShow(null); - setIsAfterAutoUpdate(true); - }, [setIsAfterAutoUpdate, setDialogToShow]); - - const handleUpdate = useCallback(async () => { - if (!updateData) return; - setIsLoading(true); - console.info('Installing latest version of Tari Universe'); - - updateData - .downloadAndInstall(async (event) => { - switch (event.event) { - case 'Started': - setContentLength(event.data.contentLength || 0); - break; - case 'Progress': - setDownloaded((c) => c + event.data.chunkLength); - break; - case 'Finished': - console.info('download finished'); - break; - } - }) - .then(async () => { - handleClose(); - await relaunch(); - }) - .catch((e) => { - console.error(e); - setError(e); - }); - }, [handleClose, setError, updateData]); - - const fetchUpdate = useCallback(async () => { - const update = await check(); - if (update) { - setUpdateData(update); - - if (auto_update) { - await handleUpdate(); - } - } - }, [auto_update, handleUpdate]); - - return { - fetchUpdate, - handleUpdate, - updateData, - isLoading, - contentLength, - handleClose, - downloaded, - }; -}; - -export const useCheckUpdate = () => { - const setIsAfterAutoUpdate = useAppStateStore((s) => s.setIsAfterAutoUpdate); - const setDialogToShow = useUIStore((s) => s.setDialogToShow); - - return useCallback(() => { - check() - .then((updateRes) => { - if (updateRes && updateRes.available) { - setDialogToShow('autoUpdate'); - } else { - setIsAfterAutoUpdate(true); - } - }) - .catch(() => setIsAfterAutoUpdate(true)); - }, [setDialogToShow, setIsAfterAutoUpdate]); -};