-
Notifications
You must be signed in to change notification settings - Fork 9
/
__init__.py
103 lines (80 loc) · 2.89 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import logging
logger = logging.getLogger(__name__)
logger.setLevel('INFO')
HERE = os.path.dirname(os.path.abspath(__file__))
def get_xpra_executable(prog):
from shutil import which
# Find prog in known locations
other_paths = [
os.path.join('/opt/xpra/bin', prog),
]
wp = os.path.join(HERE, 'bin', prog)
if os.path.exists(wp):
return wp
if which(prog):
return prog
for op in other_paths:
if os.path.exists(op):
return op
if os.getenv("XPRA_BIN") is not None:
return os.getenv("XPRA_BIN")
raise FileNotFoundError(f'Could not find {prog} in PATH')
def _xprahtml5_urlparams():
url_params = '?sharing=true'
return url_params
def _xprahtml5_mappath(path):
# always pass the url parameter
if path in ('/', '/index.html', ):
url_params = _xprahtml5_urlparams()
path = '/index.html' + url_params
return path
def setup_xprahtml5():
""" Setup commands and and return a dictionary compatible
with jupyter-server-proxy.
"""
from tempfile import mkdtemp
# ensure a known secure sockets directory exists, as /run/user/$UID might not be available
socket_path = mkdtemp(prefix='xpra_sockets_' + str(os.getuid()) + '_')
logger.info('Created secure socket directory for Xpra: ' + socket_path)
# launchers url file including url parameters
path_info = 'xprahtml5/index.html' + _xprahtml5_urlparams()
# create command
cmd = [
get_xpra_executable('xpra'),
'start',
'--html=on',
'--bind={unix_socket},auth=none', # using sockets + jupyter-server-proxy => auth is not needed here
'--socket-dir=' + socket_path,
'--start=xterm -fa "DejaVu Sans Mono" -fs 14',
'--clipboard-direction=both',
'--no-keyboard-sync', # prevent keys from repeating unexpectedly on high latency
'--no-mdns', # do not advertise the xpra session on the local network
'--no-bell',
'--no-speaker',
'--no-printing',
'--no-microphone',
'--no-notifications',
# '--dbus-control=no',
'--no-systemd-run', # do not delegated start-cmd to the system wide proxy server instance
'--sharing', # this allows to open the desktop in multiple browsers at the same time
'--no-daemon', # mandatory
]
logger.info('Xpra command: ' + ' '.join(cmd))
return {
'environment': {
'XDG_RUNTIME_DIR': socket_path,
},
'command': cmd,
'unix_socket': socket_path + '/xpra-server',
'mappath': _xprahtml5_mappath,
'absolute_url': False,
'timeout': 90,
'new_browser_tab': True,
'launcher_entry': {
'enabled': True,
'icon_path': os.path.join(HERE, 'icons/xpra-logo.svg'),
'title': 'Xpra Desktop',
'path_info': path_info,
},
}