Skip to content

fix(connect): don't quit a Figma that is already debuggable - #40

Open
clementcopper wants to merge 1 commit into
silships:mainfrom
clementcopper:fix/connect-non-destructive
Open

fix(connect): don't quit a Figma that is already debuggable#40
clementcopper wants to merge 1 commit into
silships:mainfrom
clementcopper:fix/connect-non-destructive

Conversation

@clementcopper

Copy link
Copy Markdown

The problem

connect quits and relaunches Figma unconditionally:

// src/commands/setup.js
stopDaemon();

console.log(chalk.blue('Starting Figma...'));
try {
  killFigma();
  await new Promise(r => setTimeout(r, 500));
} catch {}

startFigma();

That runs even when the CDP port is already answering and nothing needs to happen to Figma at all — which is the common case once you're set up. The cost is the user's window arrangement, their zoom/scroll position, and whatever hasn't synced yet. Running connect a second time "just to be sure" is a normal thing to do, and it shouldn't be destructive.

It also affects the recovery path people are told to take: when a command times out, restarting the daemon is usually enough, but connect looks like the safer, more thorough option — and it's the one that costs you your session.

The change

connect probes the CDP port first and branches on what it finds:

CDP reachable Figma running Action
yes reuse — leave Figma alone, just start the daemon
no yes needs-quit — ask the user to quit (they may have unsaved work; killing it for them is not our call)
no no start-fresh — patch if needed and launch, exactly as before

The start-fresh branch is the existing code, unchanged. Only the guard in front of it is new.

The decision itself is a pure function in src/lib/connect-plan.js, following the pattern of browserDebugArgs / tests/browser-mode.test.js, so it's unit-tested without a Figma or an open port:

resolveConnectAction({ cdpReachable, figmaRunning })
// → 'reuse' | 'needs-quit' | 'start-fresh'

The process probe uses the existing isFigmaRunning() from src/platform.js, so it works on macOS, Windows and Linux. The port comes from getCdpPort(), so --port / FIGMA_PORT are honored.

Verification

  • npm test → 525 passing, including 4 new cases in tests/connect-plan.test.js
  • All three branches confirmed against a real Figma Desktop:
    • reuse — Figma's PID and start time identical before and after connect; output ✓ Figma already running (left untouched), daemon reconnected
    • needs-quit — Figma running with an unpatched app.asar: connect printed the quit prompt and left the process alone
    • start-fresh — no Figma running: patched and launched as before

Notes

Happy to adjust the wording of the needs-quit message, or to make it offer a --force flag that restores the old quit-and-relaunch behavior, if you'd rather keep an escape hatch.

`connect` quit and relaunched Figma unconditionally, costing the user
their window arrangement and any unsaved state — including the common
case where the CDP port already answers and nothing needs to happen.

connect now probes the port first and branches on the result:

  reuse       CDP answers            -> leave Figma alone, wire up the daemon
  needs-quit  Figma up, no debug port -> ask the user to quit (they may have
                                         unsaved work; we must not kill it)
  start-fresh no Figma                -> patch if needed and launch, as before

The decision itself is a pure function in src/lib/connect-plan.js so it
can be unit-tested without a Figma or an open port. The process probe uses
isFigmaRunning() from platform.js, so it works on all three platforms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clementcopper added a commit to clementcopper/figma-claude that referenced this pull request Sep 3, 2026
Seven branches became one on 2026-09-03. The skill's first line still said the
default was v2, and it is the file you read right before merging from upstream.

What the cleanup was based on: `feat/swift-host` was v2 plus 26 commits with v2
fully contained, the only tree difference being `swift-host/`, and `app/` sitting
in both. The Electron app is a directory, not a branch — `make-app.sh` reads
`app/build/icon.icns` — so a second branch beside the trunk would have been a
copy of the same CLI falling behind. v2 had stood still since 22.08.

`v2` and `archive/draft-v1` are now the tags `v2-final` and `draft-v1`. The four
PR branches stay on origin because deleting them there closes PRs silships#40, silships#41, silships#43
and silships#44; that is written down so nobody tidies them away later.

Also noted: CI triggers on `branches: [main]`, which this fork has never had, so
it has never run on a push here. Left alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QuvZuDad3hi3CVwNDbTvr2
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