feat: implement openExternalUrl utility for consistent external link handling
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { openExternalUrl } from '../../utils/tauri';
|
||||||
import { Box, Button, color, config, Dialog, Header, Icon, IconButton, Icons, Text } from 'folds';
|
import { Box, Button, color, config, Dialog, Header, Icon, IconButton, Icons, Text } from 'folds';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { StageComponentProps } from './types';
|
import { StageComponentProps } from './types';
|
||||||
@@ -20,8 +21,8 @@ export function SSOStage({
|
|||||||
}, [submitAuthDict, session]);
|
}, [submitAuthDict, session]);
|
||||||
|
|
||||||
const handleContinue = () => {
|
const handleContinue = () => {
|
||||||
const w = window.open(ssoRedirectURL, '_blank');
|
openExternalUrl(ssoRedirectURL);
|
||||||
setSSOWindow(w ?? undefined);
|
setSSOWindow(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { MouseEventHandler, useCallback, useMemo, useState } from 'react';
|
import React, { MouseEventHandler, useCallback, useMemo, useState } from 'react';
|
||||||
|
import { openExternalUrl } from '../../utils/tauri';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import FocusTrap from 'focus-trap-react';
|
import FocusTrap from 'focus-trap-react';
|
||||||
import { isKeyHotkey } from 'is-hotkey';
|
import { isKeyHotkey } from 'is-hotkey';
|
||||||
@@ -110,7 +111,7 @@ export function ServerChip({ server }: { server: string }) {
|
|||||||
size="300"
|
size="300"
|
||||||
radii="300"
|
radii="300"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(`https://${server}`, '_blank');
|
openExternalUrl(`https://${server}`);
|
||||||
close();
|
close();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
|
import { openExternalUrl } from '../../../utils/tauri';
|
||||||
import { Box, Button, config, Menu, Spinner, Text } from 'folds';
|
import { Box, Button, config, Menu, Spinner, Text } from 'folds';
|
||||||
import { AuthDict, IMyDevice, MatrixError } from 'matrix-js-sdk';
|
import { AuthDict, IMyDevice, MatrixError } from 'matrix-js-sdk';
|
||||||
import { SequenceCard } from '../../../components/sequence-card';
|
import { SequenceCard } from '../../../components/sequence-card';
|
||||||
@@ -33,11 +34,10 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O
|
|||||||
const authUrl = authMetadata?.account_management_uri ?? authMetadata?.issuer;
|
const authUrl = authMetadata?.account_management_uri ?? authMetadata?.issuer;
|
||||||
if (!authUrl) return;
|
if (!authUrl) return;
|
||||||
|
|
||||||
window.open(
|
openExternalUrl(
|
||||||
withSearchParam(authUrl, {
|
withSearchParam(authUrl, {
|
||||||
action: accountManagementActions.sessionsList,
|
action: accountManagementActions.sessionsList,
|
||||||
}),
|
})
|
||||||
'_blank'
|
|
||||||
);
|
);
|
||||||
}, [authMetadata, accountManagementActions]);
|
}, [authMetadata, accountManagementActions]);
|
||||||
|
|
||||||
@@ -46,12 +46,11 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O
|
|||||||
const authUrl = authMetadata?.account_management_uri ?? authMetadata?.issuer;
|
const authUrl = authMetadata?.account_management_uri ?? authMetadata?.issuer;
|
||||||
if (!authUrl) return;
|
if (!authUrl) return;
|
||||||
|
|
||||||
window.open(
|
openExternalUrl(
|
||||||
withSearchParam(authUrl, {
|
withSearchParam(authUrl, {
|
||||||
action: accountManagementActions.sessionEnd,
|
action: accountManagementActions.sessionEnd,
|
||||||
device_id: deviceId,
|
device_id: deviceId,
|
||||||
}),
|
})
|
||||||
'_blank'
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[authMetadata, accountManagementActions]
|
[authMetadata, accountManagementActions]
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import { stopPropagation } from '../../../utils/keyboard';
|
|||||||
import { useAuthMetadata } from '../../../hooks/useAuthMetadata';
|
import { useAuthMetadata } from '../../../hooks/useAuthMetadata';
|
||||||
import { withSearchParam } from '../../../pages/pathUtils';
|
import { withSearchParam } from '../../../pages/pathUtils';
|
||||||
import { useAccountManagementActions } from '../../../hooks/useAccountManagement';
|
import { useAccountManagementActions } from '../../../hooks/useAccountManagement';
|
||||||
|
import { openExternalUrl } from '../../../utils/tauri';
|
||||||
|
|
||||||
type VerificationStatusBadgeProps = {
|
type VerificationStatusBadgeProps = {
|
||||||
verificationStatus: VerificationStatus;
|
verificationStatus: VerificationStatus;
|
||||||
@@ -273,11 +274,10 @@ export function DeviceVerificationOptions() {
|
|||||||
|
|
||||||
if (authMetadata) {
|
if (authMetadata) {
|
||||||
const authUrl = authMetadata.account_management_uri ?? authMetadata.issuer;
|
const authUrl = authMetadata.account_management_uri ?? authMetadata.issuer;
|
||||||
window.open(
|
openExternalUrl(
|
||||||
withSearchParam(authUrl, {
|
withSearchParam(authUrl, {
|
||||||
action: accountManagementActions.crossSigningReset,
|
action: accountManagementActions.crossSigningReset,
|
||||||
}),
|
})
|
||||||
'_blank'
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Open an external URL using Tauri shell on desktop/mobile, or window.open in browser
|
||||||
|
* @param url The URL to open
|
||||||
|
*/
|
||||||
|
export const openExternalUrl = async (url: string): Promise<void> => {
|
||||||
|
if (isTauri()) {
|
||||||
|
try {
|
||||||
|
const { open } = await import('@tauri-apps/plugin-shell');
|
||||||
|
await open(url);
|
||||||
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Tauri shell.open failed, falling back to window.open:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.open(url, '_blank');
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Tauri-specific utilities for desktop and mobile platforms
|
* Tauri-specific utilities for desktop and mobile platforms
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user