fix(desktop): l'app démarre après une mise à jour, et parle quand elle ne peut pas
Installer une nouvelle version remplace les fichiers sur disque mais ne touche
pas le process en cours : l'ancienne instance gardait le port 7317, la version
fraîchement installée mourait sur EADDRINUSE avant son handshake, et le shell se
contentait d'un console.error suivi d'un app.quit(). Depuis le lanceur, cliquer
l'icône ne produisait donc rien du tout.
- Tout échec de démarrage ouvre un dialogue Retry / Show log / Quit
(start-failure.ts, texte pur et testé) et la sortie du daemon est conservée
dans <userData>/logs/daemon.log. Une mort du daemon APRÈS le handshake propose
de le relancer, au lieu de laisser une fenêtre morte à l'écran.
- Le port est diagnostiqué avant le spawn (port-guard.ts, empreinte
{pid, ownerPid, port}) : un daemon orphelin, dont l'Electron est mort, est
repris (SIGTERM puis SIGKILL, en attendant un bind réellement possible) ;
une instance vivante ou un tiers (service, npx) est annoncé avec l'action qui
débloque, et jamais tué. La reprise exige deux preuves, l'empreinte orpheline
ET l'identité du process (ps -ww), car un pidfile périmé peut désigner un pid
recyclé entre-temps par un programme quelconque.
- Une mise à jour installée à chaud est signalée avec « Restart now »
(upgrade-watch.ts), qui arrête le daemon avant app.relaunch() ; sans quoi le
lock d'instance unique renvoyait silencieusement sur la fenêtre de l'ancienne
version, et on croyait avoir migré.
- ARBORETUM_DESKTOP_PORT pour cohabiter avec un Arboretum qui occupe 7317 en
permanence (service installé, ou daemon lancé en terminal).
24 tests dans packages/desktop/test, et quatre scénarios rejoués en dev sous
xvfb-run avec profil isolé : port tenu par un tiers, orphelin repris puis SPA
servie, instance vivante laissée intacte, pid recyclé épargné.
This commit is contained in:
@@ -91,6 +91,44 @@ then "Open", or run `xattr -dr com.apple.quarantine /Applications/Arboretum.app`
|
||||
`/usr/local/bin`, `/opt/homebrew/bin`, `~/.local/bin`; on Windows `%LOCALAPPDATA%\Programs` and
|
||||
`%APPDATA%\npm`, where the Claude CLI and global npm binaries actually live.
|
||||
|
||||
## Startup, and what happens when it fails
|
||||
|
||||
The shell owns the daemon: it spawns it on **port 7317** (`ARBORETUM_DESKTOP_PORT` overrides), waits for
|
||||
the handshake on fd 3, seeds the session cookie, then loads the SPA. Since a fixed port is easy to hold
|
||||
hostage, the port is checked *before* spawning (`src/main/port-guard.ts`) and the outcome decides:
|
||||
|
||||
| Who holds the port | What the app does |
|
||||
| --- | --- |
|
||||
| Nobody | Starts normally. |
|
||||
| **Our own daemon, orphaned** (its Electron died: crash, `kill -9`, package upgrade) | Reclaims it: SIGTERM, then SIGKILL, waiting for the port to be *effectively* free, then starts. |
|
||||
| **Another live instance** of the app | Says so, and points at the tray where that window is hiding. Never kills it. |
|
||||
| A third party (`arboretum install` service, `npx @johanleroy/git-arboretum`, unrelated software) | Says so, and suggests stopping it or setting `ARBORETUM_DESKTOP_PORT`. |
|
||||
|
||||
Ownership is recorded in `<userData>/daemon/daemon.json` (`{pid, ownerPid, port}`): a live daemon whose
|
||||
`ownerPid` is gone is an orphan, one whose owner is alive is another instance. Every failure now opens a
|
||||
dialog with **Retry / Show log / Quit** instead of quitting silently, and the daemon's output is kept in
|
||||
`<userData>/logs/daemon.log`. If the daemon dies *after* startup, the app offers to restart it rather
|
||||
than leaving a dead window on screen.
|
||||
|
||||
`<userData>` is `~/.config/Arboretum` (Linux), `~/Library/Application Support/Arboretum` (macOS),
|
||||
`%APPDATA%\Arboretum` (Windows).
|
||||
|
||||
## Installing a new version
|
||||
|
||||
Installers replace the files on disk; they never touch the running process. So after a `dpkg -i` (or an
|
||||
NSIS run) **the open window keeps serving the old version**, and its daemon keeps port 7317 - which used
|
||||
to make the freshly installed version unable to start at all.
|
||||
|
||||
The recommended order is therefore either one of:
|
||||
|
||||
1. Quit Arboretum from the tray, then install, then launch. Clean, nothing to think about.
|
||||
2. Install while it runs, then click the launcher or the tray icon: the shell notices that its own
|
||||
binary changed on disk (`src/main/upgrade-watch.ts`) and offers **Restart now**, which stops the
|
||||
daemon before relaunching, so the new version finds its port free.
|
||||
|
||||
Answering *Later* keeps the old window; the prompt comes back only if yet another version is installed.
|
||||
The check is inert in dev (`app.isPackaged` is false).
|
||||
|
||||
## Auto-update
|
||||
|
||||
electron-builder emits `latest*.yml` next to the artifacts and `electron-updater` reads them from a
|
||||
|
||||
Reference in New Issue
Block a user