From 33eb9b88f242b955b1c23bdd8be4618795e4720b Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 18 Dec 2024 08:36:38 +0100 Subject: [PATCH 1/3] Implement better error visualization for linking.canOpen errors --- src/components/firmware/FirmwareListItem.tsx | 12 +++++++++++- src/components/modals/ChangeLanguageModal.tsx | 8 ++++++-- src/translations | 2 +- .../screens/InformationGroup/LicensesScreen.tsx | 11 +++++++++++ .../InformationGroup/SystemInformationScreen.tsx | 12 +++++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/components/firmware/FirmwareListItem.tsx b/src/components/firmware/FirmwareListItem.tsx index be03485..80d2549 100644 --- a/src/components/firmware/FirmwareListItem.tsx +++ b/src/components/firmware/FirmwareListItem.tsx @@ -2,6 +2,7 @@ import type { FC } from 'react'; import { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Badge, Divider, List, Text, useTheme } from 'react-native-paper'; +import Toast from 'react-native-toast-message'; import { Linking, View } from 'react-native'; @@ -18,6 +19,7 @@ import useDtuState from '@/hooks/useDtuState'; import useHasAuthConfigured from '@/hooks/useHasAuthConfigured'; import capitalize from '@/utils/capitalize'; +import { rootLogging } from '@/utils/log'; import { minimumOpenDtuFirmwareVersion, spacing } from '@/constants'; import type { SupportedLanguage } from '@/translations'; @@ -35,6 +37,8 @@ const needsCapitalization: Record = { de: true, }; +const log = rootLogging.extend('FirmwareListItem'); + const FirmwareListItem: FC = ({ release, selectRelease, @@ -53,8 +57,14 @@ const FirmwareListItem: FC = ({ if (await Linking.canOpenURL(url)) { await Linking.openURL(url); + } else { + log.error(`Cannot open URL: ${url}`); + Toast.show({ + type: 'error', + text1: t('cannotOpenUrl'), + }); } - }, [release.html_url]); + }, [release.html_url, t]); const handleInstallFirmware = useCallback(() => { selectRelease(release); diff --git a/src/components/modals/ChangeLanguageModal.tsx b/src/components/modals/ChangeLanguageModal.tsx index 7446975..b7e1a00 100644 --- a/src/components/modals/ChangeLanguageModal.tsx +++ b/src/components/modals/ChangeLanguageModal.tsx @@ -25,6 +25,7 @@ import { colors, weblateUrl } from '@/constants'; import { useAppDispatch } from '@/store'; import type { SupportedLanguage } from '@/translations'; import { supportedLanguages } from '@/translations'; +import Toast from 'react-native-toast-message'; const log = rootLogging.extend('ChangeLanguageModal'); @@ -53,10 +54,13 @@ const ChangeLanguageModal: FC> = props => { if (await Linking.canOpenURL(weblateUrl)) { await Linking.openURL(weblateUrl); } else { - // TODO: Better error handling (issue #101) log.error('Cannot open Weblate URL'); + Toast.show({ + type: 'error', + text1: t('cannotOpenUrl'), + }); } - }, []); + }, [t]); return ( diff --git a/src/translations b/src/translations index 730dabd..fe5fb1e 160000 --- a/src/translations +++ b/src/translations @@ -1 +1 @@ -Subproject commit 730dabd97144a8616226258cc3309401003c3847 +Subproject commit fe5fb1e82a6f7cc2f861629935174212df81dfa9 diff --git a/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx b/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx index 31d7b06..ad23fa7 100644 --- a/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx +++ b/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx @@ -7,11 +7,16 @@ import { Linking, ScrollView, View } from 'react-native'; import type { Licenses } from 'npm-license-crawler'; +import { rootLogging } from '@/utils/log'; + import { spacing } from '@/constants'; import { StyledView } from '@/style'; import type { PropsWithNavigation } from '@/views/navigation/NavigationStack'; import licenses from '@root/licenses.json'; +import Toast from 'react-native-toast-message'; + +const log = rootLogging.extend('LicensesScreen'); const LicensesScreen: FC = ({ navigation }) => { const { t } = useTranslation(); @@ -41,6 +46,12 @@ const LicensesScreen: FC = ({ navigation }) => { const url = repository || licenseUrl; if (await Linking.canOpenURL(url)) { await Linking.openURL(url); + } else { + log.error(`Cannot open URL: ${url}`); + Toast.show({ + type: 'error', + text1: t('cannotOpenUrl'), + }); } } : undefined diff --git a/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx b/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx index 75b478d..81cb710 100644 --- a/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx +++ b/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx @@ -20,12 +20,16 @@ import useHasNewOpenDtuVersion from '@/hooks/useHasNewOpenDtuVersion'; import correctTag from '@/utils/correctTag'; import formatBytes from '@/utils/formatBytes'; +import { rootLogging } from '@/utils/log'; import percentage from '@/utils/percentage'; import { colors, spacing } from '@/constants'; import { useAppDispatch, useAppSelector } from '@/store'; import { StyledView } from '@/style'; import type { PropsWithNavigation } from '@/views/navigation/NavigationStack'; +import Toast from 'react-native-toast-message'; + +const log = rootLogging.extend('SystemInformationScreen'); const SystemInformationScreen: FC = ({ navigation }) => { const theme = useTheme(); @@ -62,8 +66,14 @@ const SystemInformationScreen: FC = ({ navigation }) => { if (await Linking.canOpenURL(url)) { await Linking.openURL(url); + } else { + log.error(`Cannot open URL: ${url}`); + Toast.show({ + type: 'error', + text1: t('cannotOpenUrl'), + }); } - }, [systemStatus]); + }, [systemStatus, t]); const versionString = useMemo(() => { if (!latestVersion || !systemStatus?.git_hash) From d3530d11f441eb6c9fb550b838309948100f45a0 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 18 Dec 2024 08:38:19 +0100 Subject: [PATCH 2/3] Fix linting --- src/components/modals/ChangeLanguageModal.tsx | 2 +- .../navigation/screens/InformationGroup/LicensesScreen.tsx | 2 +- .../screens/InformationGroup/SystemInformationScreen.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/modals/ChangeLanguageModal.tsx b/src/components/modals/ChangeLanguageModal.tsx index b7e1a00..f12cfde 100644 --- a/src/components/modals/ChangeLanguageModal.tsx +++ b/src/components/modals/ChangeLanguageModal.tsx @@ -10,6 +10,7 @@ import { Text, useTheme, } from 'react-native-paper'; +import Toast from 'react-native-toast-message'; import { Linking } from 'react-native'; @@ -25,7 +26,6 @@ import { colors, weblateUrl } from '@/constants'; import { useAppDispatch } from '@/store'; import type { SupportedLanguage } from '@/translations'; import { supportedLanguages } from '@/translations'; -import Toast from 'react-native-toast-message'; const log = rootLogging.extend('ChangeLanguageModal'); diff --git a/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx b/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx index ad23fa7..1902d4b 100644 --- a/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx +++ b/src/views/navigation/screens/InformationGroup/LicensesScreen.tsx @@ -2,6 +2,7 @@ import type { FC } from 'react'; import { useTranslation } from 'react-i18next'; import { Box } from 'react-native-flex-layout'; import { Appbar, List, useTheme } from 'react-native-paper'; +import Toast from 'react-native-toast-message'; import { Linking, ScrollView, View } from 'react-native'; @@ -14,7 +15,6 @@ import { StyledView } from '@/style'; import type { PropsWithNavigation } from '@/views/navigation/NavigationStack'; import licenses from '@root/licenses.json'; -import Toast from 'react-native-toast-message'; const log = rootLogging.extend('LicensesScreen'); diff --git a/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx b/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx index 81cb710..32a983b 100644 --- a/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx +++ b/src/views/navigation/screens/InformationGroup/SystemInformationScreen.tsx @@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Box } from 'react-native-flex-layout'; import { Appbar, Badge, List, Switch, useTheme } from 'react-native-paper'; +import Toast from 'react-native-toast-message'; import { Linking, ScrollView, View } from 'react-native'; @@ -27,7 +28,6 @@ import { colors, spacing } from '@/constants'; import { useAppDispatch, useAppSelector } from '@/store'; import { StyledView } from '@/style'; import type { PropsWithNavigation } from '@/views/navigation/NavigationStack'; -import Toast from 'react-native-toast-message'; const log = rootLogging.extend('SystemInformationScreen'); From 5f623191976b1a9df351791d8be627be63209fbb Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 18 Dec 2024 10:25:26 +0100 Subject: [PATCH 3/3] Fix links not working --- android/app/src/main/AndroidManifest.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f200221..f6f0561 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -39,6 +39,8 @@ + +