summaryrefslogtreecommitdiff
path: root/src/hooks/useInstallationActions.ts
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-13 00:04:54 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-13 00:04:54 -0400
commit77494457e2a4f5c80c3a2f7acb054b12d918d8ad (patch)
treefad4c4dd2ce69a850b56078444427866dedce9fa /src/hooks/useInstallationActions.ts
parent6cfcaa6c169cb8c898775eee276ff2497ab8f45c (diff)
downloaddecky-lsfg-vk-77494457e2a4f5c80c3a2f7acb054b12d918d8ad.tar.gz
decky-lsfg-vk-77494457e2a4f5c80c3a2f7acb054b12d918d8ad.zip
restructure for maintainability
Diffstat (limited to 'src/hooks/useInstallationActions.ts')
-rw-r--r--src/hooks/useInstallationActions.ts89
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
+ };
+}