import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import useShellAndroid from '@/hooks/shell-android' import { type Adb } from '@yume-chan/adb' import { memo, useEffect, useRef } from 'react' import { type Terminal } from 'xterm' import { FitAddon } from 'xterm-addon-fit' import 'xterm/css/xterm.css' import { useShallow } from 'zustand/react/shallow' interface ShellTabProps { adb: Adb | undefined } export const ShellTab: React.FC = memo(({ adb }) => { const { terminal, startTerminal, killTerminal } = useShellAndroid( useShallow(state => ({ terminal: state.terminal, startTerminal: state.startTerminal, killTerminal: state.killTerminal })) ) return ( Shell Access your device's shell using a terminal emulator
{terminal ? ( ) : ( )}
{terminal ? ( ) : (

No Connection ADB

)}
) }) interface ShellTerminalProps { terminal: Terminal } const ShellTerminal: React.FC = ({ terminal }) => { const shellRef = useRef(null) useEffect(() => { // check if shellRef is have child remove all if (shellRef.current && shellRef.current.children.length > 0) { for (const child of shellRef.current.children) { shellRef.current.removeChild(child) } } if (terminal && shellRef.current) { const addon = new FitAddon() terminal.loadAddon(addon) terminal.open(shellRef.current) addon.fit() } }, [terminal]) return
}