Suppress console-window flash on subprocess spawn (CREATE_NO_WINDOW); bump 0.1.2
paths::quiet_command sets CREATE_NO_WINDOW (0x08000000) on Windows so short-lived child processes (wsl.exe -l -q, where claude, wsl.exe -d X bash -lc 'command -v claude') don't briefly allocate a real console window and flash on click. Used by both paths.rs and cli_usage.rs.
This commit is contained in:
parent
6dd8200802
commit
160e08d4a8
5 changed files with 24 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "claude-usage-widget",
|
"name": "claude-usage-widget",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "claude-usage-widget"
|
name = "claude-usage-widget"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
description = "Always-on-top Windows widget visualizing local Claude Code usage"
|
description = "Always-on-top Windows widget visualizing local Claude Code usage"
|
||||||
authors = ["megaproxy"]
|
authors = ["megaproxy"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
|
||||||
|
|
@ -114,9 +114,8 @@ pub fn autodetect_command() -> Option<Vec<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn which_exists(name: &str) -> bool {
|
fn which_exists(name: &str) -> bool {
|
||||||
use std::process::Command;
|
|
||||||
let probe = if cfg!(windows) { "where" } else { "which" };
|
let probe = if cfg!(windows) { "where" } else { "which" };
|
||||||
Command::new(probe)
|
crate::paths::quiet_command(probe)
|
||||||
.arg(name)
|
.arg(name)
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success() && !o.stdout.is_empty())
|
.map(|o| o.status.success() && !o.stdout.is_empty())
|
||||||
|
|
@ -124,8 +123,7 @@ fn which_exists(name: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_wsl_distros() -> Vec<String> {
|
fn list_wsl_distros() -> Vec<String> {
|
||||||
use std::process::Command;
|
let Ok(out) = crate::paths::quiet_command("wsl.exe").args(["-l", "-q"]).output() else {
|
||||||
let Ok(out) = Command::new("wsl.exe").args(["-l", "-q"]).output() else {
|
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
};
|
};
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
|
|
@ -145,8 +143,7 @@ fn list_wsl_distros() -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn probe_claude_in_wsl(distro: &str) -> bool {
|
fn probe_claude_in_wsl(distro: &str) -> bool {
|
||||||
use std::process::Command;
|
crate::paths::quiet_command("wsl.exe")
|
||||||
Command::new("wsl.exe")
|
|
||||||
.args(["-d", distro, "bash", "-lc", "command -v claude"])
|
.args(["-d", distro, "bash", "-lc", "command -v claude"])
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success() && !o.stdout.is_empty())
|
.map(|o| o.status.success() && !o.stdout.is_empty())
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,23 @@
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
/// Construct a `Command` that won't flash a console window on Windows.
|
||||||
|
///
|
||||||
|
/// `Command::new(...).output()` allocates a console for the child process
|
||||||
|
/// before it exits, which appears as a black flash for short-lived processes
|
||||||
|
/// like `wsl.exe -l -q` or `where claude`. The CREATE_NO_WINDOW flag (Win32
|
||||||
|
/// process-creation flag 0x08000000) suppresses that.
|
||||||
|
pub fn quiet_command(program: &str) -> std::process::Command {
|
||||||
|
let mut c = std::process::Command::new(program);
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
||||||
|
c.creation_flags(CREATE_NO_WINDOW);
|
||||||
|
}
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct ResolvedRoots {
|
pub struct ResolvedRoots {
|
||||||
pub roots: Vec<PathBuf>,
|
pub roots: Vec<PathBuf>,
|
||||||
|
|
@ -24,7 +41,7 @@ pub fn list_wsl_distros() -> anyhow::Result<Vec<String>> {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let out = match std::process::Command::new("wsl.exe")
|
let out = match quiet_command("wsl.exe")
|
||||||
.args(["-l", "-q"])
|
.args(["-l", "-q"])
|
||||||
.output()
|
.output()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Claude Usage Widget",
|
"productName": "Claude Usage Widget",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"identifier": "com.megaproxy.claude-usage-widget",
|
"identifier": "com.megaproxy.claude-usage-widget",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm dev",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue