feat: refactor openExternalUrl to use dedicated Tauri shell utility
This commit is contained in:
@@ -3,12 +3,10 @@
|
|||||||
* @param url The URL to open
|
* @param url The URL to open
|
||||||
*/
|
*/
|
||||||
export const openExternalUrl = async (url: string): Promise<void> => {
|
export const openExternalUrl = async (url: string): Promise<void> => {
|
||||||
// Only try to import Tauri shell in Tauri builds
|
|
||||||
if (typeof window !== 'undefined' && (window as any).__TAURI__) {
|
if (typeof window !== 'undefined' && (window as any).__TAURI__) {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
const { openWithTauriShell } = await import('./tauriShell');
|
||||||
const { open } = await import(/* @vite-ignore */ '@tauri-apps/plugin-shell');
|
await openWithTauriShell(url);
|
||||||
await open(url);
|
|
||||||
return;
|
return;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Tauri shell.open failed, falling back to window.open:', err);
|
console.warn('Tauri shell.open failed, falling back to window.open:', err);
|
||||||
|
|||||||
9
src/app/utils/tauriShell.ts
Normal file
9
src/app/utils/tauriShell.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Tauri shell open utility, only imported in Tauri builds
|
||||||
|
*/
|
||||||
|
|
||||||
|
export async function openWithTauriShell(url: string): Promise<void> {
|
||||||
|
// @ts-ignore
|
||||||
|
const { open } = await import(/* @vite-ignore */ '@tauri-apps/plugin-shell');
|
||||||
|
await open(url);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user