From ffae92d233caea465fb924de37e462b445bd7497 Mon Sep 17 00:00:00 2001 From: James Thomas Date: Sun, 30 Mar 2025 20:52:04 -0400 Subject: [PATCH 1/3] Adding connection failure warning --- .../PageComponents/Connect/HTTP.tsx | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/components/PageComponents/Connect/HTTP.tsx b/src/components/PageComponents/Connect/HTTP.tsx index 092b79bfc..b50dbcf56 100644 --- a/src/components/PageComponents/Connect/HTTP.tsx +++ b/src/components/PageComponents/Connect/HTTP.tsx @@ -11,6 +11,7 @@ import { MeshDevice } from "@meshtastic/core"; import { TransportHTTP } from "@meshtastic/transport-http"; import { useState } from "react"; import { useForm, useController } from "react-hook-form"; +import { AlertTriangle } from "lucide-react"; interface FormData { ip: string; @@ -39,23 +40,33 @@ export const HTTP = ({ closeDialog }: TabElementProps) => { } = useController({ name: "tls", control }); const [connectionInProgress, setConnectionInProgress] = useState(false); + const [connectionError, setConnectionError] = useState<{ host: string; secure: boolean } | null>(null); const onSubmit = handleSubmit(async (data) => { setConnectionInProgress(true); - const id = randId(); - const device = addDevice(id); - const transport = await TransportHTTP.create(data.ip, data.tls); - const connection = new MeshDevice(transport, id); - connection.configure(); - setSelectedDevice(id); - device.addConnection(connection); - subscribeAll(device, connection); - closeDialog(); + setConnectionError(null); + + try { + const id = randId(); + const transport = await TransportHTTP.create(data.ip, data.tls); + const device = addDevice(id); + const connection = new MeshDevice(transport, id); + connection.configure(); + setSelectedDevice(id); + device.addConnection(connection); + subscribeAll(device, connection); + closeDialog(); + } catch (error) { + console.error("Connection error:", error); + // Capture all connection errors regardless of type + setConnectionError({ host: data.ip, secure: data.tls }); + setConnectionInProgress(false); + } }); return (
-
+
{ {...register("tls")} /> -
+ + {connectionError && ( +
+
+ +
+

+ Connection Failed +

+

+ Could not connect to the device. If using HTTPS, you may need to accept a self-signed certificate first. Please open{" "} + + {`${connectionError.secure ? "https" : "http"}://${connectionError.host}`} + + {" "}in a new tab, accept any certificate warnings if prompted, then return here to try connecting again. +

+
+
+
+ )}
{connectionError && ( -
+
- +

Connection Failed

-

- Could not connect to the device. If using HTTPS, you may need to accept a self-signed certificate first. Please open{" "} +

+ Could not connect to the device. {connectionError.secure && "If using HTTPS, you may need to accept a self-signed certificate first. "} + Please open{" "} { className="underline font-medium" > {`${connectionError.secure ? "https" : "http"}://${connectionError.host}`} + {" "} + in a new tab{connectionError.secure ? ", accept any TLS warnings if prompted, then try again" : ""}.{" "} + + Learn more - {" "}in a new tab, accept any certificate warnings if prompted, then return here to try connecting again.

From 0faafe8bc4e7b0c02b63108d78da1b1cb93157fb Mon Sep 17 00:00:00 2001 From: James Thomas Date: Sun, 30 Mar 2025 21:43:25 -0400 Subject: [PATCH 3/3] Using existing Link component and standardizing colors --- .../PageComponents/Connect/HTTP.tsx | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/components/PageComponents/Connect/HTTP.tsx b/src/components/PageComponents/Connect/HTTP.tsx index 8d8e3e2de..19ca08979 100644 --- a/src/components/PageComponents/Connect/HTTP.tsx +++ b/src/components/PageComponents/Connect/HTTP.tsx @@ -1,6 +1,7 @@ import type { TabElementProps } from "@components/Dialog/NewDeviceDialog.tsx"; import { Button } from "@components/UI/Button.tsx"; import { Input } from "@components/UI/Input.tsx"; +import { Link } from "@components/UI/Typography/Link.tsx"; import { Label } from "@components/UI/Label.tsx"; import { Switch } from "@components/UI/Switch.tsx"; import { useAppStore } from "@core/stores/appStore.ts"; @@ -88,33 +89,29 @@ export const HTTP = ({ closeDialog }: TabElementProps) => {
{connectionError && ( -
+
- +
-

+

Connection Failed

-

+

Could not connect to the device. {connectionError.secure && "If using HTTPS, you may need to accept a self-signed certificate first. "} Please open{" "} - {`${connectionError.secure ? "https" : "http"}://${connectionError.host}`} - {" "} + {" "} in a new tab{connectionError.secure ? ", accept any TLS warnings if prompted, then try again" : ""}.{" "} - Learn more - +