Skip to content

Commit

Permalink
feat: add two functions about copy and paste (#494)
Browse files Browse the repository at this point in the history
* feat: add two functions
    1. copy from selenoid clipboard to local
    2. paste to selenoid from local clipboard

* feat: add two functions
    1. copy from selenoid clipboard to local
    2. paste to selenoid from local clipboard

* feat: add two functions
    1. copy from selenoid clipboard to local
    2. paste to selenoid from local clipboard

* feat: add two functions
    1. copy from selenoid clipboard to local
    2. paste to selenoid from local clipboard

* feat: add two functions
    1. copy from selenoid clipboard to local
    2. paste to selenoid from local clipboard
  • Loading branch information
kaylezhangzhaoLin authored Oct 10, 2022
1 parent 196d640 commit be94f72
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
62 changes: 58 additions & 4 deletions ui/src/components/VncCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Link } from "react-router-dom";

import VncScreen from "./VncScreen";
import { StyledVNC } from "./style.css";
import { ajax } from "rxjs/ajax";

export default class VncCard extends Component {
state = { connection: "connecting" };

connection = connection => {
connection = (connection) => {
this.setState({ connection: connection });
};

Expand Down Expand Up @@ -38,16 +39,32 @@ export default class VncCard extends Component {
<Connection connection={connection} />
{connected && <Lock locked={!unlocked} handleLock={this.handleLock} />}
{connected && <Fullscreen handleFullscreen={this.handleFullscreen} fullscreen={fullscreen} />}
{connected && (
<Clipboard
upload={copyFromDocker}
session={session}
title={"copyFromSelenoid"}
operator={"copy"}
/>
)}
{connected && (
<Clipboard
upload={pasteToDocker}
session={session}
title={"pasteToSelenoid"}
operator={"upload"}
/>
)}
</div>

<div className="vnc-card__content">
<VncScreen
ref={instance => {
ref={(instance) => {
this.screen = instance;
}}
session={session}
origin={origin}
onUpdateState={state => this.connection(state)}
onUpdateState={(state) => this.connection(state)}
/>
</div>
</div>
Expand All @@ -59,6 +76,34 @@ export default class VncCard extends Component {
);
}
}
function copyFromDocker(sessionId) {
const request = {
url: "/clipboard/" + sessionId,
method: "GET",
async: false,
responseType: "text",
};
ajax(request).subscribe((x) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(x.response);
}
});
}

function pasteToDocker(sessionId) {
if (navigator.clipboard) {
navigator.clipboard.readText().then((text) => {
let request = {
url: "/clipboard/" + sessionId,
method: "POST",
body: text,
async: false,
headers: { "Content-Type": "application/x-www-form-urlencoded" },
};
ajax(request).subscribe((msg) => msg);
});
}
}

function Back() {
return (
Expand All @@ -70,7 +115,7 @@ function Back() {

function Connection(props) {
const { connection } = props;
const icon = function(connection) {
const icon = function (connection) {
switch (connection) {
default:
case "disconnected": {
Expand Down Expand Up @@ -99,6 +144,15 @@ function Fullscreen(props) {
);
}

function Clipboard(props) {
const { upload, session, title, operator } = props;
return (
<div className={`control control_${operator}`}>
<div title={title} className={"icon dripicons-" + operator} onClick={() => upload(session)}></div>
</div>
);
}

function Lock(props) {
const { locked, handleLock } = props;
return (
Expand Down
23 changes: 23 additions & 0 deletions ui/src/components/VncCard/style.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const colorConnecting = "#6883d3";
const colorDisconnecting = " #ca9eff";
const colorFullscreen = "#59a781";
const backgroundColorLighter = "#3d444c";
const copyAndPaste = "#405048";

export const StyledVNC = styled.div`
display: flex;
Expand Down Expand Up @@ -146,6 +147,28 @@ export const StyledVNC = styled.div`
&_disconnecting {
background-color: ${colorDisconnecting};
}
&_copy {
cursor: pointer;
background-color: ${copyAndPaste};
color: ${colorFullscreen};
margin-left: auto;
&:hover {
color: #fff;
}
}
&_upload {
cursor: pointer;
background-color: ${copyAndPaste};
color: ${colorFullscreen};
margin-right: 10px;
&:hover {
color: #fff;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function (app) {
agent: agent,
})
);
app.use(createProxyMiddleware("/clipboard", { target: "http://localhost:4444" }));
app.use(createProxyMiddleware("/status", { target: "http://localhost:8080" }));
app.use(createProxyMiddleware("/video/", { target: "http://localhost:8080" }));
app.use(createProxyMiddleware("/wd/hub/", { target: "http://localhost:8080" }));
Expand Down

0 comments on commit be94f72

Please sign in to comment.