Repository navigation
Launch skill: never take focus from the user on macOS - #350456
Draft
Sandeep Somavarapu (sandy081) wants to merge 1 commit into
Draft
Sandeep Somavarapu (sandy081) wants to merge 1 commit into
Sandeep Somavarapu (sandy081) wants to merge 1 commit into
Conversation
Add a dev-only `--inactive-window` flag (ignored by built VS Code) that shows windows without activating the app and turns app-initiated focus requests (window open and reload, second instance, crash dialog) into inactive shows. The launch skill passes it by default, reports whether the instance activated, and a new cleanup.sh stops the main process first and reports activations over the whole lifetime of the instance. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Inactive restoration can still steal focus for maximized or fullscreen windows, and combining inactive mode with hidden mode can unexpectedly reveal a window.
2 open issues
What changed in this PR
This PR adds a development-only inactive-window mode to keep agent-launched Code OSS instances from taking focus, with macOS activation reporting and safer cleanup.
Changes:
- Adds
--inactive-windowand guards window display, focus, and error-handling paths. - Enables inactive launches by default in the Bash launcher and adds activation-checking and cleanup helpers.
- Documents the workflow and adds inactive-window unit tests.
| File | Description |
|---|---|
src/vs/platform/windows/test/electron-main/windowImpl.test.ts |
Tests inactive-mode gating, display, and focus behavior. |
src/vs/platform/windows/electron-main/windows.ts |
Defines inactive mode and creates its windows hidden. |
src/vs/platform/windows/electron-main/windowImpl.ts |
Adjusts restoration, focus, and renderer-error handling. |
src/vs/platform/native/electron-main/nativeHostMainService.ts |
Guards native focus and diagnostic-window display. |
src/vs/platform/launch/electron-main/launchMainService.ts |
Skips app activation for second-instance launches. |
src/vs/platform/environment/node/argv.ts |
Registers the hidden command-line flag. |
src/vs/platform/environment/common/argv.ts |
Adds the parsed argument type. |
src/vs/platform/browserView/electron-main/browserViewMainService.ts |
Prevents forced browser-view focus in inactive mode. |
.agents/skills/launch/SKILL.md |
Documents inactive launches, activation reporting, and cleanup. |
.agents/skills/launch/scripts/launch.sh |
Enables inactive mode and records launch metadata. |
.agents/skills/launch/scripts/cleanup/cleanup.sh |
Stops the main process first and removes the temporary profile. |
.agents/skills/launch/scripts/check-activation.sh |
Reports macOS activation events from the system log. |
Review effort: Balanced
Comment on lines
+376
to
+377
| if (isInactiveWindowMode(this.environmentMainService)) { | ||
| this._win?.showInactive(); |
| this._win?.showInactive(); // a window that is about to be minimized must not take focus | ||
| } | ||
| this._win?.minimize(); | ||
| } else if (isInactiveWindowMode(this.environmentMainService) && this._win && !this._win.isVisible()) { |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


On macOS, Code OSS instances that agents start with the launch skill took focus from the user for a few seconds: when the first window showed, on a window reload or workspace switch, and when the instance was stopped by killing its helper processes first. Electron's
show(),focus()andapp.focus({ steal })all activate the app; onlyshowInactive()doesn't.Changes
--inactive-windowargument.isInactiveWindowModerequires the argument and!environmentMainService.isBuilt(isBuiltis!VSCODE_DEV), so built products ignore it. In this mode, windows:showInactive(), and focus requests never activate the app;app.focus({ steal })for second-instance launches;launch.shpasses--inactive-windowby default (--foregroundopts out);check-activation.shreports any activation from the macOS log in the launch JSON (activated,activations), and warns on stderr. It reports only, and never hides the window;cleanup/cleanup.shstops the main process first, so a dead renderer can't reopen its window in front;SKILL.mddocuments both scripts.launch.ps1is unchanged.How to test
./scripts/test.sh --run src/vs/platform/windows/test/electron-main/windowImpl.test.ts(new suite "BaseWindow - inactive window mode"): passed, 29 tests../scripts/test.sh --run src/vs/platform/environment/test/node/argv.test.ts: passed, 9 tests.pnpm run typecheck-client: passed.pnpm run oxlinton the changed TypeScript files: passed.--skip-prelaunchand 5 without. Each run launched, opened a second workspace with--reuse-window, reloaded the window over CDP, then stopped withcleanup.sh. The macOS log recorded no activations (SETFRONT events), and 0 of about 850lsappinfo frontpolls found Code - OSS in front.Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)