From 6c9a69af9ead552a34a02eef9b3e9a674aab7fd4 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Fri, 11 Sep 2026 16:45:36 -0400 Subject: [PATCH] Make first-run wait for daemon D-Bus --- daemon/index.js | 11 +++++++---- packaging/first-run.sh | 39 ++++++++++++++++++++++++++++++++------- packaging/install.sh | 3 ++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/daemon/index.js b/daemon/index.js index 3e9185c..266f8ff 100644 --- a/daemon/index.js +++ b/daemon/index.js @@ -78,10 +78,13 @@ export class JarvisDaemon extends EventEmitter { export async function startDaemon() { const daemon = new JarvisDaemon(); daemon.startVoice().catch((error) => console.error(`jarvisd: voice unavailable: ${error.message}`)); - import('./dbus-service.js').then(({ serveOnSessionBus }) => serveOnSessionBus(daemon)).catch((error) => { - daemon.emit('Error', 'DBUS_UNAVAILABLE', error.message); - console.error(`jarvisd: D-Bus unavailable: ${error.message}`); - }); + import('./dbus-service.js') + .then(({ serveOnSessionBus }) => serveOnSessionBus(daemon)) + .then(() => console.log('jarvisd: D-Bus name io.qvac.Jarvis ready')) + .catch((error) => { + daemon.emit('Error', 'DBUS_UNAVAILABLE', error.message); + console.error(`jarvisd: D-Bus unavailable: ${error.message}`); + }); process.on('SIGINT', () => daemon.close().finally(() => process.exit(0))); console.log('jarvisd ready; QVAC inference remains GPU-gated'); return daemon; diff --git a/packaging/first-run.sh b/packaging/first-run.sh index f951861..a1e1242 100755 --- a/packaging/first-run.sh +++ b/packaging/first-run.sh @@ -34,19 +34,44 @@ mkdir -p "${HOME}/.config/jarvis" "${BARE}" packaging/write-config.js "${HOME}/.config/jarvis/config.json" "${WAKE_PHRASE}" "${MODEL_PROFILE}" "${TTS_ENABLED}" echo "Saved wake phrase: ${WAKE_PHRASE}; model profile: ${MODEL_PROFILE}; TTS: ${TTS_ENABLED}" echo + +# The daemon owns the session D-Bus name. Start it after writing the config and +# wait for that name before sending the preview or smoke-test request. +DAEMON_BUS_READY=false +if command -v systemctl >/dev/null && command -v busctl >/dev/null && [[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ]]; then + systemctl --user daemon-reload || true + systemctl --user enable jarvisd.service || true + systemctl --user restart jarvisd.service || true + for _ in {1..30}; do + if busctl --user status io.qvac.Jarvis >/dev/null 2>&1; then + DAEMON_BUS_READY=true + break + fi + sleep 0.5 + done +fi + echo "[4/5] TTS preview" -if [[ "${TTS_ENABLED}" == true && -n "${DBUS_SESSION_BUS_ADDRESS:-}" ]]; then - busctl --user call io.qvac.Jarvis /io/qvac/Jarvis io.qvac.Jarvis.Session Say s "JARVIS local voice preview" || true +if [[ "${TTS_ENABLED}" == true && "${DAEMON_BUS_READY}" == true ]]; then + busctl --user call io.qvac.Jarvis /io/qvac/Jarvis io.qvac.Jarvis.Session Say s "JARVIS local voice preview" +elif [[ "${TTS_ENABLED}" == true ]]; then + echo "Daemon did not register io.qvac.Jarvis; preview skipped." else - echo "Session D-Bus is unavailable or TTS is disabled; preview skipped." + echo "TTS is disabled; preview skipped." fi echo echo "[5/5] Typed smoke test" read -r -p "Type a test prompt (default: say hello): " PROMPT PROMPT="${PROMPT:-say hello}" -if command -v busctl >/dev/null && [[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ]]; then - busctl --user call io.qvac.Jarvis /io/qvac/Jarvis io.qvac.Jarvis.Session Ask s "${PROMPT}" || true +if [[ "${DAEMON_BUS_READY}" == true ]]; then + busctl --user call io.qvac.Jarvis /io/qvac/Jarvis io.qvac.Jarvis.Session Ask s "${PROMPT}" else - echo "Session D-Bus is unavailable; saved setup and skipped live prompt." + echo "Daemon is not available on the session D-Bus; saved setup and skipped live prompt." + echo "Inspect with: systemctl --user status jarvisd.service" + echo "Logs: journalctl --user -u jarvisd.service -n 80 --no-pager" +fi +if [[ "${DAEMON_BUS_READY}" == true ]]; then + echo "First-run setup complete; jarvisd is running." +else + echo "First-run setup saved. Start with: systemctl --user enable --now jarvisd.service" fi -echo "First-run setup complete. Start with: systemctl --user enable --now jarvisd.service" diff --git a/packaging/install.sh b/packaging/install.sh index 39de0ac..a9fa1a5 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -44,7 +44,8 @@ if [[ ! -f "${CONFIG_DIR}/qvac.config.json" ]]; then fi if [[ "${1:-}" == "--enable" ]]; then systemctl --user daemon-reload - systemctl --user enable --now jarvisd.service + systemctl --user enable jarvisd.service + systemctl --user restart jarvisd.service fi echo "Installed JARVIS-QVAC to ${APP_DIR}" echo "Run: ${APP_DIR}/packaging/first-run.sh"