-
Notifications
You must be signed in to change notification settings - Fork 22
fix: allow cancel/delete while server is connecting #176
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
Open
louzt
wants to merge
2
commits into
obbyworld:main
Choose a base branch
from
louzt:fix/server-connection-loading-cancel-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { parseIrcUrl } from "./ircUrlParser"; | ||
|
|
||
| export interface ServerConnectionFields { | ||
| host: string; | ||
| port: string; | ||
| useWebSocket: boolean; | ||
| } | ||
|
|
||
| function parseStandardUrl(url: string): { | ||
| host: string; | ||
| port: string; | ||
| useWebSocket: boolean; | ||
| } | null { | ||
| try { | ||
| const parsed = new URL(url); | ||
| const useWebSocket = | ||
| parsed.protocol === "wss:" || parsed.protocol === "ws:"; | ||
| return { | ||
| host: parsed.hostname, | ||
| port: parsed.port, | ||
| useWebSocket, | ||
| }; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function parseHostWithOptionalPort(value: string): { | ||
| host: string; | ||
| port?: string; | ||
| } { | ||
| const trimmed = value.trim(); | ||
| const match = trimmed.match(/^([^:/?#\s]+):(\d+)$/); | ||
| if (!match) { | ||
| return { host: trimmed }; | ||
| } | ||
|
|
||
| return { | ||
| host: match[1], | ||
| port: match[2], | ||
| }; | ||
| } | ||
|
|
||
| export function getServerConnectionFields( | ||
| rawHost: string | null | undefined, | ||
| rawPort: string | number | null | undefined, | ||
| fallbackUseWebSocket = false, | ||
| ): ServerConnectionFields { | ||
| const fallbackPort = String(rawPort ?? "").trim(); | ||
| const host = rawHost?.trim() ?? ""; | ||
|
|
||
| if (!host) { | ||
| return { | ||
| host: "", | ||
| port: fallbackPort, | ||
| useWebSocket: fallbackUseWebSocket, | ||
| }; | ||
| } | ||
|
|
||
| if (host.startsWith("ircs://") || host.startsWith("irc://")) { | ||
| const parsed = parseIrcUrl(host); | ||
| return { | ||
| host: parsed.host, | ||
| port: String(parsed.port || fallbackPort), | ||
| useWebSocket: false, | ||
| }; | ||
| } | ||
|
|
||
| if (host.startsWith("wss://") || host.startsWith("ws://")) { | ||
| const parsed = parseStandardUrl(host); | ||
| if (parsed) { | ||
| return { | ||
| host: parsed.host, | ||
| port: parsed.port || fallbackPort, | ||
| useWebSocket: parsed.useWebSocket, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| const parsedHost = parseHostWithOptionalPort(host); | ||
| return { | ||
| host: parsedHost.host, | ||
| port: parsedHost.port || fallbackPort, | ||
| useWebSocket: fallbackUseWebSocket, | ||
| }; | ||
| } | ||
|
|
||
| export function buildServerConnectionUrl( | ||
| hostInput: string, | ||
| port: number, | ||
| options: { | ||
| isTauri: boolean; | ||
| useWebSocket: boolean; | ||
| }, | ||
| ): string { | ||
| const { host } = getServerConnectionFields( | ||
| hostInput, | ||
| String(port), | ||
| options.useWebSocket, | ||
| ); | ||
| const trimmedHost = host.trim(); | ||
| if (!trimmedHost) return ""; | ||
|
|
||
| const scheme = options.isTauri | ||
| ? options.useWebSocket | ||
| ? "wss" | ||
| : "ircs" | ||
| : "wss"; | ||
|
|
||
| return `${scheme}://${trimmedHost}:${port}`; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 15586
🏁 Script executed:
cat -n src/components/ui/EditServerModal.tsx | head -50Repository: ObsidianIRC/ObsidianIRC
Length of output: 2231
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 1061
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 49
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 49
🏁 Script executed:
cat -n src/lib/serverConnectionUrl.ts | head -100Repository: ObsidianIRC/ObsidianIRC
Length of output: 2927
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 1233
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 2040
🏁 Script executed:
Repository: ObsidianIRC/ObsidianIRC
Length of output: 968
Add a clarifying comment for legacy config handling:
ServerConfighas nouseWebSocketfield.Since
ServerConfig(the persisted type) lacks auseWebSocketfield,fallbackUseWebSocketcannot reference it. The hardcodedfalsefallback will affect bare-hostname legacy configs (those without a scheme in thehostfield): a Tauri user with a legacy storedhostlike"irc.example.com"will see the WSS checkbox unchecked after opening Edit, and saving will rewrite the URL toircs://…. Configs saved after the refactor will have schemes and round-trip correctly. Add a one-line comment (e.g.,// Legacy bare hostnames default to ircsor similar) to document this intentional behavior.🤖 Prompt for AI Agents