-
-
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, |
@dmmat: The password? Did you set up the headless mode? The basic instructions can be found on the AUR page or see this blog post.
i mean password for local user
@VSMent: You should apply it to
chrome-remote-desktop
Python script located in the chrome remote desktop install directory (usually somewhere in/opt
). Then create a file namedXsession
in the configuration directory of CRD with the number of the X session (usually 0 or 1, see $DISPLAY env variable in your shell, place the number without:
prefix).
When you say apply, do you just append it?
@Prometheus720: Patches are usually applied with the patch
command. See this reply above for instructions.
@dmmat: Sorry for disappearing. Did you figure it out? I don't understand why it requires a password. Did you perhaps run it with sudo instead of as a normal user?
@nightuser run as normal, but system ask the root password =(
@dmmat: I don't know why it happens. I found this, bit it looks bizarre. But you may try \systemctl
instead of systemctl
(the backslash runs the original command even if it's shadowed by an alias).
Also, when you restart the service with systemctl --user restart chrome-remote-desktop.service
can you check which user runs CRD? You can check with ps aux
(the first column contains a user and the last one a command itself).
If it fails, perhaps try asking at stackexchange.
@nightuser @dmmat I can confirm the patch worked for me yesterday with CRD v92.0.4515.41-1 on Manjaro KDE and chrome-remote-desktop show expected behavior
I fresh installed CRD, then configured it headless and ran it from my phone (showed new blank Xorg session) then applied patch with patch
command (from /opt/google/chrome-remote-desktop
sudo patch -Np1 -i ~/use_existing_session.patch
), then added a file Xsession
with only a 0
in it to ~/.config/chrome-remote-desktop
and finally reconnected trough my phone to see my current Xorg session!
Thanks a lot for this patch btw ;)
@nightuser, thank you for this patch. I wonder what prevents almighty Google from implementing such a useful feature in the first place.
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
@LeaT113 Hi. I've updated the patch and it works now. If it still didn't work, make sure that you're using X11 (Wayland is not supported) and then follow the steps from this postβor just do a normal install with crd --setup
if you haven't used CRD previously.
Hi guys, was attempting this patch but got the following output. Any ideas?
patching file chrome-remote-desktop
patch unexpectedly ends in middle of line
Hunk #3 succeeded at 543 with fuzz 1.
edit:
Although the patch command seems to fail, the code changes were applied successfully but it still doesn't work afterwards.
what fixed it for me was the following (Debian 11):
FIRST_X_DISPLAY_NUMBER = 0
echo "0" > ~/.config/chrome-remote-desktop/Xsession
systemctl restart chrome-remote-desktop@"your_user".service
However, my remote session seems to be missing some privileges and I can't run certain applications..
@nightuser I would like to thank you for the patch, I am now able to resume the same session when using chrome remote desktop, but 1 question, since I have 2 monitors connected, but I see 2 different resolutions when remote, how can I configure to use both screens with resolution 1920x1080? thanks again
Hi guys, was attempting this patch but got the following output. Any ideas?
patching file chrome-remote-desktop patch unexpectedly ends in middle of line Hunk #3 succeeded at 543 with fuzz 1.
edit: Although the patch command seems to fail, the code changes were applied successfully but it still doesn't work afterwards. what fixed it for me was the following (Debian 11):
FIRST_X_DISPLAY_NUMBER = 0 echo "0" > ~/.config/chrome-remote-desktop/Xsession systemctl restart chrome-remote-desktop@"your_user".service
However, my remote session seems to be missing some privileges and I can't run certain applications..
I encountered the same error as yours, I ended up manually patching the file myself without running the command
It seems this is needed on Manjaro when using xfce4 as window manager. Whenever I try to use a version that starts a new xserver, crd stops after a minute saying it cannot open or connect to Xorg.
Does Manjaro constrain Xwindows to open just one desktop?
Updated the gist.
@tokland: you can simplify things:
cd /opt/google/chrome-remote-desktop sudo cp chrome-remote-desktop chrome-remote-desktop_bak # backup the original sudo patch -Np1 -i /path/to/use_existing_session.patch systemctl --user restart chrome-remote-desktop.serviceYou don't have to stop the service and you can patch the file inplace.
Hello!
I am currently trying to get this to work on the steamdeck, but despite followig these instructions I am not getting it work unfortunately.
Is it possible to get it working currently or am I out of luck?
this patch is my hero. CRD breaks all the time and just running
cd /opt/google/chrome-remote-desktop
sudo cp chrome-remote-desktop chrome-remote-desktop_bak # backup the original
sudo patch -Np1 -i /path/to/use_existing_session.patch
systemctl --user restart chrome-remote-desktop.service
fixes it like magic.
version: 121.0.6167.13
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.
@nightuser setup_audio doesn't seem to be called
It is invalid
Below is the one-liner from @mike-callahan post and individual commands, modified to create the Xsession
file as well. I tested it on Arch Linux with chrome-remote-desktop
version 128.0.6613.44
and it worked.
@jack9603301 Audio doesn't work for me either.
echo $DISPLAY | tr -d ':' >> ~/.config/chrome-remote-desktop/Xsession && cd /opt/google/chrome-remote-desktop && sudo cp chrome-remote-desktop chrome-remote-desktop_bak && sudo 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 && rm ~/use_existing_session.patch && systemctl --user restart chrome-remote-desktop.service && systemctl --user status chrome-remote-desktop.service
echo $DISPLAY | tr -d ':' >> ~/.config/chrome-remote-desktop/Xsession && cd /opt/google/chrome-remote-desktop
sudo cp chrome-remote-desktop chrome-remote-desktop_bak
sudo 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
rm ~/use_existing_session.patch
systemctl --user restart chrome-remote-desktop.service
systemctl --user status chrome-remote-desktop.service
I already had the host configured before applying the patch and for some reason it no longer appeared in https://remotedesktop.google.com/access. I had to do again the entire process from https://remotedesktop.google.com/headless
Below is the one-liner from @mike-callahan post and individual commands, modified to create the
Xsession
file as well. I tested it on Arch Linux withchrome-remote-desktop
version128.0.6613.44
and it worked.@jack9603301 Audio doesn't work for me either.
echo $DISPLAY | tr -d ':' >> ~/.config/chrome-remote-desktop/Xsession && cd /opt/google/chrome-remote-desktop && sudo cp chrome-remote-desktop chrome-remote-desktop_bak && sudo 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 && rm ~/use_existing_session.patch && systemctl --user restart chrome-remote-desktop.service && systemctl --user status chrome-remote-desktop.serviceecho $DISPLAY | tr -d ':' >> ~/.config/chrome-remote-desktop/Xsession && cd /opt/google/chrome-remote-desktop sudo cp chrome-remote-desktop chrome-remote-desktop_bak sudo 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 rm ~/use_existing_session.patch systemctl --user restart chrome-remote-desktop.service systemctl --user status chrome-remote-desktop.serviceI already had the host configured before applying the patch and for some reason it no longer appeared in https://remotedesktop.google.com/access. I had to do again the entire process from https://remotedesktop.google.com/headless
This worked for me (Linux Mint 22, version 129.0.6668.14
) with some tweaks.
I had issues with chrome-remote-desktop
erroring out, which I solved by changing ~/.config/chrome-remote-desktop/Xsession
's contents to be 0
instead of 0.0
. I also had to run the systemctl
commands without --user
and appending @$USER
to the commands, so the last two commands became the following:
systemctl restart chrome-remote-desktop@$USER.service
systemctl status chrome-remote-desktop@$USER.service
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
I wonder if it is possible for a similar fix under wayland, given that without the patch you can use remote desktop without issue... albeit still under a different session. :p
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
that isn't me!! that was from the quote
but yeah, that almost got me, @SitramSoft might wanna edit both the one liner and individual commands π
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
that isn't me!! that was from the quote but yeah, that almost got me, @SitramSoft might wanna edit both the one liner and individual commands π
π± Thanks for pointing out that mistake. It should be fixed now in both places.
I hope nobody deleted their home directory with that command π
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
that isn't me!! that was from the quote but yeah, that almost got me, @SitramSoft might wanna edit both the one liner and individual commands π
it's still in your quote reply. the sloppy readers like me will totally copypasta themselves into doom.
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
that isn't me!! that was from the quote but yeah, that almost got me, @SitramSoft might wanna edit both the one liner and individual commands π
it's still in your quote reply. the sloppy readers like me will totally copypasta themselves into doom.
fixed also
@JovannMC I hope you are aware of the rm ~/ bomb in that one liner of yours.
that isn't me!! that was from the quote but yeah, that almost got me, @SitramSoft might wanna edit both the one liner and individual commands π
π± Thanks for pointing out that mistake. It should be fixed now in both places.
I hope nobody deleted their home directory with that command π
iirc for me it tried to but didn't really do anything (esp since it didnt have -rf
thankfully)
FYI @JovannMC the gist referenced in your expanded one liner is from 2022. It's not the current patch.
@dmmat: The password? Did you set up the headless mode? The basic instructions can be found on the AUR page or see this blog post.