Skip to content

Commit 20d0e69

Browse files
committed
Hide wsl console windows on windows
1 parent 20df4c2 commit 20d0e69

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src-tauri/src/builder/crossplatform.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
use crate::windows::{has_wsl, windows_to_wsl_path, wsl_to_windows_path};
33
#[cfg(target_os = "windows")]
44
use std::process::{Command, Stdio};
5+
#[cfg(target_os = "windows")]
6+
use std::os::windows::process::CommandExt;
57
use std::{fs, path::PathBuf};
68

9+
#[cfg(target_os = "windows")]
10+
const CREATE_NO_WINDOW: u32 = 0x08000000;
11+
712
pub fn symlink(target: &str, link: &str) -> std::io::Result<()> {
813
#[cfg(not(target_os = "windows"))]
914
{
@@ -24,6 +29,7 @@ pub fn symlink(target: &str, link: &str) -> std::io::Result<()> {
2429
.arg(windows_to_wsl_path(link))
2530
.stdout(Stdio::piped())
2631
.stderr(Stdio::piped())
32+
.creation_flags(CREATE_NO_WINDOW)
2733
.output()
2834
.expect("failed to execute process");
2935
if !output.status.success() {
@@ -52,6 +58,7 @@ pub fn read_link(path: &PathBuf) -> Result<PathBuf, String> {
5258
let output = Command::new("wsl")
5359
.arg("readlink")
5460
.arg(windows_to_wsl_path(&path.to_string_lossy().to_string()))
61+
.creation_flags(CREATE_NO_WINDOW)
5562
.output()
5663
.expect("failed to execute process");
5764
if output.status.success() {
@@ -80,6 +87,7 @@ pub fn linux_env(key: &str) -> Result<String, String> {
8087
let output = Command::new("wsl")
8188
.args(["bash", "-l", "-c"])
8289
.arg(format!("printenv {}", key))
90+
.creation_flags(CREATE_NO_WINDOW)
8391
.output()
8492
.expect("failed to execute process");
8593
if output.status.success() {

src-tauri/src/builder/sdk.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ use crate::operation::Operation;
1515

1616
#[cfg(target_os = "windows")]
1717
use crate::windows::windows_to_wsl_path;
18+
#[cfg(target_os = "windows")]
19+
use std::os::windows::process::CommandExt;
20+
#[cfg(target_os = "windows")]
21+
const CREATE_NO_WINDOW: u32 = 0x08000000;
1822

1923
const DARWIN_TOOLS_VERSION: &str = "1.0.1";
2024

@@ -284,6 +288,7 @@ async fn install_toolset(output_path: &PathBuf) -> Result<(), String> {
284288
.arg("chmod")
285289
.arg("+x")
286290
.arg(format!("{}/*", wsl_toolset_path))
291+
.creation_flags(CREATE_NO_WINDOW)
287292
.output()
288293
.map_err(|e| format!("Failed to run chmod: {}", e))?;
289294
if !output.status.success() {
@@ -325,6 +330,7 @@ async fn install_developer(
325330
windows_to_wsl_path(&xcode_path),
326331
windows_to_wsl_path(&dev_stage.to_string_lossy())
327332
))
333+
.creation_flags(CREATE_NO_WINDOW)
328334
.output();
329335
#[cfg(not(target_os = "windows"))]
330336
let status = Command::new(unxip_path)

src-tauri/src/builder/swift.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#[cfg(target_os = "windows")]
22
use crate::windows::has_wsl;
3+
#[cfg(target_os = "windows")]
4+
use std::os::windows::process::CommandExt;
5+
36
use crate::{
47
builder::{
58
config::{BuildSettings, ProjectConfig},
@@ -19,6 +22,9 @@ use std::{
1922
use tauri::{Emitter, Window};
2023
use tokio::process::Command as TokioCommand;
2124

25+
#[cfg(target_os = "windows")]
26+
const CREATE_NO_WINDOW: u32 = 0x08000000;
27+
2228
#[derive(Serialize, Deserialize, Debug, Clone)]
2329
#[serde(rename_all = "camelCase")]
2430
pub struct ToolchainResult {
@@ -61,6 +67,7 @@ impl SwiftBin {
6167
"-c",
6268
&format!("test -f \"{}/usr/bin/swift\"", toolchain_path),
6369
])
70+
.creation_flags(CREATE_NO_WINDOW)
6471
.output()
6572
.map_err(|e| format!("Failed to execute command: {}", e))?;
6673
if !output.status.success() {
@@ -109,6 +116,7 @@ impl SwiftBin {
109116
.arg(format!("\"{}\" {}", self.bin_path, args.join(" ")))
110117
.stdout(Stdio::piped())
111118
.stderr(Stdio::piped())
119+
.creation_flags(CREATE_NO_WINDOW)
112120
.output()
113121
}
114122
#[cfg(not(target_os = "windows"))]
@@ -126,6 +134,7 @@ impl SwiftBin {
126134
{
127135
let mut cmd = Command::new("wsl");
128136
cmd.arg(&self.bin_path);
137+
cmd.creation_flags(CREATE_NO_WINDOW);
129138
cmd
130139
}
131140
#[cfg(not(target_os = "windows"))]
@@ -139,6 +148,7 @@ impl SwiftBin {
139148
{
140149
let mut cmd = TokioCommand::new("wsl");
141150
cmd.arg(&self.sourcekit_path);
151+
cmd.creation_flags(CREATE_NO_WINDOW);
142152
cmd
143153
}
144154
#[cfg(not(target_os = "windows"))]

src-tauri/src/windows.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::process::{Command, Stdio};
22
#[cfg(target_os = "windows")]
33
use wslpath2::{convert, Conversion};
4+
#[cfg(target_os = "windows")]
5+
use std::os::windows::process::CommandExt;
46

57
#[cfg(target_os = "windows")]
68
pub fn windows_to_wsl_path(path: &str) -> String {
@@ -22,6 +24,7 @@ pub fn has_wsl() -> bool {
2224
.arg("echo")
2325
.arg("1")
2426
.stdout(Stdio::piped())
27+
.creation_flags(0x08000000) // CREATE_NO_WINDOW
2528
.output()
2629
.expect("failed to execute process");
2730

0 commit comments

Comments
 (0)