/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/settings/files/hooks.tsx
129 строк
4 KB
chrisnojima
build(mobile): harden gobuild.sh and go bind pipeline 2 (#29364)
08 июл 2026, 15:25
Не верифицирован
08 июл 2026, 15:25
19b55b3
Код
Авторство
О чём код?
import * as C from '@/constants' import * as React from 'react' import * as T from '@/constants/types' import {useEngineActionListener} from '@/engine/action-listener' import {clientID as fsClientID} from '@/fs/common/client' import {produce} from 'immer' export const allowedNotificationThresholds = [100 * 1024 ** 2, 1024 ** 3, 3 * 1024 ** 3, 10 * 1024 ** 3] export const defaultNotificationThreshold = 100 * 1024 ** 2 type FilesSettings = { isLoading: boolean spaceAvailableNotificationThreshold: number syncOnCellular: boolean } const useFiles = () => { const [settings, setSettings] = React.useState<FilesSettings>(() => ({ isLoading: true, spaceAvailableNotificationThreshold: 0, syncOnCellular: false, })) const readSettings = React.useCallback(async () => T.RPCGen.SimpleFSSimpleFSSettingsRpcPromise(), []) const loadSettings = React.useEffectEvent(async (showLoading: boolean) => { if (showLoading) { setSettings( produce(draft => { draft.isLoading = true }) ) } try { const next = await readSettings() setSettings({ isLoading: false, spaceAvailableNotificationThreshold: next.spaceAvailableNotificationThreshold, syncOnCellular: next.syncOnCellular, }) } catch { setSettings( produce(draft => { draft.isLoading = false }) ) } }) React.useEffect(() => { let canceled = false const f = async () => { try { const next = await readSettings() if (!canceled) { setSettings({ isLoading: false, spaceAvailableNotificationThreshold: next.spaceAvailableNotificationThreshold, syncOnCellular: next.syncOnCellular, }) } } catch { if (!canceled) { setSettings( produce(draft => { draft.isLoading = false }) ) } } } C.ignorePromise(f()) return () => { canceled = true } }, [readSettings]) useEngineActionListener('keybase.1.NotifyFS.FSSubscriptionNotify', action => { const {clientID, topic} = action.payload.params if (clientID === fsClientID && topic === T.RPCGen.SubscriptionTopic.settings) { C.ignorePromise(loadSettings(true)) } }) const setSpaceAvailableNotificationThreshold = (threshold: number) => { const f = async () => { setSettings( produce(draft => { draft.isLoading = true }) ) try { await T.RPCGen.SimpleFSSimpleFSSetNotificationThresholdRpcPromise({threshold}) await loadSettings(true) } catch { setSettings( produce(draft => { draft.isLoading = false }) ) } } C.ignorePromise(f()) } const setSyncOnCellular = (syncOnCellular: boolean) => { const f = async () => { try { await T.RPCGen.SimpleFSSimpleFSSetSyncOnCellularRpcPromise( {syncOnCellular}, C.waitingKeyFSSetSyncOnCellular ) await loadSettings(true) } catch {} } C.ignorePromise(f()) } const onDisableSyncNotifications = () => { setSpaceAvailableNotificationThreshold(0) } return { areSettingsLoading: settings.isLoading, onDisableSyncNotifications, onEnableSyncNotifications: () => setSpaceAvailableNotificationThreshold(defaultNotificationThreshold), setSpaceAvailableNotificationThreshold, setSyncOnCellular, spaceAvailableNotificationThreshold: settings.spaceAvailableNotificationThreshold, syncOnCellular: settings.syncOnCellular, } } export default useFiles