phoebus_os/installer/live/desktop/common/Bridge.qml
Phoebus 7e9fa9c2a3
Some checks are pending
ci / test (push) Waiting to run
feat(installer): graphical welcome and install wizard over a typed bridge
Add a branded live welcome window and a Quickshell/QML installer frontend
over a narrow, fail-closed JSON bridge (phoebus-installer --gui-bridge)
that reuses the same InstallConfig, plan, validation, authorization and
staged executor as the TUI/CLI. Add the Phoebus brand system (emblem,
wordmark, wallpaper, tokens), suppress DMS first-run dialogs on the live
medium, identify the live medium as protected, make the installer
shortcut live-only, and fix the installed boot default so systemd-boot
never selects the recovery entry.

Verified in a disposable graphical VM (welcome/installer journey,
duplicate prevention, keyboard navigation, blocked AI prerequisite) plus
a real non-interactive install and detached boot (INSTALL-RC=0,
NO_SECRET_LEAK, systemd running, 0 failed units, LUKS2, Btrfs, network).
2026-09-21 13:13:40 -07:00

173 lines
5.1 KiB
Bash

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
// Typed JSON bridge to the privileged Rust installer. The frontend never
// scrapes terminal output: every call is a typed request and every reply is a
// typed JSON object. Secrets are written over the process stdin only.
Singleton {
id: root
// True once the bridge process is running and accepting requests.
property bool ready: false
property bool crashed: false
property string crashMessage: ""
property string lastError: ""
property var handshake: null
property var config: null
property var pending: ({})
property int nextId: 1
signal event(string name, var data)
signal availabilityChanged
signal handshakeReady
readonly property var bridgeCommand: {
const override = Quickshell.env("PHOEBUS_BRIDGE_CMD");
if (override && override.length > 0)
return override.split(" ").filter(part => part.length > 0);
// Absolute paths: Quickshell's Process execs the command directly and
// does not perform PATH lookup.
return ["/usr/bin/sudo", "-n", "/usr/local/bin/phoebus-installer", "--gui-bridge"];
}
// Retried until the first successful handshake, so a process-start race can
// never leave the frontend permanently stuck.
Timer {
interval: 400
repeat: true
running: proc.running && root.handshake === null
onTriggered: root.refreshHandshake(null)
}
function start() {
if (!proc.running)
proc.running = true;
}
function stop() {
if (proc.running)
proc.running = false;
}
function call(op, payload, onDone) {
const id = root.nextId++;
if (onDone)
root.pending[id] = onDone;
const request = Object.assign({ id: id, op: op }, payload || {});
const line = JSON.stringify(request) + "\n";
if (!proc.running) {
// Quickshell's Process.write() returns void, so it cannot be used
// to detect a failed write. Check the process state instead.
delete root.pending[id];
root.lastError = "backend not running";
if (onDone)
onDone({ ok: false, error: "the installer backend is not running" });
return;
}
proc.write(line);
}
function handleLine(line) {
const text = ("" + line).trim();
if (text.length === 0)
return;
let msg;
try {
msg = JSON.parse(text);
} catch (e) {
console.log("bridge: unparsable line: " + text);
return;
}
if (msg.event === "progress") {
root.event("progress", msg);
return;
}
if (msg.id !== undefined && root.pending[msg.id]) {
const cb = root.pending[msg.id];
delete root.pending[msg.id];
cb(msg);
}
}
// Convenience wrappers.
function refreshHandshake(cb) {
call("handshake", {}, reply => {
if (reply.ok) {
root.handshake = reply.data;
root.handshakeReady();
}
if (cb)
cb(reply);
});
}
function listDisks(cb) {
call("disks", {}, cb);
}
function setConfig(cfg, cb) {
call("set_config", { config: cfg }, reply => {
if (reply.ok)
root.config = cfg;
if (cb)
cb(reply);
});
}
function setSecrets(secrets, cb) {
call("set_secrets", { secrets: secrets }, cb);
}
function validate(cb) {
call("validate", {}, cb);
}
function plan(cb) {
call("plan", {}, cb);
}
function destructivePreview(cb) {
call("destructive_preview", {}, cb);
}
function aiCheck(cb) {
call("ai_check", {}, cb);
}
function approve(eraseText, finalConfirmed, cb) {
call("approve", { erase: eraseText, final_confirm: finalConfirmed }, cb);
}
function startInstall(planDigest, eraseText, cb) {
call("start_install", {
erase: eraseText,
final_confirm: true,
plan_digest: planDigest
}, cb);
}
function logTail(lines, cb) {
call("log_tail", { lines: lines }, cb);
}
Process {
id: proc
command: root.bridgeCommand
stdinEnabled: true
running: false
onStarted: {
root.ready = true;
root.crashed = false;
root.crashMessage = "";
root.availabilityChanged();
}
onExited: exitCode => {
root.ready = false;
root.crashed = true;
root.crashMessage = "The installer backend stopped (exit " + exitCode + ").";
root.availabilityChanged();
}
stdout: SplitParser {
onRead: line => root.handleLine(line)
}
stderr: SplitParser {
onRead: line => {
root.lastError = line;
console.log("phoebus-bridge: " + line);
}
}
}
}