From 91fdbd2b3e0a09e34f2ead723f806ae6ac20d77f Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 17 Oct 2024 00:43:36 +0530 Subject: [PATCH 1/2] fix: add hostname check to decide http mode in windows --- frontend/src/components/ExternalLink.tsx | 4 +++- frontend/src/components/layouts/AppLayout.tsx | 8 ++++++-- frontend/src/screens/BackupNode.tsx | 4 +++- frontend/src/screens/setup/RestoreNode.tsx | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/ExternalLink.tsx b/frontend/src/components/ExternalLink.tsx index c76d31a1..d0caf44c 100644 --- a/frontend/src/components/ExternalLink.tsx +++ b/frontend/src/components/ExternalLink.tsx @@ -8,7 +8,9 @@ type Props = { }; export default function ExternalLink({ to, className, children }: Props) { - const isHttpMode = window.location.protocol.startsWith("http"); + const isHttpMode = + window.location.protocol.startsWith("http") && + !window.location.hostname.startsWith("wails"); return isHttpMode ? ( { e.preventDefault(); - const isHttpMode = window.location.protocol.startsWith("http"); + const isHttpMode = + window.location.protocol.startsWith("http") && + !window.location.hostname.startsWith("wails"); try { setLoading(true); diff --git a/frontend/src/screens/setup/RestoreNode.tsx b/frontend/src/screens/setup/RestoreNode.tsx index 0cd5fd95..86aa5cb5 100644 --- a/frontend/src/screens/setup/RestoreNode.tsx +++ b/frontend/src/screens/setup/RestoreNode.tsx @@ -34,7 +34,9 @@ export function RestoreNode() { const [loading, setLoading] = useState(false); const [restored, setRestored] = useState(false); const { data: info } = useInfo(restored); - const isHttpMode = window.location.protocol.startsWith("http"); + const isHttpMode = + window.location.protocol.startsWith("http") && + !window.location.hostname.startsWith("wails"); React.useEffect(() => { if (restored && info?.setupCompleted) { From 7ec580dd9c87787c299a64c836185aaa57c72659 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Mon, 21 Oct 2024 22:48:51 +0530 Subject: [PATCH 2/2] chore: extract into utils isHttpMode function --- frontend/src/components/ExternalLink.tsx | 7 +++---- frontend/src/components/layouts/AppLayout.tsx | 16 ++++++---------- frontend/src/screens/BackupNode.tsx | 7 +++---- frontend/src/screens/setup/RestoreNode.tsx | 9 ++++----- frontend/src/utils/isHttpMode.ts | 6 ++++++ 5 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 frontend/src/utils/isHttpMode.ts diff --git a/frontend/src/components/ExternalLink.tsx b/frontend/src/components/ExternalLink.tsx index d0caf44c..2ce0273e 100644 --- a/frontend/src/components/ExternalLink.tsx +++ b/frontend/src/components/ExternalLink.tsx @@ -1,4 +1,5 @@ import { Link } from "react-router-dom"; +import { isHttpMode } from "src/utils/isHttpMode"; import { openLink } from "src/utils/openLink"; type Props = { @@ -8,11 +9,9 @@ type Props = { }; export default function ExternalLink({ to, className, children }: Props) { - const isHttpMode = - window.location.protocol.startsWith("http") && - !window.location.hostname.startsWith("wails"); + const _isHttpMode = isHttpMode(); - return isHttpMode ? ( + return _isHttpMode ? ( { setMobileMenuOpen(false); }, [location]); @@ -73,19 +76,12 @@ export default function AppLayout() { deleteAuthToken(); await refetchInfo(); - const isHttpMode = - window.location.protocol.startsWith("http") && - !window.location.hostname.startsWith("wails"); - if (isHttpMode) { + if (_isHttpMode) { window.location.href = "/logout"; } else { navigate("/", { replace: true }); } - }, [navigate, refetchInfo]); - - const isHttpMode = - window.location.protocol.startsWith("http") && - !window.location.hostname.startsWith("wails"); + }, [_isHttpMode, navigate, refetchInfo]); if (!info) { return null; @@ -119,7 +115,7 @@ export default function AppLayout() { )} - {isHttpMode && ( + {_isHttpMode && ( { e.preventDefault(); - const isHttpMode = - window.location.protocol.startsWith("http") && - !window.location.hostname.startsWith("wails"); + const _isHttpMode = isHttpMode(); try { setLoading(true); - if (isHttpMode) { + if (_isHttpMode) { const response = await fetch("/api/backup", { method: "POST", headers: { diff --git a/frontend/src/screens/setup/RestoreNode.tsx b/frontend/src/screens/setup/RestoreNode.tsx index 86aa5cb5..a580f8de 100644 --- a/frontend/src/screens/setup/RestoreNode.tsx +++ b/frontend/src/screens/setup/RestoreNode.tsx @@ -21,6 +21,7 @@ import { useToast } from "src/components/ui/use-toast"; import { useInfo } from "src/hooks/useInfo"; import { handleRequestError } from "src/utils/handleRequestError"; +import { isHttpMode } from "src/utils/isHttpMode"; import { request } from "src/utils/request"; export function RestoreNode() { @@ -34,9 +35,7 @@ export function RestoreNode() { const [loading, setLoading] = useState(false); const [restored, setRestored] = useState(false); const { data: info } = useInfo(restored); - const isHttpMode = - window.location.protocol.startsWith("http") && - !window.location.hostname.startsWith("wails"); + const _isHttpMode = isHttpMode(); React.useEffect(() => { if (restored && info?.setupCompleted) { @@ -73,7 +72,7 @@ export function RestoreNode() { try { setLoading(true); - if (isHttpMode) { + if (_isHttpMode) { const formData = new FormData(); formData.append("unlockPassword", unlockPassword); if (file !== null) { @@ -130,7 +129,7 @@ export function RestoreNode() { placeholder="Unlock Password" /> - {isHttpMode && ( + {_isHttpMode && (
{ + return ( + window.location.protocol.startsWith("http") && + !window.location.hostname.startsWith("wails") + ); +};