Skip to content
Open
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
100 changes: 82 additions & 18 deletions packages/manager/src/features/Lish/Glish.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, CircleProgress, ErrorState } from '@linode/ui';
import { Box, Button, CircleProgress, ErrorState } from '@linode/ui';
import { styled } from '@mui/material/styles';
import * as React from 'react';
import { VncScreen } from 'react-vnc';
import type { VncScreenHandle } from 'react-vnc';
Expand All @@ -13,6 +14,13 @@

let monitor: WebSocket;

// RFB key codes for Ctrl+Alt+Delete
const KEY_CODES = {
ctrl: 0xffe3,
alt: 0xffe9,
del: 0xffff,
};

const Glish = (props: Props) => {
const { glish_url, linode, monitor_url, refreshToken, ws_protocols } = props;
const ref = React.useRef<VncScreenHandle>(null);
Expand Down Expand Up @@ -111,26 +119,52 @@
const rfbOptions = { wsProtocols: ws_protocols };

return (
<VncScreen
autoConnect={false}
loadingUI={
<Box p={8} position="absolute" top="0" width="100%">
<CircleProgress />
</Box>
}
ref={ref}
rfbOptions={rfbOptions}
scaleViewport
showDotCursor
style={{
height: 'calc(100vh - 60px)',
padding: 8,
}}
url={glish_url}
/>
<div>
<ButtonContainer>
<StyledButton onClick={() => sendCtrlAltDel(ref)} variant="outlined">
Send Ctrl+Alt+Del
</StyledButton>
</ButtonContainer>
<VncScreen
autoConnect={false}
loadingUI={
<Box p={8} position="absolute" top="0" width="100%">
<CircleProgress />
</Box>
}
ref={ref}
rfbOptions={rfbOptions}
scaleViewport
showDotCursor
style={{
height: 'calc(100vh - 110px)',
padding: 8,
}}
url={glish_url}
/>
</div>
);
};

const ButtonContainer = styled('div')(({ theme }) => ({
display: 'flex',
justifyContent: 'flex-end',
padding: theme.spacing(1),

Check warning on line 152 in packages/manager/src/features/Lish/Glish.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Use of theme.spacing() method is deprecated. Use theme.spacingFunction instead. See: https://linode.github.io/manager/development-guide/16-design-tokens.html#spacing Raw Output: {"ruleId":"@linode/cloud-manager/no-mui-theme-spacing","severity":1,"message":"Use of theme.spacing() method is deprecated. Use theme.spacingFunction instead. See: https://linode.github.io/manager/development-guide/16-design-tokens.html#spacing","line":152,"column":12,"nodeType":"CallExpression","messageId":"themeSpacingMethodUsage","endLine":152,"endColumn":28}
position: 'absolute',
right: 0,
bottom: 0,
zIndex: 5,
}));

const StyledButton = styled(Button)(({ theme }) => ({
backgroundColor: theme.palette.primary.main,
color: theme.name === 'light' ? theme.color.white : theme.color.black,
fontSize: 13,
'&:hover': {
backgroundColor: theme.palette.primary.light,
},
}));

export default Glish;

/**
Expand Down Expand Up @@ -197,3 +231,33 @@
sendString(contents.slice(1), ref);
}, delay);
};

/**
* Sends Ctrl+Alt+Delete key combination via RFB.
*/
const sendCtrlAltDel = (ref: React.RefObject<null | VncScreenHandle>) => {
if (
!ref.current?.rfb ||
ref.current.rfb._rfbConnectionState !== 'connected'
) {
return;
}

// Press Ctrl
ref.current.rfb.sendKey(KEY_CODES.ctrl, undefined, true);
// Press Alt
ref.current.rfb.sendKey(KEY_CODES.alt, undefined, true);
// Press Delete (with modifiers held)
ref.current.rfb.sendKey(KEY_CODES.del, undefined, true);

// Release in reverse order
setTimeout(() => {
ref.current?.rfb?.sendKey(KEY_CODES.del, undefined, false);
}, 10);
setTimeout(() => {
ref.current?.rfb?.sendKey(KEY_CODES.alt, undefined, false);
}, 20);
setTimeout(() => {
ref.current?.rfb?.sendKey(KEY_CODES.ctrl, undefined, false);
}, 30);
};
Loading