Skip to content

Commit 203e123

Browse files
authored
Merge pull request #104 from consideRatio/pr/small-refactor
refactor: a few smaller details
2 parents bc39ad7 + 7797912 commit 203e123

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

jupyter_remote_desktop_proxy/setup_websockify.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77

88

99
def setup_websockify():
10-
# make a secure temporary directory for sockets
11-
# This is only readable, writeable & searchable by our uid
12-
sockets_dir = tempfile.mkdtemp()
13-
sockets_path = os.path.join(sockets_dir, 'vnc-socket')
1410
vncserver = which('vncserver')
15-
1611
if not vncserver:
1712
raise RuntimeError(
1813
"vncserver executable not found, please install a VNC server"
1914
)
2015

21-
# TigerVNC provides the option to connect a Unix socket. TurboVNC does not.
2216
# TurboVNC and TigerVNC share the same origin and both use a Perl script
2317
# as the executable vncserver. We can determine if vncserver is TigerVNC
2418
# by searching tigervnc string in the Perl script.
@@ -34,11 +28,17 @@ def setup_websockify():
3428
is_tigervnc = "tigervnc" in vncserver_file.read().casefold()
3529

3630
if is_tigervnc:
31+
# Make a secure temporary directory for sockets that is only readable,
32+
# writeable, and searchable by our uid - TigerVNC can listen to a Unix
33+
# socket!
34+
sockets_dir = tempfile.mkdtemp()
35+
sockets_path = os.path.join(sockets_dir, 'vnc-socket')
36+
37+
websockify_args = ['--unix-target', sockets_path]
3738
vnc_args = [vncserver, '-rfbunixpath', sockets_path]
38-
socket_args = ['--unix-target', sockets_path]
3939
else:
40-
vnc_args = [vncserver, '-rfbport', '{port}']
41-
socket_args = []
40+
websockify_args = []
41+
vnc_args = [vncserver, '-localhost', '-rfbport', '{port}']
4242

4343
if not os.path.exists(os.path.expanduser('~/.vnc/xstartup')):
4444
vnc_args.extend(['-xstartup', os.path.join(HERE, 'share/xstartup')])
@@ -47,23 +47,22 @@ def setup_websockify():
4747
vnc_args
4848
+ [
4949
'-verbose',
50+
'-fg',
5051
'-geometry',
5152
'1680x1050',
5253
'-SecurityTypes',
5354
'None',
54-
'-fg',
5555
]
5656
)
5757

5858
return {
5959
'command': [
6060
'websockify',
61-
'-v',
62-
'--heartbeat',
63-
'30',
61+
'--verbose',
62+
'--heartbeat=30',
6463
'{port}',
6564
]
66-
+ socket_args
65+
+ websockify_args
6766
+ ['--', '/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'],
6867
'timeout': 30,
6968
'new_browser_window': True,

0 commit comments

Comments
 (0)