Skip to content

Persist the selected port in the main process before navigating away #89

@germanescobar

Description

@germanescobar

Context

The first-run welcome flow (PR #84) has a race that prevents the selected port from being persisted on the first explicit Continue click. Subsequent launches therefore show the welcome screen again instead of auto-starting on the saved port.

Current behavior

  1. User clicks Continue on the welcome screen.
  2. Renderer awaits controller.startServer(port).
  3. Main process runs startProductionServer, then await openMainAppWindow(url), which calls loadURL on the welcome window (navigating it to the main app).
  4. Main process returns the IPC reply.
  5. Renderer's continuation runs writeSavedPort(result.port) then navigateToApp(result.url).

By step 5, the welcome page is being torn down by loadURL from step 3. The continuation may never run, and even if it does, the localStorage write is racing the page teardown. The selected port is not reliably saved.

Expected behavior

The port is persisted before any navigation happens, so the next launch can auto-start on it.

Proposed fix

Move persistence into the main process. After startProductionServer succeeds, write the port to app.getPath('userData')/controller.json. Expose it to the renderer via a new controller.getSavedPort() IPC method (replacing localStorage.controller.port). The main process owns persistence from then on; the renderer reads through IPC.

This is a small, well-scoped change but touches the welcome script, the preload, the main process, and shared/controller.ts. Worth a follow-up PR rather than a last-minute addition to #84.

Workaround

Until this is fixed, the auto-start on second launch only works if the user didn't go through the explicit Continue path on first run (e.g. if the saved port was already populated by a previous, separate run). In practice, first-time users will see the welcome screen every launch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions