Bluesky app fork with some witchin' additions 💫

Clear image cache button (#8190)

authored by samuel.fm and committed by

GitHub cf6c8dc3 719d7b7a

+59 -3
+1
assets/icons/broomSparkle_stroke2_corner2_rounded.svg
··· 1 + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path fill="#000" fill-rule="evenodd" d="M20.494 2.13a1 1 0 0 1 .375 1.364l-4.658 8.2.263.095c1.52.554 2.737 2.062 2.484 3.864-.336 2.393-1.358 4.12-3.245 6.047a1 1 0 0 1-1.102.222l-9.5-4a1 1 0 0 1-.166-1.754c1.458-.971 2.623-1.923 3.498-3.3 1.057-1.662 3.154-2.854 5.281-2.08l.58.212 4.827-8.494a1 1 0 0 1 1.363-.375ZM13.04 12.669c-.983-.358-2.19.142-2.91 1.273-.737 1.16-1.628 2.054-2.601 2.828l1.708.72a.2.2 0 0 0 .177-.011l2.13-1.218a.2.2 0 0 1 .29.237l-.551 1.653a.2.2 0 0 0 .112.247l3.353 1.413c1.359-1.494 1.994-2.76 2.23-4.435.094-.675-.359-1.405-1.188-1.707l-2.75-1ZM4.407 7.184a.5.5 0 0 1-.224.224l-1.29.645a.5.5 0 0 0 0 .894l1.29.645a.5.5 0 0 1 .224.224l.645 1.29a.5.5 0 0 0 .894 0l.645-1.29a.5.5 0 0 1 .224-.224l1.29-.645a.5.5 0 0 0 0-.894l-1.29-.645a.5.5 0 0 1-.224-.224l-.645-1.29a.5.5 0 0 0-.894 0l-.645 1.29ZM9.559 3.72a.36.36 0 0 0 .16-.16l.46-.921a.357.357 0 0 1 .64 0l.46.921q.054.106.16.16l.921.46a.357.357 0 0 1 0 .64l-.921.46a.36.36 0 0 0-.16.16l-.46.921a.357.357 0 0 1-.64 0l-.46-.921a.36.36 0 0 0-.16-.16l-.921-.46a.357.357 0 0 1 0-.64l.921-.46Z" clip-rule="evenodd"/></svg>
+5
src/components/icons/BroomSparkle.tsx
··· 1 + import {createSinglePathSVG} from './TEMPLATE' 2 + 3 + export const BroomSparkle_Stroke2_Corner2_Rounded = createSinglePathSVG({ 4 + path: 'M20.494 2.13a1 1 0 0 1 .375 1.364l-4.658 8.2.263.095c1.52.554 2.737 2.062 2.484 3.864-.336 2.393-1.358 4.12-3.245 6.047a1 1 0 0 1-1.102.222l-9.5-4a1 1 0 0 1-.166-1.754c1.458-.971 2.623-1.923 3.498-3.3 1.057-1.662 3.154-2.854 5.281-2.08l.58.212 4.827-8.494a1 1 0 0 1 1.363-.375ZM13.04 12.669c-.983-.358-2.19.142-2.91 1.273-.737 1.16-1.628 2.054-2.601 2.828l1.708.72a.2.2 0 0 0 .177-.011l2.13-1.218a.2.2 0 0 1 .29.237l-.551 1.653a.2.2 0 0 0 .112.247l3.353 1.413c1.359-1.494 1.994-2.76 2.23-4.435.094-.675-.359-1.405-1.188-1.707l-2.75-1ZM4.407 7.184a.5.5 0 0 1-.224.224l-1.29.645a.5.5 0 0 0 0 .894l1.29.645a.5.5 0 0 1 .224.224l.645 1.29a.5.5 0 0 0 .894 0l.645-1.29a.5.5 0 0 1 .224-.224l1.29-.645a.5.5 0 0 0 0-.894l-1.29-.645a.5.5 0 0 1-.224-.224l-.645-1.29a.5.5 0 0 0-.894 0l-.645 1.29ZM9.559 3.72a.36.36 0 0 0 .16-.16l.46-.921a.357.357 0 0 1 .64 0l.46.921q.054.106.16.16l.921.46a.357.357 0 0 1 0 .64l-.921.46a.36.36 0 0 0-.16.16l-.46.921a.357.357 0 0 1-.64 0l-.46-.921a.36.36 0 0 0-.16-.16l-.921-.46a.357.357 0 0 1 0-.64l.921-.46Z', 5 + })
+53 -3
src/screens/Settings/AboutSettings.tsx
··· 1 1 import {useMemo} from 'react' 2 2 import {Platform} from 'react-native' 3 3 import {setStringAsync} from 'expo-clipboard' 4 + import * as FileSystem from 'expo-file-system' 5 + import {Image} from 'expo-image' 4 6 import {msg, Trans} from '@lingui/macro' 5 7 import {useLingui} from '@lingui/react' 6 - import {NativeStackScreenProps} from '@react-navigation/native-stack' 8 + import {type NativeStackScreenProps} from '@react-navigation/native-stack' 9 + import {useMutation} from '@tanstack/react-query' 7 10 import {Statsig} from 'statsig-react-native-expo' 8 11 9 12 import {appVersion, BUNDLE_DATE, bundleInfo} from '#/lib/app-info' 10 13 import {STATUS_PAGE_URL} from '#/lib/constants' 11 - import {CommonNavigatorParams} from '#/lib/routes/types' 14 + import {type CommonNavigatorParams} from '#/lib/routes/types' 15 + import {isAndroid, isNative} from '#/platform/detection' 12 16 import {useDevModeEnabled} from '#/state/preferences/dev-mode' 13 17 import * as Toast from '#/view/com/util/Toast' 14 18 import * as SettingsList from '#/screens/Settings/components/SettingsList' 19 + import {BroomSparkle_Stroke2_Corner2_Rounded as BroomSparkleIcon} from '#/components/icons/BroomSparkle' 15 20 import {CodeLines_Stroke2_Corner2_Rounded as CodeLinesIcon} from '#/components/icons/CodeLines' 16 21 import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe' 17 22 import {Newspaper_Stroke2_Corner2_Rounded as NewspaperIcon} from '#/components/icons/Newspaper' 18 23 import {Wrench_Stroke2_Corner2_Rounded as WrenchIcon} from '#/components/icons/Wrench' 19 24 import * as Layout from '#/components/Layout' 25 + import {Loader} from '#/components/Loader' 20 26 import {OTAInfo} from './components/OTAInfo' 21 27 22 28 type Props = NativeStackScreenProps<CommonNavigatorParams, 'AboutSettings'> 23 29 export function AboutSettingsScreen({}: Props) { 24 - const {_} = useLingui() 30 + const {_, i18n} = useLingui() 25 31 const [devModeEnabled, setDevModeEnabled] = useDevModeEnabled() 26 32 const stableID = useMemo(() => Statsig.getStableID(), []) 27 33 34 + const {mutate: onClearImageCache, isPending: isClearingImageCache} = 35 + useMutation({ 36 + mutationFn: async () => { 37 + const freeSpaceBefore = await FileSystem.getFreeDiskStorageAsync() 38 + await Image.clearDiskCache() 39 + const freeSpaceAfter = await FileSystem.getFreeDiskStorageAsync() 40 + const spaceDiff = freeSpaceBefore - freeSpaceAfter 41 + return spaceDiff * -1 42 + }, 43 + onSuccess: sizeDiffBytes => { 44 + if (isAndroid) { 45 + Toast.show( 46 + _( 47 + msg({ 48 + message: `Image cache cleared, freed ${i18n.number( 49 + Math.abs(sizeDiffBytes / 1024 / 1024), 50 + { 51 + notation: 'compact', 52 + style: 'unit', 53 + unit: 'megabyte', 54 + }, 55 + )}`, 56 + comment: `Android-only toast message which includes amount of space freed using localized number formatting`, 57 + }), 58 + ), 59 + ) 60 + } else { 61 + Toast.show(_(msg`Image cache cleared`)) 62 + } 63 + }, 64 + }) 65 + 28 66 return ( 29 67 <Layout.Screen> 30 68 <Layout.Header.Outer> ··· 69 107 <Trans>System log</Trans> 70 108 </SettingsList.ItemText> 71 109 </SettingsList.LinkItem> 110 + {isNative && ( 111 + <SettingsList.PressableItem 112 + onPress={() => onClearImageCache()} 113 + label={_(msg`Clear image cache`)} 114 + disabled={isClearingImageCache}> 115 + <SettingsList.ItemIcon icon={BroomSparkleIcon} /> 116 + <SettingsList.ItemText> 117 + <Trans>Clear image cache</Trans> 118 + </SettingsList.ItemText> 119 + {isClearingImageCache && <SettingsList.ItemIcon icon={Loader} />} 120 + </SettingsList.PressableItem> 121 + )} 72 122 <SettingsList.PressableItem 73 123 label={_(msg`Version ${appVersion}`)} 74 124 accessibilityHint={_(msg`Copies build version to clipboard`)}