Skip to content

Commit

Permalink
Merge pull request #285 from OpenDTU-App/276-links-not-working
Browse files Browse the repository at this point in the history
Implement better error visualization for linking.canOpen
  • Loading branch information
CommanderRedYT authored Dec 18, 2024
2 parents 7de4b96 + 5f62319 commit 3f5c74b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
<!-- https://stackoverflow.com/a/70672054 -->
<data android:host="*" />
</intent>
</queries>
</manifest>
12 changes: 11 additions & 1 deletion src/components/firmware/FirmwareListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
Expand All @@ -35,6 +37,8 @@ const needsCapitalization: Record<SupportedLanguage, boolean> = {
de: true,
};

const log = rootLogging.extend('FirmwareListItem');

const FirmwareListItem: FC<FirmwareListItemProps> = ({
release,
selectRelease,
Expand All @@ -53,8 +57,14 @@ const FirmwareListItem: FC<FirmwareListItemProps> = ({

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);
Expand Down
8 changes: 6 additions & 2 deletions src/components/modals/ChangeLanguageModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Text,
useTheme,
} from 'react-native-paper';
import Toast from 'react-native-toast-message';

import { Linking } from 'react-native';

Expand Down Expand Up @@ -53,10 +54,13 @@ const ChangeLanguageModal: FC<Omit<ModalProps, 'children'>> = 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 (
<Portal>
Expand Down
2 changes: 1 addition & 1 deletion src/translations
11 changes: 11 additions & 0 deletions src/views/navigation/screens/InformationGroup/LicensesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ 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';

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';

const log = rootLogging.extend('LicensesScreen');

const LicensesScreen: FC<PropsWithNavigation> = ({ navigation }) => {
const { t } = useTranslation();
const theme = useTheme();
Expand Down Expand Up @@ -41,6 +46,12 @@ const LicensesScreen: FC<PropsWithNavigation> = ({ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -20,13 +21,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';

const log = rootLogging.extend('SystemInformationScreen');

const SystemInformationScreen: FC<PropsWithNavigation> = ({ navigation }) => {
const theme = useTheme();
const { t } = useTranslation();
Expand Down Expand Up @@ -62,8 +66,14 @@ const SystemInformationScreen: FC<PropsWithNavigation> = ({ 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)
Expand Down

0 comments on commit 3f5c74b

Please sign in to comment.