-
Notifications
You must be signed in to change notification settings - Fork 7
Fix: Allow opening external links in Tauri app #293
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
521eb93
Fix: Allow opening external links in Tauri app
github-actions[bot] 58d1b4a
Fix: Add HTTPS wildcard to Tauri capabilities
AnthonyRonning a9299b2
Add confirmation dialog for external URLs in markdown
AnthonyRonning 4563bc6
Switch ExternalUrlConfirmDialog from AlertDialog to Dialog
github-actions[bot] 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,9 @@ | |
| }, | ||
| { | ||
| "url": "https://opensecret.cloud/*" | ||
| }, | ||
| { | ||
| "url": "https://*" | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -75,6 +75,9 @@ | |
| }, | ||
| { | ||
| "url": "https://*.google.com/*" | ||
| }, | ||
| { | ||
| "url": "https://*" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -32,6 +32,9 @@ | |
| }, | ||
| { | ||
| "url": "https://opensecret.cloud/*" | ||
| }, | ||
| { | ||
| "url": "https://*" | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
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,49 @@ | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle | ||
| } from "@/components/ui/dialog"; | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
||
| interface ExternalUrlConfirmDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| onConfirm: () => void; | ||
| url: string; | ||
| } | ||
|
|
||
| export function ExternalUrlConfirmDialog({ | ||
| open, | ||
| onOpenChange, | ||
| onConfirm, | ||
| url | ||
| }: ExternalUrlConfirmDialogProps) { | ||
| const handleConfirm = (e: React.MouseEvent) => { | ||
| e.preventDefault(); | ||
| onConfirm(); | ||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={onOpenChange}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>Open External Link?</DialogTitle> | ||
| <DialogDescription> | ||
| You are about to open an external URL in your browser: | ||
| <div className="mt-2 p-2 bg-muted rounded-md break-all text-sm font-mono">{url}</div> | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <DialogFooter> | ||
| <Button variant="outline" onClick={() => onOpenChange(false)}> | ||
| Cancel | ||
| </Button> | ||
| <Button onClick={handleConfirm}>Open</Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
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,32 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { ExternalUrlConfirmDialog } from "@/components/ExternalUrlConfirmDialog"; | ||
| import { setUrlConfirmationCallback, openExternalUrl } from "@/utils/openUrl"; | ||
|
|
||
| export function ExternalUrlConfirmHandler() { | ||
| const [pendingUrl, setPendingUrl] = useState<string | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const register = (url: string) => { | ||
| // Only set if no pending URL (ignore rapid clicks while dialog is open) | ||
| setPendingUrl((current) => (current !== null ? current : url)); | ||
| }; | ||
| setUrlConfirmationCallback(register); | ||
| return () => setUrlConfirmationCallback(null); | ||
| }, []); | ||
|
|
||
| const handleConfirm = () => { | ||
| if (pendingUrl) { | ||
| openExternalUrl(pendingUrl); | ||
| setPendingUrl(null); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <ExternalUrlConfirmDialog | ||
| open={pendingUrl !== null} | ||
| onOpenChange={(open) => !open && setPendingUrl(null)} | ||
| onConfirm={handleConfirm} | ||
| url={pendingUrl || ""} | ||
| /> | ||
| ); | ||
| } |
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 |
|---|---|---|
|
|
@@ -245,9 +245,9 @@ function ToolCallRenderer({ | |
| {query ? `Searched: "${query}"` : "Web Search"} | ||
| </span> | ||
| </div> | ||
| {/* Search result - indented to align with text */} | ||
| <div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words"> | ||
| {isExpanded ? output : preview} | ||
| {/* Search result - indented to align with text, render as markdown for links */} | ||
| <div className="pl-6 text-foreground/80"> | ||
| <Markdown content={isExpanded ? output : preview} fontSize={14} /> | ||
|
Comment on lines
+249
to
+250
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. style: Check that removing Prompt To Fix With AIThis is a comment left during a code review.
Path: frontend/src/components/UnifiedChat.tsx
Line: 249:250
Comment:
**style:** Check that removing `whitespace-pre-wrap break-words` doesn't affect plain text formatting in tool outputs. The Markdown component handles this via `RemarkBreaks` plugin and CSS, but verify with outputs containing multiple spaces or special formatting.
How can I resolve this? If you propose a fix, please make it concise. |
||
| {hasMore && ( | ||
| <button | ||
| onClick={() => setIsExpanded(!isExpanded)} | ||
|
|
@@ -275,9 +275,9 @@ function ToolCallRenderer({ | |
| <Check className="h-4 w-4 text-green-600 dark:text-green-400 flex-shrink-0" /> | ||
| <span className="font-medium text-foreground">{statusText}</span> | ||
| </div> | ||
| {/* Tool output - indented */} | ||
| <div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words"> | ||
| {isExpanded ? output : preview} | ||
| {/* Tool output - indented, render as markdown for links */} | ||
| <div className="pl-6 text-foreground/80"> | ||
| <Markdown content={isExpanded ? output : preview} fontSize={14} /> | ||
| {hasMore && ( | ||
| <button | ||
| onClick={() => setIsExpanded(!isExpanded)} | ||
|
|
@@ -328,8 +328,8 @@ function ToolCallRenderer({ | |
| <Check className="h-4 w-4 text-green-600 dark:text-green-400 flex-shrink-0" /> | ||
| <span className="font-medium text-foreground">Tool Result</span> | ||
| </div> | ||
| <div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words"> | ||
| {isExpanded ? output : preview} | ||
| <div className="pl-6 text-foreground/80"> | ||
| <Markdown content={isExpanded ? output : preview} fontSize={14} /> | ||
| {hasMore && ( | ||
| <button | ||
| onClick={() => setIsExpanded(!isExpanded)} | ||
|
|
||
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,103 @@ | ||
| /** | ||
| * Utility for opening external URLs | ||
| * | ||
| * This module provides a unified way to open external URLs that works | ||
| * correctly in both web browsers and Tauri environments. | ||
| * | ||
| * In Tauri apps, regular <a> tags with target="_blank" don't work properly. | ||
| * We need to use the Tauri opener plugin to open URLs in the system browser. | ||
| */ | ||
|
|
||
| import { isTauri } from "@/utils/platform"; | ||
|
|
||
| // State management for confirmation dialog | ||
| let urlConfirmationCallback: ((url: string) => void) | null = null; | ||
|
|
||
| export function setUrlConfirmationCallback(callback: ((url: string) => void) | null) { | ||
| urlConfirmationCallback = callback; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Opens an external URL in the appropriate way for the current environment | ||
| * | ||
| * - In web browsers: uses window.open() | ||
| * - In Tauri apps: uses the opener plugin to open in system browser | ||
| * | ||
| * @param url - The URL to open | ||
| * @returns Promise that resolves when the URL is opened (or rejects on error) | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // In a component | ||
| * import { openExternalUrl } from '@/utils/openUrl'; | ||
| * | ||
| * <a | ||
| * href={url} | ||
| * onClick={(e) => { | ||
| * e.preventDefault(); | ||
| * openExternalUrl(url); | ||
| * }} | ||
| * > | ||
| * Click me | ||
| * </a> | ||
| * ``` | ||
| */ | ||
| export async function openExternalUrl(url: string): Promise<void> { | ||
| try { | ||
| if (isTauri()) { | ||
| // In Tauri, use the opener plugin | ||
| const { openUrl } = await import("@tauri-apps/plugin-opener"); | ||
| await openUrl(url); | ||
|
AnthonyRonning marked this conversation as resolved.
|
||
| } else { | ||
| // In web browsers, use window.open | ||
| const popup = window.open(url, "_blank", "noopener,noreferrer"); | ||
| if (!popup) { | ||
| throw new Error("Failed to open URL - popup may be blocked"); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error("Failed to open URL:", url, error); | ||
| // Fallback: try window.open anyway | ||
| try { | ||
| const popup = window.open(url, "_blank", "noopener,noreferrer"); | ||
| if (!popup) { | ||
| console.error("Fallback window.open was also blocked"); | ||
| } | ||
| } catch (fallbackError) { | ||
| console.error("Fallback also failed:", fallbackError); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Opens an external URL with user confirmation | ||
| * | ||
| * Shows a confirmation dialog to the user before opening the URL. | ||
| * Requires ExternalUrlConfirmHandler to be mounted in the app. | ||
| * | ||
| * @param url - The URL to open | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // In a component | ||
| * import { openExternalUrlWithConfirmation } from '@/utils/openUrl'; | ||
| * | ||
| * <a | ||
| * href={url} | ||
| * onClick={(e) => { | ||
| * e.preventDefault(); | ||
| * openExternalUrlWithConfirmation(url); | ||
| * }} | ||
| * > | ||
| * Click me | ||
| * </a> | ||
| * ``` | ||
| */ | ||
| export function openExternalUrlWithConfirmation(url: string): void { | ||
| if (urlConfirmationCallback) { | ||
| urlConfirmationCallback(url); | ||
| } else { | ||
| console.warn("URL confirmation callback not set, opening directly"); | ||
| openExternalUrl(url); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.