Skip to content

fix(process): hide console window for child processes on Windows - #139

Merged
Haleclipse merged 2 commits into
Haleclipse:masterfrom
aurorapolestar:fix/windows-hide-console-popup
Oct 24, 2026
Merged

Haleclipse merged 2 commits into
Haleclipse:masterfrom
aurorapolestar:fix/windows-hide-console-popup

Conversation

@aurorapolestar

@aurorapolestar aurorapolestar commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Windows, background refreshes (such as refresh-git in git_cache.rs or check-update) are spawned with DETACHED_PROCESS. When a detached process executes a child console application (like git status) without CREATE_NO_WINDOW, Windows allocates and briefly flashes a new console window on the desktop before closing it upon exit.

This PR adds CREATE_NO_WINDOW (0x0800_0000):

  1. In src/process.rs for all child processes invoked via process::run.
  2. In src/state/mod.rs for spawn_detached.

Fixes #138

Summary by Sourcery

Bug Fixes:

  • Prevent Windows console windows from flashing when running background child processes, including Git operations and update checks.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds the Windows CREATE_NO_WINDOW creation flag to both normal child-process execution and detached background-process spawning, preventing transient console windows while preserving existing behavior and flags on other platforms.

Sequence diagram for Windows child process execution without a console window

sequenceDiagram
    participant Caller
    participant ProcessRun as process::run
    participant Child as Child process
    participant Console as Windows console
    Caller->>ProcessRun: run(cmd, stdin, timeout)
    ProcessRun->>ProcessRun: creation_flags(CREATE_NO_WINDOW)
    ProcessRun->>Child: spawn()
    Child-->>Console: No console window created
Loading

Sequence diagram for detached background process spawning without a console window

sequenceDiagram
    participant Caller
    participant State as state::spawn_detached
    participant Child as Detached process
    participant Console as Windows console
    Caller->>State: spawn_detached(args)
    State->>State: creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW)
    State->>Child: spawn()
    Child-->>Console: No console window created
Loading

File-Level Changes

Change Details Files
Suppress Windows console-window creation for processes launched through the generic process runner.
  • Apply the Windows CREATE_NO_WINDOW creation flag before spawning commands.
  • Keep the behavior platform-specific through conditional compilation, leaving non-Windows execution unchanged.
src/process.rs
Prevent detached background processes and their console children from flashing a console window.
  • Combine CREATE_NO_WINDOW with the existing detached-process and new-process-group flags.
  • Use the updated flags when spawning detached refresh and update commands.
src/state/mod.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#138 Prevent transient Windows console windows from appearing during periodic refreshes and other background child-process execution. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/process.rs" line_range="33" />
<code_context>
+    {
+        use std::os::windows::process::CommandExt;
+        const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+        cmd.creation_flags(CREATE_NO_WINDOW);
+    }
     let Ok(mut child) = cmd.spawn() else {
</code_context>
<issue_to_address>
**Shell-launched commands flash consoles**

When a Windows command run through `cmd.exe` launches a console application, `process::run` applies `CREATE_NO_WINDOW` only to `cmd.exe`, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.

Ensure console applications launched by `cmd.exe` also receive `CREATE_NO_WINDOW`.
</issue_to_address>

### Comment 2
<location path="src/state/mod.rs" line_range="144-145" />
<code_context>
+    #[cfg(windows)]
+    {
+        use std::os::windows::process::CommandExt;
+        const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+        cmd.creation_flags(CREATE_NO_WINDOW);
+    }
</code_context>
<issue_to_address>
**Update checks still flash consoles**

When a Windows background update check reaches `curl`, `state::update::fetch` launches `curl` with `Command::output()` rather than applying `CREATE_NO_WINDOW`, so Windows opens and flashes a console during the background check.

Apply `CREATE_NO_WINDOW` to the `curl` command launched by `state::update::fetch`.

Also at `src/process.rs:33`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/process.rs:33, src/state/mod.rs:145


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/process.rs
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
cmd.creation_flags(CREATE_NO_WINDOW);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Shell-launched commands flash consoles

When a Windows command run through cmd.exe launches a console application, process::run applies CREATE_NO_WINDOW only to cmd.exe, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.

Ensure console applications launched by cmd.exe also receive CREATE_NO_WINDOW.

Prompt for AI agents
In `src/process.rs` at line 33:

**Shell-launched commands flash consoles**

When a Windows command run through `cmd.exe` launches a console application, `process::run` applies `CREATE_NO_WINDOW` only to `cmd.exe`, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.

Ensure console applications launched by `cmd.exe` also receive `CREATE_NO_WINDOW`.

Comment thread src/state/mod.rs Resolved
@Haleclipse
Haleclipse merged commit 45a988c into Haleclipse:master Oct 24, 2026
1 check passed
@Haleclipse Haleclipse mentioned this pull request Oct 24, 2026
3 tasks
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.

每次refresh的时候会出现一个终端窗口闪烁

2 participants