Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(windows): add CREATE_NO_WINDOW to all subprocess spawns

Louis Beaumontaab48f07a002
diff --git a/crates/screenpipe-connect/src/remote_sync.rs b/crates/screenpipe-connect/src/remote_sync.rs
index 1f98fca52..9faa243c4 100644
--- a/crates/screenpipe-connect/src/remote_sync.rs
+++ b/crates/screenpipe-connect/src/remote_sync.rs
@@ -463,11 +463,14 @@ async fn sync_to_remote_inner(config: &SyncConfig, data_dir: &Path) -> Result<Sy
// This is best-effort — if the DB is locked or doesn't exist, we skip.
let db_path = data_dir.join("db.sqlite");
if db_path.exists() {
- match tokio::process::Command::new("sqlite3")
- .arg(&db_path)
- .arg("PRAGMA wal_checkpoint(TRUNCATE);")
- .output()
- .await
+ let mut wal_cmd = tokio::process::Command::new("sqlite3");
+ wal_cmd.arg(&db_path).arg("PRAGMA wal_checkpoint(TRUNCATE);");
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ wal_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ match wal_cmd.output().await
{
Ok(out) if out.status.success() => {
debug!("WAL checkpoint completed before sync");
@@ -770,10 +773,14 @@ fn parse_known_hosts(content: &str) -> Vec<DiscoveredHost> {
}
async fn discover_tailscale() -> Vec<DiscoveredHost> {
- let out = match tokio::process::Command::new("tailscale")
- .args(["status", "--json"])
- .output()
- .await
+ let mut ts_cmd = tokio::process::Command::new("tailscale");
+ ts_cmd.args(["status", "--json"]);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ ts_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ let out = match ts_cmd.output().await
{
Ok(o) if o.status.success() => o,
_ => return vec![],
diff --git a/crates/screenpipe-connect/src/whatsapp/mod.rs b/crates/screenpipe-connect/src/whatsapp/mod.rs
index 8e7b43afc..e56885bd5 100644
--- a/crates/screenpipe-connect/src/whatsapp/mod.rs
+++ b/crates/screenpipe-connect/src/whatsapp/mod.rs
@@ -128,14 +128,18 @@ impl WhatsAppGateway {
.join("@whiskeysockets");
if !node_modules.exists() {
info!("installing @whiskeysockets/baileys, pino, and ws...");
- let install = Command::new(bun_path)
+ let mut install_cmd = Command::new(bun_path);
+ install_cmd
.args(["add", "@whiskeysockets/baileys", "pino", "ws"])
.current_dir(&self.screenpipe_dir)
.stdout(Stdio::null())
- .stderr(Stdio::piped())
- .spawn()?
- .wait()
- .await?;
+ .stderr(Stdio::piped());
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ install_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ let install = install_cmd.spawn()?.wait().await?;
if !install.success() {
anyhow::bail!("failed to install @whiskeysockets/baileys");
}
@@ -149,13 +153,20 @@ impl WhatsAppGateway {
let script_path = self.screenpipe_dir.join("whatsapp-gateway.mjs");
let node_path = which_node().unwrap_or_else(|| "node".to_string());
- let mut child = Command::new(&node_path)
+ let mut gateway_cmd = Command::new(&node_path);
+ gateway_cmd
.arg(script_path.to_str().unwrap())
.env("WHATSAPP_SESSION_DIR", session_dir.to_str().unwrap())
.stdin(Stdio::piped()) // keep stdin open so gateway doesn't self-terminate
.stdout(Stdio::piped())
.stderr(Stdio::piped())
- .kill_on_drop(true)
+ .kill_on_drop(true);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ gateway_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ let mut child = gateway_cmd
.spawn()
.context("failed to spawn whatsapp gateway")?;
@@ -337,14 +348,20 @@ impl WhatsAppGateway {
let script_path = screenpipe_dir.join("whatsapp-gateway.mjs");
let node_path = which_node().unwrap_or_else(|| "node".to_string());
- match Command::new(&node_path)
+ let mut respawn_cmd = Command::new(&node_path);
+ respawn_cmd
.arg(script_path.to_str().unwrap())
.env("WHATSAPP_SESSION_DIR", session_dir.to_str().unwrap())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
- .kill_on_drop(true)
- .spawn()
+ .kill_on_drop(true);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ respawn_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ match respawn_cmd.spawn()
{
Ok(mut new_child) => {
let stdin_handle = new_child.stdin.take().expect("stdin piped");
@@ -469,32 +486,34 @@ impl WhatsAppGateway {
/// Find bun executable on PATH.
pub fn which_bun() -> Option<String> {
- std::process::Command::new("which")
- .arg("bun")
- .output()
- .ok()
- .and_then(|o| {
- if o.status.success() {
- String::from_utf8(o.stdout)
- .ok()
- .map(|s| s.trim().to_string())
- } else {
- None
- }
- })
+ which_executable("bun")
}
/// Find node executable on PATH.
fn which_node() -> Option<String> {
- std::process::Command::new("which")
- .arg("node")
- .output()
+ which_executable("node")
+}
+
+fn which_executable(name: &str) -> Option<String> {
+ let (cmd_name, args) = if cfg!(windows) {
+ ("where", vec![name.to_string()])
+ } else {
+ ("which", vec![name.to_string()])
+ };
+ let mut cmd = std::process::Command::new(cmd_name);
+ cmd.args(&args);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ cmd.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout)
.ok()
- .map(|s| s.trim().to_string())
+ .map(|s| s.lines().next().unwrap_or("").trim().to_string())
} else {
None
}
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 5f8000d0d..cfaa592c5 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -1365,6 +1365,13 @@ fn build_async_command(path: &str) -> tokio::process::Command {
}
}
+ // Prevent console window flash on Windows
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x08000000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+
cmd
}
#[cfg(not(windows))]