Skip to content

Commit 33c8970

Browse files
Merge pull request tonyantony300#127 from Avazbek22/fix/external-links-not-working-125
Fix external links/buttons by using opener plugin
2 parents 9e17d45 + 3629cd6 commit 33c8970

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

web-app/src/components/AppFooter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from '@/i18n'
44
import { AppVersion } from './AppVersionPayload'
55
import { Separator } from './ui/separator'
66
import { Link } from 'react-router-dom'
7-
//import { Link } from 'react-router-dom'
7+
import { handleExternalLinkClick } from '@/lib/openExternalUrl'
88

99
const CONTACTS = [
1010
{
@@ -36,6 +36,7 @@ export function AppFooter() {
3636
<a
3737
key={contact.link}
3838
href={contact.link}
39+
onClick={(event) => handleExternalLinkClick(event, contact.link)}
3940
target="_blank"
4041
rel="noopener noreferrer"
4142
aria-label={contact['aria-label']}

web-app/src/components/setting-sidebar/setting-sidebar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useTranslation } from '../../i18n'
1616
import { cn } from '../../lib/utils'
1717
import { LICENSE_LINK, PRIVACY_LINK, VERSION_DISPLAY } from '../../lib/version'
1818
import { Badge } from '../ui/badge'
19+
import { handleExternalLinkClick } from '@/lib/openExternalUrl'
1920

2021
function SettingSidebarRoot(props: React.ComponentProps<typeof Sidebar>) {
2122
return <Sidebar {...props} />
@@ -118,6 +119,7 @@ function SettingSidebarFooter({
118119
<a
119120
className="hover:underline hover:text-foreground transition-color"
120121
href={PRIVACY_LINK}
122+
onClick={(event) => handleExternalLinkClick(event, PRIVACY_LINK)}
121123
target="_blank"
122124
rel="noopener noreferrer"
123125
>
@@ -127,6 +129,7 @@ function SettingSidebarFooter({
127129
<a
128130
className="hover:underline hover:text-foreground transition-color"
129131
href={LICENSE_LINK}
132+
onClick={(event) => handleExternalLinkClick(event, LICENSE_LINK)}
130133
target="_blank"
131134
rel="noopener noreferrer"
132135
>

web-app/src/lib/openExternalUrl.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { openUrl } from '@tauri-apps/plugin-opener'
2+
3+
export async function openExternalUrl(url: string): Promise<void> {
4+
if (IS_TAURI) {
5+
await openUrl(url)
6+
return
7+
}
8+
9+
const openedWindow = window.open(url, '_blank', 'noopener,noreferrer')
10+
if (openedWindow) {
11+
openedWindow.opener = null
12+
}
13+
}
14+
15+
export function handleExternalLinkClick(
16+
event: { preventDefault: () => void },
17+
url: string
18+
): void {
19+
if (!IS_TAURI) {
20+
return
21+
}
22+
23+
event.preventDefault()
24+
void openExternalUrl(url).catch((error) => {
25+
console.error('Failed to open external URL:', error)
26+
})
27+
}

web-app/src/lib/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import packageJson from '../../../package.json'
33
export const VERSION = packageJson.version
44
export const VERSION_DISPLAY = `v${VERSION}`
55
export const PRIVACY_LINK =
6-
'https://github.com/tonyantony300/alt-sendme/blob/main/PRIVACY'
6+
'https://github.com/tonyantony300/alt-sendme/blob/main/PRIVACY.md'
77
export const LICENSE_LINK =
88
'https://github.com/tonyantony300/alt-sendme/blob/main/LICENSE'

0 commit comments

Comments
 (0)