Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ Read on every request, so behaviour can be flipped mid-session without a restart
2. In Orca, go to Settings > Mobile and scan the QR code with this app
3. The QR encodes the connection endpoint, device token, and TLS fingerprint

## Samsung DeX / desktop mode

Manifest changes require a native Android rebuild; Expo Go cannot validate them.

```bash
pnpm exec expo prebuild --platform android --clean
cd android
./gradlew assembleDebug
```

Use the manual DeX, multi-window, hardware-keyboard, and DPI checklist in
[`docs/dex-mode-layout-design.md`](docs/dex-mode-layout-design.md#62-manual-dex-checklist).
The native Activity display-metrics hook works around
[React Native #55659](https://github.com/facebook/react-native/issues/55659), which otherwise uses
the phone display's density for windows on a DeX monitor. A density-only change at identical pixel
bounds may wait for the next geometry-driven layout; DeX enter, exit, resize, and maximize also
change the window bounds.
RN Android does not deliver every arrow/Ctrl/F-key event; the terminal accessory row remains the
fallback until the planned native hardware-key module lands.

## Project Structure

```
Expand Down
1 change: 1 addition & 0 deletions mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"plugins": [
"expo-router",
"./plugins/android-respect-rotation-lock.js",
"./plugins/android-desktop-mode.js",
[
"expo-splash-screen",
{
Expand Down
7 changes: 4 additions & 3 deletions mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef } from 'react'
import { View, StyleSheet } from 'react-native'
import { StyleSheet } from 'react-native'
import { Stack, useRouter } from 'expo-router'
import { StatusBar } from 'expo-status-bar'
import * as SplashScreen from 'expo-splash-screen'
Expand All @@ -13,6 +13,7 @@ import { useOpenNotificationRoute } from '../src/notifications/use-open-notifica
import { loadHostCatalog } from '../src/transport/host-store'
import { extractPairingCodeFromUrl } from '../src/transport/pairing'
import { recoverMobileRelayPairing } from '../src/transport/mobile-relay-pairing-recovery'
import { WindowBoundsProvider } from '../src/layout/window-bounds'

// Why: keeps the native splash screen visible until the React tree is mounted
// and ready to render. Without this the user sees a blank white/black frame
Expand Down Expand Up @@ -159,7 +160,7 @@ export default function RootLayout() {

return (
<RpcClientProvider>
<View style={styles.root} onLayout={onNavigatorLayout}>
<WindowBoundsProvider style={styles.root} onLayout={onNavigatorLayout}>
<StatusBar style="light" />
<Stack
screenOptions={{
Expand Down Expand Up @@ -200,7 +201,7 @@ export default function RootLayout() {
<Stack.Screen name="about" options={{ headerShown: false }} />
<Stack.Screen name="h" options={{ headerShown: false }} />
</Stack>
</View>
</WindowBoundsProvider>
</RpcClientProvider>
)
}
Expand Down
111 changes: 56 additions & 55 deletions mobile/app/h/[hostId]/session/[worktreeId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AppState,
Linking,
type AppStateStatus,
BackHandler,
FlatList,
Image,
View,
Expand Down Expand Up @@ -133,6 +132,9 @@ import { isTerminalSendRpcAccepted } from '../../../../src/terminal/terminal-sen
import { sendMobileTerminalQueryReply } from '../../../../src/terminal/mobile-terminal-query-reply'
import { TERMINAL_QUERY_REPLY_INPUT_RUNTIME_CAPABILITY } from '../../../../../src/shared/protocol-version'
import { useTerminalLiveInputCommit } from '../../../../src/terminal/use-terminal-live-input-commit'
import { useHardwareKeyboardAttached } from '../../../../src/platform/hardware-keyboard'
import { useSessionBackHandler } from '../../../../src/session/use-session-back-handler'
import { useTerminalFrameLayout } from '../../../../src/session/use-terminal-frame-layout'
import { resolveMobileTerminalInputGate } from '../../../../src/terminal/terminal-input-connection-gate'
import {
buildTerminalSendParams,
Expand Down Expand Up @@ -897,6 +899,8 @@ export default function SessionScreen() {
)
// Why: Expo SDK 55 edge-to-edge doesn't resize the window on IME open, so track keyboard height ourselves and lift the input without resizing the desktop PTY.
const [keyboardHeight, setKeyboardHeight] = useState(0)
const { hardwareKeyboard, notifyHardwareKeyEvent, notifyImeShown, notifyImeHidden } =
useHardwareKeyboardAttached()
// Why: server-authoritative display mode per terminal, populated from subscribe responses.
const [terminalModes, setTerminalModes] = useState<Map<string, MobileDisplayMode>>(new Map())
const [terminalKeyboardMetrics, setTerminalKeyboardMetrics] = useState<
Expand Down Expand Up @@ -977,6 +981,7 @@ export default function SessionScreen() {
const sendingRef = useRef(false)
// Why: exact terminal-frame height for measureFitDimensions; window.innerHeight can overstate the visible area.
const terminalFrameHeightRef = useRef<number>(0)
const terminalFrameWidthRef = useRef<number>(0)
// Why: sidebar resizes change the terminal frame width without a window-dim change; track it so the refit hook re-fits (see terminal-viewport-refit.ts).
const [terminalFrameWidth, setTerminalFrameWidth] = useState(0)
const activeSessionTab = sessionTabs.find((tab) => tab.id === activeSessionTabId) ?? null
Expand All @@ -997,7 +1002,8 @@ export default function SessionScreen() {
liveInputTerminalHandles,
liveInputTerminalHandlesRef,
sendLiveTerminalInputRef,
setLiveInputCapture
setLiveInputCapture,
onKeyPressObserved: notifyHardwareKeyEvent
})
const { canCompose, canSend } = resolveMobileTerminalInputGate({
connState,
Expand All @@ -1010,6 +1016,7 @@ export default function SessionScreen() {
canSend,
inputRef: liveInputRef,
keyboardHeight,
hardwareKeyboard,
lifecycleIdentity: client,
lifecycleKey: JSON.stringify([hostId, worktreeId, connState]),
liveInputEnabled,
Expand Down Expand Up @@ -1322,7 +1329,8 @@ export default function SessionScreen() {
return
}
const dims = await getTerminalRef(handle)?.measureFitDimensions(
terminalFrameHeightRef.current || undefined
terminalFrameHeightRef.current || undefined,
terminalFrameWidthRef.current || undefined
)
terminalDiagnosticsRef.current.viewportMeasured(handle, dims, terminalFrameHeightRef.current)
if (dims) {
Expand Down Expand Up @@ -2172,43 +2180,15 @@ export default function SessionScreen() {
[markdownDocs, showToast]
)

const getDirtyMarkdownDrafts = useCallback(() => {
const drafts: DirtyMarkdownDraft[] = []
for (const [tabId, doc] of markdownDocs) {
if (doc.status === 'ready' && doc.isDirty) {
const tab = sessionTabs.find((candidate) => candidate.id === tabId)
drafts.push({ tabId, title: tab?.title || 'Markdown', content: doc.localContent })
}
}
return drafts
}, [markdownDocs, sessionTabs])

const leaveSession = useCallback(() => {
if (router.canGoBack()) {
router.back()
return
}
// Why: Android back can fire at the root route; replace avoids React Navigation's dev-only GO_BACK warning.
router.replace(`/h/${hostId}`)
}, [hostId, router])

const requestLeaveSession = useCallback(() => {
const dirtyDrafts = getDirtyMarkdownDrafts()
if (dirtyDrafts.length === 0) {
leaveSession()
return
}
Keyboard.dismiss()
setLeaveDrafts(dirtyDrafts)
}, [getDirtyMarkdownDrafts, leaveSession])

useEffect(() => {
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
requestLeaveSession()
return true
})
return () => subscription.remove()
}, [requestLeaveSession])
const { leaveSession, requestLeaveSession } = useSessionBackHandler({
handleLiveInputKeyPress,
hardwareKeyboard,
hostId,
liveInputRef,
markdownDocs,
sessionTabs,
setLeaveDrafts
})

const discardMarkdownLocalContent = useCallback(
(tab: Extract<MobileSessionTab, { type: 'markdown' }>) => {
Expand Down Expand Up @@ -2559,7 +2539,12 @@ export default function SessionScreen() {
}, [connState, scheduleDelayedAction, subscribeToTerminal, unsubscribeTerminal])

// Why: non-subscribe layout refits (tab strip, fold, rotation) live in a dedicated hook — see terminal-viewport-refit.ts.
const { notifyTerminalFrameHeight, notifyKeyboardVisibility } = useTerminalViewportRefit({
const {
notifyTerminalFrameHeight,
notifyKeyboardVisibility,
notifyHardwareKeyboard,
notifyWebViewViewport
} = useTerminalViewportRefit({
activeHandleRef,
terminalRefs,
terminalFrameHeightRef,
Expand All @@ -2580,10 +2565,13 @@ export default function SessionScreen() {
useEffect(() => {
const onShow = (e: KeyboardEvent) => {
notifyKeyboardVisibility(true)
setKeyboardHeight(e.endCoordinates?.height ?? 0)
const height = e.endCoordinates?.height ?? 0
notifyImeShown(height)
setKeyboardHeight(height)
}
const onHide = () => {
notifyKeyboardVisibility(false)
notifyImeHidden()
setKeyboardHeight(0)
}
const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'
Expand All @@ -2594,7 +2582,22 @@ export default function SessionScreen() {
showSub.remove()
hideSub.remove()
}
}, [notifyKeyboardVisibility])
}, [notifyImeHidden, notifyImeShown, notifyKeyboardVisibility])

useEffect(() => {
if (hardwareKeyboard) {
notifyHardwareKeyboard()
}
}, [hardwareKeyboard, notifyHardwareKeyboard])

const handleTerminalFrameLayout = useTerminalFrameLayout({
terminalRefs,
heightRef: terminalFrameHeightRef,
widthRef: terminalFrameWidthRef,
onHeightChange: notifyTerminalFrameHeight,
onWidthChange: (width) =>
setTerminalFrameWidth((current) => (current === width ? current : width))
})

const scrollActiveTabIntoView = useCallback((tabId: string | null, animated: boolean) => {
if (!tabId) {
Expand Down Expand Up @@ -2953,6 +2956,9 @@ export default function SessionScreen() {
terminalDiagnosticsRef.current.webViewRef(handle, ref != null)
if (ref) {
terminalRefs.current.set(handle, ref)
if (terminalFrameWidthRef.current > 0 && terminalFrameHeightRef.current > 0) {
ref.setViewport(terminalFrameWidthRef.current, terminalFrameHeightRef.current)
}
} else {
terminalRefs.current.delete(handle)
terminalGestureInputBucketsRef.current.delete(handle)
Expand Down Expand Up @@ -4268,7 +4274,7 @@ export default function SessionScreen() {

// Why: iOS keyboard height includes the home-indicator inset; Android IME height does not.
const keyboardLift =
keyboardHeight > 0
!hardwareKeyboard && keyboardHeight > 0
? Platform.OS === 'ios'
? Math.max(0, keyboardHeight - insets.bottom)
: keyboardHeight
Expand Down Expand Up @@ -4717,17 +4723,7 @@ export default function SessionScreen() {
)}
</View>
) : (
<View
style={styles.terminalFrame}
onLayout={(e) => {
terminalFrameHeightRef.current = e.nativeEvent.layout.height
// Why: notify height imperatively so dock settling re-fits the PTY without rerendering SessionScreen.
const nextWidth = Math.round(e.nativeEvent.layout.width)
const nextHeight = Math.round(e.nativeEvent.layout.height)
setTerminalFrameWidth((prev) => (prev === nextWidth ? prev : nextWidth))
notifyTerminalFrameHeight(nextHeight)
}}
>
<View style={styles.terminalFrame} onLayout={handleTerminalFrameLayout}>
{terminals.map((terminal) => (
<TerminalPaneView
key={terminal.handle}
Expand All @@ -4752,6 +4748,11 @@ export default function SessionScreen() {
onTerminalInput={handleTerminalInput}
onTerminalQueryReply={handleTerminalQueryReply}
onTerminalTap={handleTerminalTap}
onViewportChanged={(handle, width, height) => {
if (handle === activeHandleRef.current) {
notifyWebViewViewport(width, height)
}
}}
onFileTap={handleFileTap}
onOpenUrl={handleTerminalOpenUrl}
/>
Expand Down
4 changes: 2 additions & 2 deletions mobile/app/h/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function HostStack({ animation }: { animation: 'none' | 'default' }) {

export default function HostGroupLayout() {
// Wide layout = tablet/foldable canvas (see responsive-layout-metrics).
const { isWideLayout, width: windowWidth } = useResponsiveLayout()
const { windowClass, width: windowWidth } = useResponsiveLayout()
const { hostId, action } = useGlobalSearchParams<{ hostId?: string; action?: string }>()
const pathname = usePathname()
const [sidebarOpen, setSidebarOpen] = useState(true)
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function HostGroupLayout() {
}, [windowWidth])

const hideSidebar = useCallback(() => setSidebarOpen(false), [])
const showSidebar = isWideLayout && !!hostId
const showSidebar = windowClass !== 'compact' && !!hostId
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const detailHasContent = !!hostId && pathname !== `/h/${hostId}`
const canCollapseSidebar = showSidebar && detailHasContent

Expand Down
12 changes: 3 additions & 9 deletions mobile/app/mobile-onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import {
AccessibilityInfo,
Animated,
BackHandler,
Text,
useWindowDimensions,
View
} from 'react-native'
import { AccessibilityInfo, Animated, BackHandler, Text, View } from 'react-native'
import { useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router'
import { SafeAreaView } from 'react-native-safe-area-context'
import { OrcaLogo } from '../src/components/OrcaLogo'
Expand All @@ -23,6 +16,7 @@ import {
type MobileSessionView
} from '../src/storage/session-view-preferences'
import { savePushNotificationsEnabled } from '../src/storage/preferences'
import { useWindowBounds } from '../src/layout/window-bounds'

const SLIDE_DURATION_MS = 280

Expand Down Expand Up @@ -52,7 +46,7 @@ function MobileOnboardingFlow({
}) {
const router = useRouter()
const steps = useMemo(() => parseMobileOnboardingSteps(rawSteps), [rawSteps])
const { width } = useWindowDimensions()
const { width } = useWindowBounds()
const [activeIndex, setActiveIndex] = useState(0)
const [busyChoice, setBusyChoice] = useState<MobileOnboardingBusyChoice>(null)
const [error, setError] = useState<string | null>(null)
Expand Down
Loading