Repository navigation
fix(desktop): honest start, supervised processes and install progress for the Virtual Desktop - #37
Merged
Merged
Conversation
…n start linxr-desktop start used to report success once websockify listened on 6080 and any recorded pid was alive, so it could return success with x11vnc or the window manager dead, and the viewer then failed with no reason given (#26). - One supervisor owns Xvfb, D-Bus, the window manager, panel, x11vnc and websockify, restarts any of them that exits (5 times in 10 minutes) and ends the session cleanly when Xvfb dies. State and pids live in /run/linxr-desktop, logs in /var/log/linxr-desktop. - start waits until Xvfb has opened :1, the WM runs, x11vnc listens on 5900 and websockify on 6080, or fails naming the component with its last log lines. start, stop and restart are idempotent; settings are saved in /etc/linxr/desktop.conf so Start works after a VM reboot. - app launches only allow-listed apps (no eval); JSON output is escaped. - install logs apk progress, waits for the apk lock instead of killing apk, fixes a repository branch that does not match the image, checks free space, and adds galculator, dbus-x11 and xsetroot. - x11vnc: -noncache -noxrecord -nowf -noscr -xkb.
- /desktop/start validates the resolution and environment, serialises starts, and returns 200 only when every component is up; otherwise it returns the guest's error (409 for not installed or busy, 500 for a failed component, 504 on a hung script) with the status fields. - /desktop/install starts the install in the background and returns 202; /desktop/status reports install_state, install_progress, install_step and install_error, so a long XFCE install no longer hits the 600 s timeout and failures are not reported as success. - /desktop/status reads the supervisor's state files: running means the processes are alive (not zombies) and ports 5900 and 6080 listen. - New GET /desktop/log (token required) returns one component log or a combined summary. - /desktop/app rejects anything outside the allow-list.
- The Desktop screen shows why a start or install failed, with a "View desktop log" dialog, and also shows failures recorded by the guest (for example Xvfb exited while the app was in the background). - Installing shows apk's progress and a progress bar by polling the status; the start only reports success when the guest says running. - The viewer opens 127.0.0.1 (the port forward is IPv4 only) with reconnect_delay, after checking the desktop is up; status is refreshed when the app returns to the foreground. - "Fit this screen" resolution from the device aspect ratio. - Calculator button sent "calc"; it now sends "calculator". - Touch tips describe noVNC's real gestures and the on-screen keyboard. - Kotlin: desktop calls surface the API's "detail" message, start uses a 330 s read timeout, new getDesktopLog channel method, and custom port forwards can no longer take host ports 2222, 7081, 6080 or 5900.
The Home screen's Start Desktop button always started 1280x720 Openbox, even when the user had set up XFCE only; the old launcher then silently began installing Openbox. It now uses the resolution and environment of the last session and shows the guest's reason, with a Details action that opens the Desktop screen, when the start fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR comes from an end-to-end review of the Linux desktop: the guest launcher, the VM API, the Kotlin bridge and the Flutter screens. The main problem was that "Start" could report success while the desktop was not usable, and nothing told the user why. That matches #26.
After this PR:
Refs #26. It is not marked as fixed because the reporter's underlying failure can't be confirmed without a device. After this PR the app shows the reason instead of a false success. See "Relation to #26" below.
What was wrong or incomplete
Guest launcher (
android/app/src/main/assets/bootstrap/linxr-desktop.sh)is_runningreturned true if any recorded pid was alive.cmd_startwaited only for that and for port 6080._get_desktop_statusinapi_server.pyused the same weak rule: the X socket plus port 6080, or any pid alive.&and never checked again. A crashed x11vnc, websockify, Openbox or tint2 stayed down while the status still said "running".eval "$APP". Any app id that was not one of the known four was passed toevalas root (/desktop/app). The app's Calculator button sentcalc, which matched none of the cases, so it went toeval calcand did nothing. No calculator was installed either.killall -9 apk; rm -f /lib/apk/db/lock, which kills the boot-time bootstrap'sapk add(podman and others) mid-transaction.apk updateerrors were thrown away._installDesktopshowed "installed successfully" whatever the reply said.main,init_bootstrap.shwritesv3.20repositories into Alpine 3.24 images, so the desktop install can mix branches and fail to resolve dependencies. fix: code review fixes for disk resize, dockerd, k3s, recipes, API and VM lifecycle #34 fixes the bootstrap, and this PR adds a guard in the installer./tmp, which is tmpfs. After a VM reboot the desktop came back at the defaults.xfwm4.xmlwas written twice.eval $(dbus-launch), and its daemon was never stopped.rfind("{").VM API (
api_server.py)/desktop/starterrors were unreadable in the app. Failures did return 500, but the Kotlin client threw the raw JSON body cut to 300 characters (VmApiClient.kt), so the app showedPlatformException(..., {"detail": ....App
lib/main.dart,_VirtualDesktopCard). It always started 1280×720 Openbox. If the user had set up XFCE only, the old launcher silently started installing Openbox inside the start call. This is a likely path for [bug] Virtual Desktop (GUI) #26.VmState.startDesktoptreatedstatus == 'started'as running.localhost, but the QEMU forward listens on IPv4127.0.0.1only.reconnect_delay.(custom + builtin).distinctBy { it.host }let a custom forward on the same host port silently replace them. The same applied to SSH 2222 and the API 7081.Performance under TCG (reviewed)
Openbox stays the default, which is right for TCG. XFCE keeps
xfwm4 --compositor=off.x11vnc:
-noxdamage -wait 50 -defer 50are kept from c5bed9e.-noncache: noVNC cannot use x11vnc's client-side cache.-noxrecord -nowf -noscr: these skip the XRECORD scroll detection and wireframing, which cost CPU.-xkb: symbols typed on the phone keyboard map to the right keys.-nobell.websockify race: c5bed9e made start wait for port 6080. What was left:
All three are now handled. The numpy and Python 3.14
unix_listenpatches are kept unchanged. On Alpine 3.24 (websockify 0.13.0)import numpysits insidetry, so the numpy patch is safe.What changed
linxr-desktop.sh(rewritten, same commands and ports):One supervisor owns the desktop. A
_superviseprocess owns Xvfb:1, D-Bus, the WM, the panel, xfdesktop/xfsettingsd, x11vnc:5900and websockify:6080./run/linxr-desktop, and logs in/var/log/linxr-desktop/. Both are tmpfs./etc/linxr/desktop.conf, which survives reboots.startchecks every part before it returns. It returns only when::1;Otherwise it fails, names the component and includes its last log lines. Nothing is left half-running.
stopandrestartcan be repeated. Exit codes: 2 bad argument, 3 not installed, 4 not running, 75 busy.apponly takesterminal,files,editororcalculator. Nothing from the request is executed.install:apk --wait 600) instead of killing apk;Packages added:
galculator,dbus/dbus-x11andxsetrootfor Openbox. Fonts (font-dejavu, plusfont-notofor XFCE) and a terminal (xterm, xfce4-terminal) were already there.Config files:
linxr-desktop:managedmarker and are only rewritten while the marker is still there. A file the user edited, or that xfconfd rewrote, is left alone.api_server.py:/desktop/start:/desktop/installruns in the background and returns 202./desktop/statusaddsinstall_state,install_progress(37/199),install_stepandinstall_error./desktop/statusreads the supervisor's files. It also returnsstate(running, degraded, starting, failed or stopped), a flag per component, the two port checks,errorandfailed_component.GET /desktop/log?name=all|<component>&lines=Nis new. It needs the token./desktop/apprejects ids that are not on the allow-list.Kotlin:
detailmessage./desktop/startgets a 330 s read timeout.getDesktopLogchannel method.addPortForwardrefuses them.Flutter:
http://127.0.0.1:<web_port>/vnc.html?autoconnect=true&resize=scale&reconnect=true&reconnect_delay=2000&show_dot=true&path=websockifycalc.CHANGELOG.md: Unreleased entry.Mobile usability: what is and isn't covered
resize=scale.resize=remotewould do nothing, because x11vnc cannot resize the Xvfb screen.reconnect=truewith a 2 s delay.Relation to #34
Based on
main, as requested. #34 changesinit_bootstrap.sh,_build_rootfs.sh,api_server.pyand the VM lifecycle. This PR keeps out of those hunks:init_bootstrap.shand_build_rootfs.share not touched.api_server.py: only the desktop helper block, the desktop POST handlers, and a new route just beforedo_GET's final 404 are changed. No new top-level imports.import timeat module level.timeinside a module-level helper, so it doesn't shadowtimeinsidedo_POST.VmManager.kt,MainActivity.kt,VmApiClient.kt,vm_platform.dart: different hunks.git merge --no-commit). OnlyCHANGELOG.mdconflicts, because both add an[Unreleased]section. The mergedapi_server.pycompiles and pyflakes reports nothing new./desktop/statusrequire the token. The app already sends it, and/desktop/logrequires it here too.v3.20repositories at boot. The installer guard here covers images that booted with the old bootstrap.Relation to #26
#26 says: tapping Start, or Install & Start, shows a success message but no desktop starts, and there is no reason. After this PR:
Likely causes this PR removes:
localhostwhile the forward is IPv4 only.I can't confirm which of these the reporter hit without a device, so this says Refs #26. Close #26 after the device test below passes.
Checks run
koalaman/shellcheck:stable -s sh):linxr-desktop.sh: 0 findings (main: 10: SC2046 ×2, SC2013 ×2, SC2235 ×5, SC2034 ×1).init_bootstrap.shis not touched.alpine:3.24container: Alpine 3.24.4, the image's branch. Python 3.14.10, websockify 0.13.0, noVNC 1.6.0, x11vnc 0.9.17, tint2 17.1.3. It ran natively, not under TCG.vnc.htmlreturns 200, the WebSocket upgrade on/websockifyreturns 101, and x11vnc's bannerRFB 003.008arrives through websockify.kill -9x11vnc or websockify: restarted within 5 s, and the handshake works again.kill -9Xvfb: statefailed, error "Xvfb exited unexpectedly…".detail)./runand/var/logstate cleared): statusstopped, and Start brings XFCE back with the saved settings.xterm; touch /tmp/pis rejected (exit 2, API 400) and nothing runs. Starting an app while the desktop is stopped returns exit 4 (API 409). terminal, files and calculator open.install_state=failedwith "Could not reach the Alpine package mirror… galculator (no such package)";v3.20repositories on a 3.24 image are rewritten tov3.24;ok.api_server.py:py_compileOK.python:3.12-slim): the same 4 findings asmain, none new. One of them is the undefinedtimein the containers handler, which fix: code review fixes for disk resize, dockerd, k3s, recipes, API and VM lifecycle #34 fixes./desktop/log→ 401. Bad log name → 400.ghcr.io/cirruslabs/flutter:stable):flutter analyze: 0 errors and the same 6 warnings asmain; 124 issues in total against 122 onmain. The 2 extra arewithOpacitydeprecation infos in the new error card. That is the file's existing style: the builder is pinned to Flutter 3.22 (CHANGELOG NEW-1).flutter test: 20 passed (11 onmain). The new tests cover:waitForInstallwith failures and a missed poll;running=truenot counting as success;getDesktopLogarguments../gradlew :app:compileDebugKotlintwice in the Flutter container, once with-Xmx1536m. Both times the Gradle daemon was killed ("daemon disappeared unexpectedly") in the 4 GB Colima VM, before Kotlin compilation started. The Kotlin changes are small and were reviewed by hand. They need a compile in CI or locally.Device test checklist
Use a fresh install of this build on an arm64 phone. Keep "LAN access" off unless a step says otherwise.
echo |<>~in xterm and check that the symbols come out right (-xkb).kill -9 $(cat /run/linxr-desktop/xvfb.pid). Within about 10 s the Desktop screen shows "The desktop stopped: Xvfb exited unexpectedly…".kill -9 $(cat /run/linxr-desktop/x11vnc.pid). The viewer reconnects within about 10 s.linxr-desktop log desktopshows "x11vnc exited; restarting (1/5)".topwith the viewer open.topCPU of x11vnc idle and while dragging a window, before and after this build. The new flags are meant to lower it.