blob: 18de6b57721fc1b5f8a1fa2b413adfe929e638d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import { useState } from "react";
import { installLsfgVk, uninstallLsfgVk } from "../api/lsfgApi";
import {
showInstallSuccessToast,
showInstallErrorToast,
showUninstallSuccessToast,
showUninstallErrorToast
} from "../utils/toastUtils";
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!");
showInstallSuccessToast();
// Reload lsfg config after installation
if (reloadConfig) {
await reloadConfig();
}
} else {
setInstallationStatus(`Installation failed: ${result.error}`);
showInstallErrorToast(result.error);
}
} catch (error) {
setInstallationStatus(`Installation failed: ${error}`);
showInstallErrorToast(String(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!");
showUninstallSuccessToast();
} else {
setInstallationStatus(`Uninstallation failed: ${result.error}`);
showUninstallErrorToast(result.error);
}
} catch (error) {
setInstallationStatus(`Uninstallation failed: ${error}`);
showUninstallErrorToast(String(error));
} finally {
setIsUninstalling(false);
}
};
return {
isInstalling,
isUninstalling,
handleInstall,
handleUninstall
};
}
|