From 22afb4268aa44dd4b9422e4803c8f486ad96c34b Mon Sep 17 00:00:00 2001 From: LukeGus Date: Fri, 19 Dec 2025 20:31:03 -0600 Subject: [PATCH] fix: cleanup files --- src/locales/en/translation.json | 1 + .../apps/host-manager/HostManagerEditor.tsx | 384 ++++++++++++++++-- .../apps/host-manager/Socks5ProxyConfig.tsx | 244 ----------- 3 files changed, 362 insertions(+), 267 deletions(-) delete mode 100644 src/ui/desktop/apps/host-manager/Socks5ProxyConfig.tsx diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index b7ba7697..72aa1f8f 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -652,6 +652,7 @@ "failedToLoadHosts": "Failed to load hosts", "retry": "Retry", "refresh": "Refresh", + "optional": "Optional", "hostsCount": "{{count}} hosts", "importJson": "Import JSON", "importing": "Importing...", diff --git a/src/ui/desktop/apps/host-manager/HostManagerEditor.tsx b/src/ui/desktop/apps/host-manager/HostManagerEditor.tsx index e83a7e3e..90551f62 100644 --- a/src/ui/desktop/apps/host-manager/HostManagerEditor.tsx +++ b/src/ui/desktop/apps/host-manager/HostManagerEditor.tsx @@ -88,7 +88,6 @@ import { import { TerminalPreview } from "@/ui/desktop/apps/terminal/TerminalPreview.tsx"; import type { TerminalConfig, SSHHost, Credential } from "@/types"; import { Plus, X, Check, ChevronsUpDown, Save } from "lucide-react"; -import { Socks5ProxyConfig } from "./Socks5ProxyConfig.tsx"; interface JumpHostItemProps { jumpHost: { hostId: number }; @@ -303,9 +302,7 @@ export function HostManagerEditor({ const [snippets, setSnippets] = useState< Array<{ id: number; name: string; content: string }> >([]); - const [proxyMode, setProxyMode] = useState<"single" | "chain">( - "single", - ); + const [proxyMode, setProxyMode] = useState<"single" | "chain">("single"); const [authTab, setAuthTab] = useState< "password" | "key" | "credential" | "none" @@ -777,8 +774,7 @@ export function HostManagerEditor({ | "ssh-rsa-sha2-256" | "ssh-rsa-sha2-512") || "auto"; } else if (defaultAuthType === "credential") { - formData.credentialId = - cleanedHost.credentialId; + formData.credentialId = cleanedHost.credentialId; } form.reset(formData as FormData); @@ -942,13 +938,13 @@ export function HostManagerEditor({ window.dispatchEvent(new CustomEvent("ssh-hosts:changed")); if (savedHost?.id) { - const { notifyHostCreatedOrUpdated } = await import( - "@/ui/main-axios.ts" - ); + const { notifyHostCreatedOrUpdated } = + await import("@/ui/main-axios.ts"); notifyHostCreatedOrUpdated(savedHost.id); } } catch (error) { - const errorMessage = error instanceof Error ? error.message : String(error); + const errorMessage = + error instanceof Error ? error.message : String(error); toast.error(t("hosts.failedToSaveHost") + ": " + errorMessage); console.error("Failed to save host:", error); } finally { @@ -1481,7 +1477,8 @@ export function HostManagerEditor({ {field.value === "existing_key" @@ -1792,11 +1789,9 @@ export function HostManagerEditor({ control={form.control} name="useSocks5" render={({ field }) => ( - +
- - {t("hosts.enableSocks5")} - + {t("hosts.enableSocks5")} {t("hosts.enableSocks5Description")} @@ -1812,13 +1807,354 @@ export function HostManagerEditor({ /> {form.watch("useSocks5") && ( - +
+
+ + {t("hosts.socks5ProxyMode")} + +
+ + +
+
+ + {proxyMode === "single" && ( +
+ ( + + + {t("hosts.socks5Host")} + + + + + + {t("hosts.socks5HostDescription")} + + + )} + /> + + ( + + + {t("hosts.socks5Port")} + + + + field.onChange( + parseInt(e.target.value) || 1080, + ) + } + /> + + + {t("hosts.socks5PortDescription")} + + + )} + /> + + ( + + + {t("hosts.socks5Username")} ( + {t("hosts.optional")}) + + + + + + )} + /> + + ( + + + {t("hosts.socks5Password")} ( + {t("hosts.optional")}) + + + + + + )} + /> +
+ )} + + {proxyMode === "chain" && ( +
+
+ + {t("hosts.socks5ProxyChain")} + + +
+ + {(form.watch("socks5ProxyChain") || []) + .length === 0 && ( +
+ {t("hosts.noProxyNodes")} +
+ )} + + {(form.watch("socks5ProxyChain") || []).map( + (node: any, index: number) => ( +
+
+ + {t("hosts.proxyNode")} {index + 1} + + +
+ +
+
+ + {t("hosts.socks5Host")} + + { + const currentChain = + form.watch( + "socks5ProxyChain", + ) || []; + const newChain = [ + ...currentChain, + ]; + newChain[index] = { + ...newChain[index], + host: e.target.value, + }; + form.setValue( + "socks5ProxyChain", + newChain, + ); + }} + /> +
+ +
+ + {t("hosts.socks5Port")} + + { + const currentChain = + form.watch( + "socks5ProxyChain", + ) || []; + const newChain = [ + ...currentChain, + ]; + newChain[index] = { + ...newChain[index], + port: + parseInt(e.target.value) || + 1080, + }; + form.setValue( + "socks5ProxyChain", + newChain, + ); + }} + /> +
+
+ +
+ + {t("hosts.proxyType")} + + +
+ +
+
+ + {t("hosts.socks5Username")} ( + {t("hosts.optional")}) + + { + const currentChain = + form.watch( + "socks5ProxyChain", + ) || []; + const newChain = [ + ...currentChain, + ]; + newChain[index] = { + ...newChain[index], + username: e.target.value, + }; + form.setValue( + "socks5ProxyChain", + newChain, + ); + }} + /> +
+ +
+ + {t("hosts.socks5Password")} ( + {t("hosts.optional")}) + + { + const currentChain = + form.watch( + "socks5ProxyChain", + ) || []; + const newChain = [ + ...currentChain, + ]; + newChain[index] = { + ...newChain[index], + password: e.target.value, + }; + form.setValue( + "socks5ProxyChain", + newChain, + ); + }} + /> +
+
+
+ ), + )} +
+ )} +
)} @@ -1832,7 +2168,9 @@ export function HostManagerEditor({ defaultValue={["appearance", "behavior", "advanced"]} > - {t("hosts.appearance")} + + {t("hosts.appearance")} + ; - watch: UseFormWatch; - setValue: UseFormSetValue; - proxyMode: "single" | "chain"; - onProxyModeChange: (mode: "single" | "chain") => void; -} - -export function Socks5ProxyConfig({ - control, - watch, - setValue, - proxyMode, - onProxyModeChange, -}: Socks5ProxyConfigProps) { - const { t } = useTranslation(); - const proxyChain = watch("socks5ProxyChain") || []; - - const addProxyNode = () => { - const currentChain = watch("socks5ProxyChain") || []; - const newNode: ProxyNode = { - host: "", - port: 1080, - type: 5, - username: "", - password: "", - }; - setValue("socks5ProxyChain", [...currentChain, newNode]); - }; - - const removeProxyNode = (index: number) => { - const currentChain = watch("socks5ProxyChain") || []; - const newChain = currentChain.filter((_: any, i: number) => i !== index); - setValue("socks5ProxyChain", newChain); - }; - - const updateProxyNode = (index: number, field: keyof ProxyNode, value: any) => { - const currentChain = watch("socks5ProxyChain") || []; - const newChain = [...currentChain]; - newChain[index] = { ...newChain[index], [field]: value }; - setValue("socks5ProxyChain", newChain); - }; - - return ( -
-
- {t("hosts.socks5ProxyMode")} -
- - -
-
- - {proxyMode === "single" && ( -
- ( - - {t("hosts.socks5Host")} - - - - - {t("hosts.socks5HostDescription")} - - - )} - /> - - ( - - {t("hosts.socks5Port")} - - field.onChange(parseInt(e.target.value) || 1080)} - /> - - - {t("hosts.socks5PortDescription")} - - - )} - /> - - ( - - {t("hosts.socks5Username")} ({t("hosts.optional")}) - - - - - )} - /> - - ( - - {t("hosts.socks5Password")} ({t("hosts.optional")}) - - - - - )} - /> -
- )} - - {proxyMode === "chain" && ( -
-
- {t("hosts.socks5ProxyChain")} - -
- - {proxyChain.length === 0 && ( -
- {t("hosts.noProxyNodes")} -
- )} - - {proxyChain.map((node: ProxyNode, index: number) => ( -
-
- - {t("hosts.proxyNode")} {index + 1} - - -
- -
-
- {t("hosts.socks5Host")} - updateProxyNode(index, "host", e.target.value)} - /> -
- -
- {t("hosts.socks5Port")} - updateProxyNode(index, "port", parseInt(e.target.value) || 1080)} - /> -
-
- -
- {t("hosts.proxyType")} - -
- -
-
- {t("hosts.socks5Username")} ({t("hosts.optional")}) - updateProxyNode(index, "username", e.target.value)} - /> -
- -
- {t("hosts.socks5Password")} ({t("hosts.optional")}) - updateProxyNode(index, "password", e.target.value)} - /> -
-
-
- ))} -
- )} -
- ); -}