toggle for tuning off update alerts

This commit is contained in:
tapframe 2025-12-16 15:47:56 +05:30
parent 8c0b47975c
commit 78553d8323
3 changed files with 467 additions and 315 deletions

View file

@ -26,6 +26,12 @@ export function useGithubMajorUpdate(): MajorUpdateData {
const check = useCallback(async () => { const check = useCallback(async () => {
if (Platform.OS === 'ios') return; if (Platform.OS === 'ios') return;
try { try {
// Check if major update alerts are disabled
const majorAlertsEnabled = await mmkvStorage.getItem('@major_updates_alerts_enabled');
if (majorAlertsEnabled === 'false') {
return; // Major update alerts are disabled by user
}
// Always compare with Settings screen version // Always compare with Settings screen version
const current = getDisplayedAppVersion() || Updates.runtimeVersion || '0.0.0'; const current = getDisplayedAppVersion() || Updates.runtimeVersion || '0.0.0';
const info = await fetchLatestGithubRelease(); const info = await fetchLatestGithubRelease();

View file

@ -28,6 +28,11 @@ export const useUpdatePopup = (): UseUpdatePopupReturn => {
const checkForUpdates = useCallback(async (forceCheck = false) => { const checkForUpdates = useCallback(async (forceCheck = false) => {
try { try {
// Check if OTA update alerts are disabled
const otaAlertsEnabled = await mmkvStorage.getItem('@ota_updates_alerts_enabled');
if (otaAlertsEnabled === 'false' && !forceCheck) {
return; // OTA alerts are disabled by user
}
// Check if user has dismissed the popup for this version // Check if user has dismissed the popup for this version
const dismissedVersion = await mmkvStorage.getItem(UPDATE_POPUP_STORAGE_KEY); const dismissedVersion = await mmkvStorage.getItem(UPDATE_POPUP_STORAGE_KEY);

View file

@ -9,7 +9,8 @@ import {
StatusBar, StatusBar,
Platform, Platform,
Dimensions, Dimensions,
Linking Linking,
Switch
} from 'react-native'; } from 'react-native';
import { useToast } from '../contexts/ToastContext'; import { useToast } from '../contexts/ToastContext';
import { useNavigation } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native';
@ -111,6 +112,71 @@ const UpdateScreen: React.FC = () => {
const [updateProgress, setUpdateProgress] = useState<number>(0); const [updateProgress, setUpdateProgress] = useState<number>(0);
const [updateStatus, setUpdateStatus] = useState<'idle' | 'checking' | 'available' | 'downloading' | 'installing' | 'success' | 'error'>('idle'); const [updateStatus, setUpdateStatus] = useState<'idle' | 'checking' | 'available' | 'downloading' | 'installing' | 'success' | 'error'>('idle');
// Update notification settings
const [otaAlertsEnabled, setOtaAlertsEnabled] = useState(true);
const [majorAlertsEnabled, setMajorAlertsEnabled] = useState(true);
// Load notification settings on mount
useEffect(() => {
(async () => {
try {
const otaSetting = await mmkvStorage.getItem('@ota_updates_alerts_enabled');
const majorSetting = await mmkvStorage.getItem('@major_updates_alerts_enabled');
// Default to true if not set
setOtaAlertsEnabled(otaSetting !== 'false');
setMajorAlertsEnabled(majorSetting !== 'false');
} catch { }
})();
}, []);
// Handle toggling OTA alerts with warning
const handleOtaAlertsToggle = async (value: boolean) => {
if (!value) {
openAlert(
'Disable OTA Update Alerts?',
'You will no longer receive automatic notifications for OTA updates.\n\n⚠ Warning: Staying on the latest version is important for:\n• Bug fixes and stability improvements\n• New features and enhancements\n• Providing accurate feedback and crash reports\n\nYou can still manually check for updates in this screen.',
[
{ label: 'Cancel', onPress: () => setAlertVisible(false) },
{
label: 'Disable',
onPress: async () => {
await mmkvStorage.setItem('@ota_updates_alerts_enabled', 'false');
setOtaAlertsEnabled(false);
setAlertVisible(false);
}
}
]
);
} else {
await mmkvStorage.setItem('@ota_updates_alerts_enabled', 'true');
setOtaAlertsEnabled(true);
}
};
// Handle toggling Major update alerts with warning
const handleMajorAlertsToggle = async (value: boolean) => {
if (!value) {
openAlert(
'Disable Major Update Alerts?',
'You will no longer receive notifications for major app updates that require reinstallation.\n\n⚠ Warning: Major updates often include:\n• Critical security patches\n• Breaking changes that require app reinstall\n• Important compatibility fixes\n\nYou can still check for updates manually.',
[
{ label: 'Cancel', onPress: () => setAlertVisible(false) },
{
label: 'Disable',
onPress: async () => {
await mmkvStorage.setItem('@major_updates_alerts_enabled', 'false');
setMajorAlertsEnabled(false);
setAlertVisible(false);
}
}
]
);
} else {
await mmkvStorage.setItem('@major_updates_alerts_enabled', 'true');
setMajorAlertsEnabled(true);
}
};
const checkForUpdates = async () => { const checkForUpdates = async () => {
try { try {
setIsChecking(true); setIsChecking(true);
@ -575,6 +641,57 @@ const UpdateScreen: React.FC = () => {
</SettingsCard> </SettingsCard>
) : null} ) : null}
{/* Update Notification Settings */}
<SettingsCard title="NOTIFICATION SETTINGS" isTablet={isTablet}>
{/* OTA Updates Toggle */}
<View style={styles.settingRow}>
<View style={styles.settingInfo}>
<Text style={[styles.settingLabel, { color: currentTheme.colors.highEmphasis }]}>
OTA Update Alerts
</Text>
<Text style={[styles.settingDescription, { color: currentTheme.colors.mediumEmphasis }]}>
Show notifications for over-the-air updates
</Text>
</View>
<Switch
value={otaAlertsEnabled}
onValueChange={handleOtaAlertsToggle}
trackColor={{ false: '#505050', true: currentTheme.colors.primary }}
thumbColor={Platform.OS === 'android' ? '#fff' : undefined}
ios_backgroundColor="#505050"
/>
</View>
{/* Major Updates Toggle */}
<View style={[styles.settingRow, { borderBottomWidth: 0 }]}>
<View style={styles.settingInfo}>
<Text style={[styles.settingLabel, { color: currentTheme.colors.highEmphasis }]}>
Major Update Alerts
</Text>
<Text style={[styles.settingDescription, { color: currentTheme.colors.mediumEmphasis }]}>
Show notifications for new app versions on GitHub
</Text>
</View>
<Switch
value={majorAlertsEnabled}
onValueChange={handleMajorAlertsToggle}
trackColor={{ false: '#505050', true: currentTheme.colors.primary }}
thumbColor={Platform.OS === 'android' ? '#fff' : undefined}
ios_backgroundColor="#505050"
/>
</View>
{/* Warning note */}
<View style={[styles.infoItem, { paddingHorizontal: 16, paddingBottom: 12 }]}>
<View style={[styles.infoIcon, { backgroundColor: `${currentTheme.colors.warning || '#FFA500'}20` }]}>
<MaterialIcons name="info-outline" size={14} color={currentTheme.colors.warning || '#FFA500'} />
</View>
<Text style={[styles.settingDescription, { color: currentTheme.colors.mediumEmphasis, flex: 1 }]}>
Keeping alerts enabled ensures you receive bug fixes and can provide accurate crash reports.
</Text>
</View>
</SettingsCard>
{false && ( {false && (
<SettingsCard title="UPDATE LOGS" isTablet={isTablet}> <SettingsCard title="UPDATE LOGS" isTablet={isTablet}>
<View style={styles.logsContainer}> <View style={styles.logsContainer}>
@ -962,6 +1079,30 @@ const styles = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
paddingVertical: 20, paddingVertical: 20,
}, },
// Settings toggle styles
settingRow: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 14,
paddingHorizontal: 16,
borderBottomWidth: 0.5,
borderBottomColor: 'rgba(255, 255, 255, 0.1)',
},
settingInfo: {
flex: 1,
marginRight: 12,
},
settingLabel: {
fontSize: 16,
fontWeight: '500',
marginBottom: 4,
},
settingDescription: {
fontSize: 13,
lineHeight: 18,
},
}); });
export default UpdateScreen; export default UpdateScreen;