Skip to content

Commit 7d89016

Browse files
committed
Launch a TigerVNC server running a virtual desktop if the container has noVNC installed
Ideally this would permit developing GUI applications, but currently only the xeyes program works. When launching the X server, we use -nolisten local to allow it to coexist with any existing one(s).
1 parent 34110d0 commit 7d89016

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

main.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ const SHUTDOWN_TIMEOUT_S = 90;
1717

1818
const emailToToken: {[_: string]: string} = {};
1919
const tokenToEditor: {[_: string]: Editor} = {};
20+
const nextDisplay = [1];
2021

2122
type Editor = {
22-
port: number,
2323
process: Deno.Process,
24+
port: number,
25+
26+
display: number,
27+
2428
refCount: number,
2529
shutdownHandle?: number,
30+
2631
queryString?: string,
2732
};
2833

@@ -94,6 +99,10 @@ async function handler(request: Request): Promise<Response> {
9499
+ tokenToEditor[vsCodeToken].port
95100
);
96101
else {
102+
let display = nextDisplay.pop()!;
103+
if(!nextDisplay.length)
104+
nextDisplay.push(display + 1);
105+
97106
const process = Deno.run({
98107
cmd: ["chroot/jail", "vscode", "-c", "openvscode-drive", "--port", "0"],
99108
stdin: "piped",
@@ -103,11 +112,13 @@ async function handler(request: Request): Promise<Response> {
103112
process.stdin.write(stdin.encode(tokens.access_token + "\n"));
104113
process.stdin.write(stdin.encode(tokens.refresh_token + "\n"));
105114
process.stdin.write(stdin.encode(expiry.toISOString() + "\n"));
115+
process.stdin.write(stdin.encode(display + "\n"));
106116

107117
const {port, token} = await parsePortAndToken(process.stdout);
108118
tokenToEditor[token] = {
109-
port,
110119
process,
120+
port,
121+
display,
111122
refCount: 0,
112123
};
113124
emailToToken[email] = token;
@@ -140,6 +151,7 @@ function proxy(request: Request, token: string): Promise<Response> {
140151
delete tokenToEditor[token];
141152
editor.process.kill("SIGHUP");
142153
await editor.process.status();
154+
nextDisplay.push(editor.display);
143155
};
144156
const decrRefCount = function() {
145157
--editor.refCount;

plugins/openvscode-drive

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/sh
22

3+
readonly X11_PORT="5900"
4+
readonly VNC_PORT="6080"
5+
36
read access_token
47
read refresh_token
58
read expiry
9+
read display
610
cd
711

812
cat <<-tac >.rclone.conf
@@ -22,4 +26,12 @@ do
2226
done
2327
cd
2428

29+
if which novnc_proxy >/dev/null
30+
then
31+
Xvnc -SecurityTypes None -localhost -nolisten local ":$display" &
32+
novnc_proxy --vnc ":$((X11_PORT + display))" --listen $((VNC_PORT + display)) &
33+
34+
export DISPLAY=":$display"
35+
fi
36+
2537
exec unshare -U openvscode-server "$@"

0 commit comments

Comments
 (0)