Files
archived-orca/mobile/src/session/use-mobile-session-preference-focus.ts
Neil 19043a3d76 refactor(mobile): organize pairing, session, RPC and host owners (#39846)
* refactor(mobile): give relay and encryption concrete owners

* refactor(mobile): organize session and review feature owners

* refactor(mobile): organize RPC and host ownership

* test(mobile): point render fixtures at concrete owners

* refactor(mobile): use explicit type-only owner imports
2026-11-08 07:19:05 -08:00

43 lines
1.6 KiB
TypeScript

import { useShellStorage } from '../platform/shell-storage'
import { settleSessionPreferenceRead } from './session-preference-read'
import { useCallback, useState } from 'react'
import { useFocusEffect } from 'expo-router'
import { loadTerminalLinkOpenMode, loadTerminalTextScale } from '../storage/preferences'
import type { MobileSessionKeyboardStateModel } from '../terminal/session/use-mobile-session-keyboard-state'
export function useMobileSessionPreferenceFocus(
scope: Pick<
MobileSessionKeyboardStateModel,
'setTerminalTextScale' | 'terminalTextScaleRevisionRef' | 'setTerminalLinkOpenMode'
>
) {
const { setTerminalTextScale, terminalTextScaleRevisionRef, setTerminalLinkOpenMode } = scope
const shellStorage = useShellStorage()
const [terminalPreferencesReady, setTerminalPreferencesReady] = useState(false)
// Reload on Settings return without dropping readiness or remounting terminal panes.
useFocusEffect(
useCallback(() => {
let active = true
const scaleRevision = terminalTextScaleRevisionRef.current
void settleSessionPreferenceRead(
Promise.all([loadTerminalTextScale(), loadTerminalLinkOpenMode()])
).then((preferences) => {
if (active) {
if (preferences) {
const [scale, linkMode] = preferences
if (terminalTextScaleRevisionRef.current === scaleRevision) {
setTerminalTextScale(scale)
}
setTerminalLinkOpenMode(linkMode)
}
setTerminalPreferencesReady(true)
}
})
return () => {
active = false
}
}, [shellStorage])
)
return { terminalPreferencesReady }
}