Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/ui/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { FaPlus } from "react-icons/fa";
import { isTauri } from "../../lib/tauri";
import useStore from "../../store";
import { TextInput } from "./TextInput";

Expand All @@ -8,7 +9,7 @@ const DiscoverGrid = () => {
useStore();
const [query, setQuery] = useState("");
const [servers, setServers] = useState<
{ name: string; description: string; server?: string; port?: string }[]
{ name: string; description: string; wss?: string; ircs?: string }[]
>([]);

useEffect(() => {
Expand Down Expand Up @@ -36,11 +37,16 @@ const DiscoverGrid = () => {
server.description.toLowerCase().includes(query.toLowerCase()),
);

const uriPort = (uri: string, defaultPort: string) =>
new URL(uri).port || defaultPort;

const handleServerClick = (server: Record<string, string>) => {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const uri = isTauri() ? server.ircs : server.wss;
const defaultPort = isTauri() ? "6697" : "443";
toggleAddServerModal(true, {
name: server.name,
host: server.server || "", // Use empty string if server is undefined
port: server.port || "443", // Default to 443 if port is undefined
host: uri ? new URL(uri).hostname : "",
port: uri ? uriPort(uri, defaultPort) : defaultPort,
nickname: "", // Generate a default nickname
ui: {
disableServerConnectionInfo: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Don't open a locked server config when the current transport URI is missing.

wss/ircs are optional in the server shape, but this branch still opens the modal with host: "" and disableServerConnectionInfo: true when the platform-specific URI is absent. That leaves the user stuck with an invalid, non-editable connection.

Suggested fix
 const handleServerClick = (server: Record<string, string>) => {
   const uri = isTauri() ? server.ircs : server.wss;
+  if (!uri) {
+    return;
+  }
   const defaultPort = isTauri() ? "6697" : "443";
+  const parsed = new URL(uri);
   toggleAddServerModal(true, {
     name: server.name,
-    host: uri ? new URL(uri).hostname : "",
-    port: uri ? uriPort(uri, defaultPort) : defaultPort,
+    host: parsed.hostname,
+    port: parsed.port || defaultPort,
     nickname: "", // Generate a default nickname
     ui: {
       disableServerConnectionInfo: true,
       title: server.name,
     },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/ui/HomeScreen.tsx` around lines 43 - 52, The handleServerClick
handler opens a locked AddServer modal even when platform-specific URI
(server.ircs or server.wss) is missing; update handleServerClick to first
compute uri = isTauri() ? server.ircs : server.wss and if uri is falsy call
toggleAddServerModal with ui.disableServerConnectionInfo set to false (and
host/port left empty or default editable values) so the user can enter
connection details, otherwise continue to parse new URL(uri).hostname and
uriPort as now; reference handleServerClick, toggleAddServerModal,
server.ircs/server.wss, uriPort, and isTauri when making the change.

Expand Down
8 changes: 8 additions & 0 deletions src/lib/tauri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare global {
interface Window {
__TAURI__?: unknown;
}
}

export const isTauri = () =>
typeof window !== "undefined" && window.__TAURI__ !== undefined;
Loading