import * as React from "react" import { Application, isExecutableApplication, isRunningApplication } from "../../common/api" import { HttpError } from "../../common/http" import { getSession, killSession } from "../api" import { RequestError } from "../components/error" export const AppDetails: React.FunctionComponent = (props) => { return ( <> {props.icon ? ( ) : (
)}
{props.name}
) } export interface AppRowProps { readonly app: Application onKilled(app: Application): void open(app: Application): void } export const AppRow: React.FunctionComponent = (props) => { const [killing, setKilling] = React.useState(false) const [error, setError] = React.useState() function kill(): void { if (isRunningApplication(props.app)) { setKilling(true) killSession(props.app) .then(() => { setKilling(false) props.onKilled(props.app) }) .catch((error) => { setError(error) setKilling(false) }) } } return (
{isRunningApplication(props.app) && !killing ? ( ) : ( undefined )}
) } export interface AppListProps { readonly header: string readonly apps?: ReadonlyArray open(app: Application): void onKilled(app: Application): void } export const AppList: React.FunctionComponent = (props) => { return (

{props.header}

{props.apps && props.apps.length > 0 ? ( props.apps.map((app, i) => ) ) : props.apps ? ( ) : (
loading...
)}
) } export interface ApplicationSection { readonly apps?: ReadonlyArray readonly header: string } export interface AppLoaderProps { readonly app?: Application setApp(app?: Application): void getApps(): Promise> } /** * Display provided applications or sessions and allow opening them. */ export const AppLoader: React.FunctionComponent = (props) => { const [apps, setApps] = React.useState>() const [error, setError] = React.useState() const refresh = (): void => { props .getApps() .then(setApps) .catch((e) => setError(e.message)) } React.useEffect(() => { refresh() }, [props]) function open(app: Application): void { props.setApp(app) if (!isRunningApplication(app) && isExecutableApplication(app)) { getSession(app) .then((session) => { props.setApp({ ...app, ...session }) }) .catch(setError) } } if (error) { props.setApp(undefined) return ( { setError(undefined) }} /> ) } if (props.app && !props.app.loaded) { return (
Opening
) } if (!apps) { return (
loading
) } return ( <> {apps.map((section, i) => ( ))} ) }