Skip to content

refactor(viewer): split start_viewer.sh into per-platform libs - #3161

Merged
vpetersson merged 1 commit into
masterfrom
refactor/start-viewer-per-platform
Jul 8, 2026
Merged

refactor(viewer): split start_viewer.sh into per-platform libs#3161
vpetersson merged 1 commit into
masterfrom
refactor/start-viewer-per-platform

Conversation

@vpetersson

Copy link
Copy Markdown
Contributor

What

bin/start_viewer.sh had grown to ~800 lines interleaving shared boot setup with three display paths (cage/wayland, eglfs, linuxfb). This splits it into an orchestrator plus per-platform libraries — pure structural refactor, no behavior change.

bin/start_viewer.sh                  orchestrator: shared setup + dispatch by DEVICE_TYPE
bin/lib/viewer/common.sh             paths, pulseaudio, locale, scale factor, render group,
                                     Plymouth handoff, direct-sudo launch, supervise loop
bin/lib/viewer/platform_wayland.sh   cage launch (x86 / arm64 / pi5)
bin/lib/viewer/platform_eglfs.sh     eglfs display wait + KMS-card detection (pi4-64 / pi3-64)
bin/lib/viewer/platform_linuxfb.sh   framebuffer wait + HDMI-hotplug resolution recovery (pi2 / pi3)

Why it's safe

  • Verbatim move. Every command, comment, and guard is moved unchanged; former inline top-level blocks are just wrapped in functions. A line-by-line check confirms every original content line is present verbatim in the new files — the only diff is the two case-syntax ;; lines changing indentation.
  • Order preserved. Each platform bring-up step already self-guards on QT_QPA_PLATFORM / DEVICE_TYPE, so the orchestrator calls them unconditionally in the same order the monolithic script ran.
  • No packaging change. COPY . /usr/src/app/ already ships the new bin/lib/viewer/ dir; the container CMD ["bash", "./bin/start_viewer.sh"] is unchanged. Nothing else in the repo references start_viewer.sh internals.

Verification

  • bash -n clean on all five files; sourcing the libs defines 17 functions with no side effects at source time.
  • Deployed to a Pi 5 and restarted: shared setup ran, the wayland launch ran, cage bound the output (Applied wlroots transform), grim captured, display renders at 3840×2160.
  • shellcheck surfaces three findings (SC2172 trap-by-number, SC2181 $?, SC2016 single-quoted bash -c) — all pre-existing patterns carried over verbatim; SC2016 is a false positive (the ${XDG_RUNTIME_DIR} is meant to expand in cage's child shell). Not touched, to keep this a no-behavior-change move.

Follow-up to the headless-boot display-wedge fix (#3155, merged); the vc4 self-heal from that PR now lives in platform_wayland.sh. Replaces the earlier stacked PR that GitHub auto-closed when its base branch was deleted on merge.

🤖 Generated with Claude Code

start_viewer.sh had grown to ~790 lines mixing shared boot setup with
three interleaved display paths (cage/wayland, eglfs, linuxfb), which
made it hard to follow and to change safely.

Extract the platform-specific bring-up and launch into
bin/lib/viewer/*.sh and reduce start_viewer.sh to an orchestrator that
runs shared setup then dispatches by DEVICE_TYPE:

  bin/start_viewer.sh                  orchestrator: shared setup + dispatch
  bin/lib/viewer/common.sh             paths, pulseaudio, locale, scale
                                       factor, render group, Plymouth,
                                       direct-sudo launch, supervise loop
  bin/lib/viewer/platform_wayland.sh   cage launch (x86 / arm64 / pi5)
  bin/lib/viewer/platform_eglfs.sh     eglfs display wait + KMS card detect
  bin/lib/viewer/platform_linuxfb.sh   fb wait + HDMI-hotplug recovery

No behavior change: every command, comment, and guard is moved verbatim.
The former inline top-level blocks are wrapped in functions, and each
platform step keeps its own QT_QPA_PLATFORM / DEVICE_TYPE guard, so the
orchestrator can call them unconditionally in the same order the
monolithic script ran. COPY . /usr/src/app/ already ships the new lib
dir and the container CMD is unchanged.

Verified: every original content line is present verbatim in the new
files (only the two case-syntax ";;" lines changed indentation); bash -n
clean on all five files; the sourced libs load with no side effects; and
the refactored script boots and binds the display on a Pi 5.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vpetersson
vpetersson requested a review from a team as a code owner July 8, 2026 15:15
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@vpetersson
vpetersson merged commit def0fb7 into master Jul 8, 2026
7 checks passed
@vpetersson
vpetersson deleted the refactor/start-viewer-per-platform branch July 8, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant