-
-
Save nightuser/2ec1b91a66ec33ef0a0a67b6c570eb40 to your computer and use it in GitHub Desktop.
Add an option to use the existing Xorg session with | |
chrome-remote-desktop. | |
The original idea of the patch: https://superuser.com/a/850359 | |
--- a/chrome-remote-desktop 2024-03-27 16:03:20.518579015 +0000 | |
+++ b/chrome-remote-desktop 2024-03-27 16:17:58.241912847 +0000 | |
@@ -110,6 +110,8 @@ | |
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock" | |
FIRST_X_DISPLAY_NUMBER = 20 | |
+EXISTING_X_DISPLAY_FILE_PATH = os.path.join(CONFIG_DIR, "Xsession") | |
+X_SESSION_FILE_TEMPLATE = "/tmp/.X11-unix/X%d" | |
# Amount of time to wait between relaunching processes. | |
SHORT_BACKOFF_TIME = 5 | |
@@ -738,16 +740,33 @@ | |
return True | |
return False | |
+ def _use_existing_session(self): | |
+ with open(EXISTING_X_DISPLAY_FILE_PATH) as fh: | |
+ try: | |
+ display_raw = fh.readline().rstrip() | |
+ display = int(display_raw) | |
+ except ValueError: | |
+ logging.error("Display must be a number; got: '%s'" % display_raw) | |
+ sys.exit(1) | |
+ if not os.path.exists(X_SESSION_FILE_TEMPLATE % display): | |
+ logging.error("Xorg session file doesn't exist") | |
+ sys.exit(1) | |
+ logging.info("Using existing Xorg session: %d" % display) | |
+ self.child_env["DISPLAY"] = ":%d" % display | |
+ | |
def launch_session(self, server_args, backoff_time): | |
"""Launches process required for session and records the backoff time | |
for inhibitors so that process restarts are not attempted again until | |
that time has passed.""" | |
logging.info("Setting up and launching session") | |
self._setup_gnubby() | |
- self._launch_server(server_args) | |
- if not self._launch_pre_session(): | |
- # If there was no pre-session script, launch the session immediately. | |
- self.launch_desktop_session() | |
+ if os.path.exists(EXISTING_X_DISPLAY_FILE_PATH): | |
+ self._use_existing_session() | |
+ else: | |
+ self._launch_server(server_args) | |
+ if not self._launch_pre_session(): | |
+ # If there was no pre-session script, launch the session immediately. | |
+ self.launch_desktop_session() | |
self.server_inhibitor.record_started(MINIMUM_PROCESS_LIFETIME, | |
backoff_time) | |
self.session_inhibitor.record_started(MINIMUM_PROCESS_LIFETIME, |
Hello, this has not worked for me. I tried applying the patch by manually replacing the lines as well and it seems the original file has changed. The function
def launch_session
is no longer around line 774, but around line 519. Even then I was not able to get this working. Could you update the patch please?The console output was:
can't find file to patch at input line 4 Perhaps you used the wrong -p or --strip option?
and then
File to patch: /opt/google/chrome-remote-desktop/chrome-remote-desktop patching file /opt/google/chrome-remote-desktop/chrome-remote-desktop Hunk #1 succeeded at 109 (offset 2 lines). Hunk #2 FAILED at 776. 1 out of 2 hunks FAILED -- saving rejects to file /opt/google/chrome-remote-desktop/chrome-remote-desktop.rej
For those of you who ran into this issue you need to delete the first 4 lines of the patch (the plain text).
Here is a one-liner to do everything:
cd /opt/google/chrome-remote-desktop && sudo cp chrome-remote-desktop chrome-remote-desktop_bak && wget -qO- "https://gist.githubusercontent.com/nightuser/2ec1b91a66ec33ef0a0a67b6c570eb40/raw/b09250dcc9a28f09de93192a948dffb4963c2aca/use_existing_session.patch" | tail -n +5 > use_existing_session.patch && sudo patch -Np1 -i ./use_existing_session.patch && systemctl --user restart chrome-remote-desktop.service
Sorry, I don’t have any desktop Linux machines, so I can’t update (and test) the patch at the moment.
Updated the patch. Works for me on Ubuntu 22.04 in a virtual machine. The sound didn’t work, probably because the pipewire version is too old (there’s a check in the code). It’s not clear whether the setup_audio
is being called at the moment, but it looks like it should.
this patch is my hero. CRD breaks all the time and just running
fixes it like magic.
version: 121.0.6167.13