diff options
Diffstat (limited to 'src/hooks/useInstallationActions.ts')
| -rw-r--r-- | src/hooks/useInstallationActions.ts | 89 |
1 files changed, 89 insertions, 0 deletions
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<boolean>(false); + const [isUninstalling, setIsUninstalling] = useState<boolean>(false); + + const handleInstall = async ( + setIsInstalled: (value: boolean) => void, + setInstallationStatus: (value: string) => void, + reloadConfig?: () => Promise<void> + ) => { + 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 + }; +} |
