From 77494457e2a4f5c80c3a2f7acb054b12d918d8ad Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Sun, 13 Jul 2025 00:04:54 -0400 Subject: restructure for maintainability --- src/hooks/useInstallationActions.ts | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/hooks/useInstallationActions.ts (limited to 'src/hooks/useInstallationActions.ts') diff --git a/src/hooks/useInstallationActions.ts b/src/hooks/useInstallationActions.ts new file mode 100644 index 0000000..8dcf831 --- /dev/null +++ b/src/hooks/useInstallationActions.ts @@ -0,0 +1,89 @@ +import { useState } from "react"; +import { toaster } from "@decky/api"; +import { installLsfgVk, uninstallLsfgVk } from "../api/lsfgApi"; + +export function useInstallationActions() { + const [isInstalling, setIsInstalling] = useState(false); + const [isUninstalling, setIsUninstalling] = useState(false); + + const handleInstall = async ( + setIsInstalled: (value: boolean) => void, + setInstallationStatus: (value: string) => void, + reloadConfig?: () => Promise + ) => { + setIsInstalling(true); + setInstallationStatus("Installing lsfg-vk..."); + + try { + const result = await installLsfgVk(); + if (result.success) { + setIsInstalled(true); + setInstallationStatus("lsfg-vk installed successfully!"); + toaster.toast({ + title: "Installation Complete", + body: "lsfg-vk has been installed successfully" + }); + + // Reload lsfg config after installation + if (reloadConfig) { + await reloadConfig(); + } + } else { + setInstallationStatus(`Installation failed: ${result.error}`); + toaster.toast({ + title: "Installation Failed", + body: result.error || "Unknown error occurred" + }); + } + } catch (error) { + setInstallationStatus(`Installation failed: ${error}`); + toaster.toast({ + title: "Installation Failed", + body: `Error: ${error}` + }); + } finally { + setIsInstalling(false); + } + }; + + const handleUninstall = async ( + setIsInstalled: (value: boolean) => void, + setInstallationStatus: (value: string) => void + ) => { + setIsUninstalling(true); + setInstallationStatus("Uninstalling lsfg-vk..."); + + try { + const result = await uninstallLsfgVk(); + if (result.success) { + setIsInstalled(false); + setInstallationStatus("lsfg-vk uninstalled successfully!"); + toaster.toast({ + title: "Uninstallation Complete", + body: result.message || "lsfg-vk has been uninstalled successfully" + }); + } else { + setInstallationStatus(`Uninstallation failed: ${result.error}`); + toaster.toast({ + title: "Uninstallation Failed", + body: result.error || "Unknown error occurred" + }); + } + } catch (error) { + setInstallationStatus(`Uninstallation failed: ${error}`); + toaster.toast({ + title: "Uninstallation Failed", + body: `Error: ${error}` + }); + } finally { + setIsUninstalling(false); + } + }; + + return { + isInstalling, + isUninstalling, + handleInstall, + handleUninstall + }; +} -- cgit v1.2.3