Skip to content

Commit 18259f5

Browse files
committed
fix(windows): suppress console window flashing for background processes
- Add CREATE_NO_WINDOW flag to arp command execution on Windows to prevent console window from appearing during LAN scans - Apply CREATE_NO_WINDOW flag to powershell clipboard read operation in transfer module - Apply CREATE_NO_WINDOW flag to powershell clipboard write operation in transfer module - Prevents black cmd windows from flashing every 8 seconds during LAN scans and clipboard operations on Windows
1 parent 92a2f6c commit 18259f5

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

app/src-tauri/src/lan_scan.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ pub struct LanEntry {
1515
}
1616

1717
pub fn scan() -> Vec<LanEntry> {
18-
let Ok(output) = Command::new("arp").arg("-a").output() else {
18+
let mut cmd = Command::new("arp");
19+
cmd.arg("-a");
20+
// Suppress the flashing console window on Windows. `arp -a` is a console
21+
// app; without this flag, Windows opens a black cmd window for each call
22+
// and we run this every 8 seconds.
23+
#[cfg(target_os = "windows")]
24+
{
25+
use std::os::windows::process::CommandExt;
26+
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
27+
cmd.creation_flags(CREATE_NO_WINDOW);
28+
}
29+
let Ok(output) = cmd.output() else {
1930
return Vec::new();
2031
};
2132
if !output.status.success() {

app/src-tauri/src/transfer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,11 @@ end try
790790
// FileDropList yields plain string paths, not FileInfo, so `$_` is
791791
// what we want — `$_.FullName` was dropping every line.
792792
let script = "Get-Clipboard -Format FileDropList | ForEach-Object { $_ }";
793+
use std::os::windows::process::CommandExt;
794+
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
793795
let out = std::process::Command::new("powershell")
794796
.args(["-NoProfile", "-NonInteractive", "-Command", script])
797+
.creation_flags(CREATE_NO_WINDOW)
795798
.output();
796799
if let Ok(o) = out {
797800
let s = String::from_utf8_lossy(&o.stdout);
@@ -899,6 +902,8 @@ pub fn copy_paths_to_clipboard(paths: Vec<String>) -> Result<(), String> {
899902
[System.Windows.Forms.Clipboard]::SetFileDropList($col)\n"
900903
);
901904
// -STA is required: clipboard APIs need a single-threaded apartment.
905+
use std::os::windows::process::CommandExt;
906+
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
902907
let out = std::process::Command::new("powershell")
903908
.args([
904909
"-NoProfile",
@@ -907,6 +912,7 @@ pub fn copy_paths_to_clipboard(paths: Vec<String>) -> Result<(), String> {
907912
"-Command",
908913
&script,
909914
])
915+
.creation_flags(CREATE_NO_WINDOW)
910916
.output()
911917
.map_err(|e| format!("powershell: {e}"))?;
912918
if !out.status.success() {

0 commit comments

Comments
 (0)