diff --git a/package.json b/package.json index b8b561a0..173f1d0d 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "react-native-mmkv": "3.3.3", "react-native-nitro-image": "0.8.1", "react-native-nitro-modules": "^0.31.3", - "react-native-nitro-ota": "^0.3.0", + "react-native-nitro-ota": "^0.4.0", "react-native-nitro-web-image": "0.8.1", "react-native-pager-view": "^6.9.1", "react-native-reanimated": "4.1.3", diff --git a/scripts/getRandomVersion.sh b/scripts/getRandomVersion.sh index 74b3afea..a750c6dd 100644 --- a/scripts/getRandomVersion.sh +++ b/scripts/getRandomVersion.sh @@ -30,11 +30,23 @@ get_random_sentence() { done } +# Function to generate a random 3-digit alphanumeric string +get_random_alphanum() { + local chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + local result="" + for i in {1..3}; do + result="${result}${chars:RANDOM%${#chars}:1}" + done + echo "$result" +} + new_sentence=$(get_random_sentence) +alphanum_suffix=$(get_random_alphanum) +version_string="${new_sentence} (${alphanum_suffix})" # Write atomically tmp="${FILE}.tmp.$$" -echo "$new_sentence" > "$tmp" +echo "$version_string" > "$tmp" mv "$tmp" "$FILE" -echo "✅ Updated $FILE with: \"$new_sentence\"" \ No newline at end of file +echo "✅ Updated $FILE with: \"$version_string\"" \ No newline at end of file diff --git a/src/components/OtaUpdates/index.tsx b/src/components/OtaUpdates/index.tsx index 56fa793e..9ee080d6 100644 --- a/src/components/OtaUpdates/index.tsx +++ b/src/components/OtaUpdates/index.tsx @@ -26,6 +26,23 @@ const { downloadUrl, versionUrl } = githubOTA({ const otaManager = new OTAUpdateManager(downloadUrl, versionUrl) +export const downloadUpdate = (showCatchAlert: boolean = false) => { + otaManager + .downloadUpdate() + .then(() => { + Alert.alert('Jellify has been updated!', 'Restart to apply the changes', [ + { text: 'OK', onPress: () => reloadApp() }, + { text: 'Cancel', style: 'cancel' }, + ]) + }) + .catch((error) => { + if (showCatchAlert) { + Alert.alert('Either the update is not available or there is an error') + } + console.error('Error downloading update:', error) + }) +} + const GitUpdateModal = () => { const progress = useSharedValue(0) const [loading, setLoading] = React.useState(false) @@ -47,21 +64,7 @@ const GitUpdateModal = () => { .checkForUpdates() .then((update) => { if (update) { - otaManager - .downloadUpdate() - .then(() => { - Alert.alert( - 'Jellify has been updated!', - 'Restart to apply the changes', - [ - { text: 'OK', onPress: () => reloadApp() }, - { text: 'Cancel', style: 'cancel' }, - ], - ) - }) - .catch((error) => { - console.error('Error downloading update:', error) - }) + downloadUpdate() } }) .catch((error) => { diff --git a/src/components/Settings/components/preferences-tab.tsx b/src/components/Settings/components/preferences-tab.tsx index 02087a86..c7e9fc0f 100644 --- a/src/components/Settings/components/preferences-tab.tsx +++ b/src/components/Settings/components/preferences-tab.tsx @@ -2,6 +2,10 @@ import { RadioGroup, YStack } from 'tamagui' import { SwitchWithLabel } from '../../Global/helpers/switch-with-label' import SettingsListGroup from './settings-list-group' import { RadioGroupItemWithLabel } from '../../Global/helpers/radio-group-item-with-label' +import Button from '../../Global/helpers/button' +import Icon from '../../Global/components/icon' +import { Text } from '../../Global/helpers/text' +import { downloadUpdate } from '../../OtaUpdates' import { ThemeSetting, useReducedHapticsSetting, @@ -68,6 +72,26 @@ export default function PreferencesTab(): React.JSX.Element { /> ), }, + + { + title: 'Forcefully download the latest OTA', + iconName: 'web', + iconColor: '$success', + subTitle: 'Download the latest ota forcefully', + children: ( + + ), + }, ]} /> ) diff --git a/yarn.lock b/yarn.lock index 9fa45221..2c85201a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8432,10 +8432,10 @@ react-native-nitro-modules@^0.31.3: resolved "https://registry.yarnpkg.com/react-native-nitro-modules/-/react-native-nitro-modules-0.31.3.tgz#19d26c3c677921687a42ed9c9943050034b3aebe" integrity sha512-jGHBfSTzSo6eXcb0X4/N1sfYdHm2E+koE2fifLZ3gtArD+3ZeThyFvERhB2fzd4JOqtcIJL/5VLIjxlbjISQ/g== -react-native-nitro-ota@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/react-native-nitro-ota/-/react-native-nitro-ota-0.3.0.tgz#f3a45db30c120b1ad6230229e8725f8e0e827b96" - integrity sha512-dOus16bKJ4wLsPWFLToXoEOiCl5loxh8l3fPqF4WiMxiLkUyXuH3mh+e0S5HIdd8kbnZHqtLGofCX0CdUxksnQ== +react-native-nitro-ota@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/react-native-nitro-ota/-/react-native-nitro-ota-0.4.0.tgz#996b2ccaf6accc92b1d352df448250ca35a6d2e6" + integrity sha512-/JAoM2m3WsvnO7dC51bf5jCghxO78yrP3vHyq3/itK+MqiwU8HPk8bGbXLhE+/GYRPS8DbUHGrzptzO2KOoutQ== react-native-nitro-web-image@0.8.1: version "0.8.1"