Repository navigation
Support TCP servers in native app discover page #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"; | ||
|
|
||
|
|
@@ -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(() => { | ||
|
|
@@ -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>) => { | ||
| 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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't open a locked server config when the current transport URI is missing.
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 |
||
|
|
||
| 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; |
Uh oh!
There was an error while loading. Please reload this page.