Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/compute/launcher.tsx
Views: 687
/*1Launcher buttons shown for a running compute server.2*/34import { Button, Modal, Spin, Tooltip } from "antd";5import { Icon } from "@cocalc/frontend/components";6import { useImages } from "@cocalc/frontend/compute/images-hook";7import { useMemo, useState } from "react";8import { LauncherButton, getRoute } from "./proxy";9import { useTypedRedux } from "@cocalc/frontend/app-framework";10import ShowError from "@cocalc/frontend/components/error";11import { useServer } from "./compute-server";12import { getApps } from "./menu";1314export default function Launcher({15style,16configuration,17data,18compute_server_id,19project_id,20}) {21const [appName, setAppName] = useState<string>("");22const image = configuration?.image;23if (image == null || data == null || configuration == null) {24return null;25}26const apps = getApps(image);27if (!apps) {28return null;29}30return (31<div style={style}>32{!!appName && (33<AppLauncherModal34id={compute_server_id}35name={appName}36project_id={project_id}37close={() => setAppName("")}38/>39)}40{/*<Button41onClick={() => setAppName("explorer")}42type="text"43size="small"44style={{ color: "#666" }}45>46<Icon name="folder-open" /> Explorer47</Button>*/}4849{apps["jupyterlab"] != null && (50<Tooltip title={apps["jupyterlab"].tip} placement="left">51<Button52onClick={() => setAppName("jupyterlab")}53type="text"54size="small"55style={{ color: "#666" }}56>57<Icon58name={apps["jupyterlab"].icon}59style={{ marginRight: "-5px" }}60/>61JupyterLab62</Button>63</Tooltip>64)}65{apps["vscode"] != null && (66<Tooltip title={apps["vscode"].tip} placement="left">67<Button68onClick={() => setAppName("vscode")}69type="text"70size="small"71style={{ color: "#666" }}72>73<Icon name={apps["vscode"].icon} style={{ marginRight: "-5px" }} />74VS Code75</Button>76</Tooltip>77)}78{apps["xpra"] != null && (79<Tooltip title={apps["xpra"].tip} placement="left">80<Button81onClick={() => setAppName("xpra")}82type="text"83size="small"84style={{ color: "#666" }}85>86<Icon name={apps["xpra"].icon} style={{ marginRight: "-5px" }} />87Desktop88</Button>89</Tooltip>90)}91</div>92);93}9495function AppLauncher({96name,97configuration,98data,99compute_server_id,100project_id,101IMAGES,102}) {103const [error, setError] = useState<string>("");104const compute_servers_dns = useTypedRedux("customize", "compute_servers_dns");105const image = configuration.image;106const app = (IMAGES[image]?.apps ?? IMAGES["defaults"]?.apps ?? [])[name];107if (app == null) {108return <ShowError error={`Unknown application '${name}'`} />;109}110const route = useMemo(() => {111try {112return getRoute({ app, configuration, IMAGES });113} catch (err) {114setError(`${err}`);115return null;116}117}, [app, configuration, IMAGES]);118119return (120<div>121{route && (122<LauncherButton123name={name}124app={app}125compute_server_id={compute_server_id}126project_id={project_id}127configuration={configuration}128data={data}129compute_servers_dns={compute_servers_dns}130setError={setError}131route={route}132noHide133autoLaunch134/>135)}136<ShowError137error={error}138setError={setError}139style={{ margin: "15px 0", width: "100%" }}140/>141</div>142);143}144145// function ExplorerLauncher({ compute_server_id, project_id }) {146// return (147// <div>148// {compute_server_id} {project_id}149// </div>150// );151// }152153export function AppLauncherModal({154name,155id,156project_id,157close,158}: {159name: string;160id: number;161project_id: string;162close: () => void;163}) {164const server = useServer({ id, project_id });165const [IMAGES] = useImages();166if (server == null || IMAGES == null) {167return <Spin />;168}169const image = server.configuration?.image ?? "defaults";170const apps = getApps(image);171172return (173<Modal174title={175<>176<Icon177name={apps[name]?.icon ?? "global"}178style={{ marginRight: "5px" }}179/>180{apps[name]?.label ?? name}181</>182}183open184onOk={close}185onCancel={close}186destroyOnClose187>188{apps[name]?.tip}189<AppLauncher190name={name}191configuration={server.configuration}192data={server.data}193compute_server_id={server.id}194project_id={project_id}195IMAGES={IMAGES}196/>197</Modal>198);199}200201202