Refactor URL opening logic and update imports for improved modularity

- Moved the openUrl function to a new utility file for better organization and reusability across components.
- Updated import paths in Home and GetStartedStep components to reflect the new location of the openUrl function.
- Simplified error handling in the handleStartCooking function by removing unnecessary try-catch block.

These changes enhance code maintainability and streamline the process of opening URLs in the application.
This commit is contained in:
Steven Enamakel
2026-01-28 01:55:01 +05:30
parent 0929a3681d
commit cb0cf66649
4 changed files with 28 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
VITE_TELEGRAM_BOT_USERNAME=steve_test_bot
VITE_TELEGRAM_BOT_USERNAME=steve_test_robot
+2 -6
View File
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { openUrl } from '@tauri-apps/plugin-opener';
import { openUrl } from '../utils/openUrl';
import { TELEGRAM_BOT_USERNAME } from '../utils/config';
import ConnectionIndicator from '../components/ConnectionIndicator';
@@ -24,11 +24,7 @@ const Home = () => {
// Handle Telegram bot link
const handleStartCooking = async () => {
try {
await openUrl(`https://t.me/${TELEGRAM_BOT_USERNAME}`);
} catch (error) {
console.error('Failed to open Telegram:', error);
}
await openUrl(`https://t.me/${TELEGRAM_BOT_USERNAME}`);
};
const handleManageConnections = () => {
+4 -10
View File
@@ -1,4 +1,4 @@
import { openUrl } from '@tauri-apps/plugin-opener';
import { openUrl } from '../../../utils/openUrl';
import { TELEGRAM_BOT_USERNAME } from '../../../utils/config';
import ConnectionIndicator from '../../../components/ConnectionIndicator';
@@ -8,15 +8,9 @@ interface GetStartedStepProps {
const GetStartedStep = ({ onComplete }: GetStartedStepProps) => {
const handleOpenTelegram = async () => {
try {
// Open Telegram and navigate to home immediately
await openUrl(`https://t.me/${TELEGRAM_BOT_USERNAME}`);
onComplete();
} catch (error) {
console.error('Failed to open Telegram:', error);
// Still navigate to home even if opening Telegram fails
onComplete();
}
// Open Telegram and navigate to home immediately
await openUrl(`https://t.me/${TELEGRAM_BOT_USERNAME}`);
onComplete();
};
return (
+21
View File
@@ -0,0 +1,21 @@
import { openUrl as tauriOpenUrl } from '@tauri-apps/plugin-opener';
/**
* Opens a URL in the default browser or app.
* Works in both Tauri desktop app and regular browser environments.
*/
export const openUrl = async (url: string): Promise<void> => {
// Check if we're running in Tauri desktop app
if ((window as any).__TAURI__) {
try {
await tauriOpenUrl(url);
return;
} catch (error) {
console.error('Failed to open URL with Tauri:', error);
// Fall through to browser fallback
}
}
// Browser fallback
window.open(url, '_blank', 'noopener,noreferrer');
};