import deepEqual from 'fast-deep-equal' ; import type { TypedUseSelectorHook } from 'react-redux' ; import { shallowEqual , useSelector as useReduxSelector } from 'react-redux' ; import type { AppId , Apps } from '../../../config/apps' ; import { apps as allApps } from '../../../config/apps' ; import type { RootState } from '../../../shared/state/reducer.root' ; export const useSelector = useReduxSelector ; export const useShallowEqualSelector = ( selector ) => useSelector ( selector , shallowEqual ) ; export const useDeepEqualSelector = ( selector ) => useSelector ( selector , deepEqual ) ; export interface InstalledApp { id : AppId ; name : Apps [ AppId ] [ 'name' ] ; hotCode : string | null ; } export const useInstalledApps = ( ) : InstalledApp [ ] => { const storedApps = useDeepEqualSelector ( ( state ) => state . storage . apps ) ; const installedApps = useDeepEqualSelector ( ( state ) => state . data . installedApps ) ; return storedApps . filter ( ( storedApp ) => installedApps . includes ( storedApp . id ) ) . map ( ( storedApp ) => ( { id : storedApp . id , hotCode : storedApp . hotCode , name : allApps [ storedApp . id ] . name } ) ) ; } ; export const useIsSupportMessageHidden = ( ) : boolean => { const supportMessageNumber = useSelector ( ( state ) => state . storage . supportMessage ) ; const ONE_WEEK = 604800000 ; return ( supportMessageNumber === - 1 || supportMessageNumber > Date . now ( ) - ONE_WEEK ) ; } ; export const useKeyCodeMap = ( ) : Record < string , string > => useShallowEqualSelector ( ( state ) => state . data . keyCodeMap ) ;