Skip to content

Commit 464eaeb

Browse files
author
b45632
committed
fix: hide Windows console and improve release workflow
1 parent d035ba1 commit 464eaeb

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ use std::{
1010
use tauri::{AppHandle, Emitter};
1111
use walkdir::WalkDir;
1212

13+
#[cfg(target_os = "windows")]
14+
const CREATE_NO_WINDOW: u32 = 0x08000000;
15+
16+
#[cfg(target_os = "windows")]
17+
fn hide_console_window(command: &mut Command) {
18+
use std::os::windows::process::CommandExt;
19+
command.creation_flags(CREATE_NO_WINDOW);
20+
}
21+
22+
#[cfg(not(target_os = "windows"))]
23+
fn hide_console_window(_command: &mut Command) {}
24+
1325
#[derive(Debug, Serialize)]
1426
#[serde(rename_all = "camelCase")]
1527
struct DetectedScript {
@@ -119,13 +131,14 @@ fn marker_names(path: &Path) -> Vec<String> {
119131
}
120132

121133
fn command_output(path: &Path, program: &str, args: &[&str]) -> Option<String> {
122-
let output = Command::new(program)
134+
let mut command = Command::new(program);
135+
command
123136
.args(args)
124137
.current_dir(path)
125138
.stdin(Stdio::null())
126-
.stderr(Stdio::null())
127-
.output()
128-
.ok()?;
139+
.stderr(Stdio::null());
140+
hide_console_window(&mut command);
141+
let output = command.output().ok()?;
129142

130143
output
131144
.status
@@ -749,13 +762,15 @@ fn create_project_from_template(
749762
}
750763

751764
if init_git && which::which("git").is_ok() {
752-
let _ = Command::new("git")
765+
let mut command = Command::new("git");
766+
command
753767
.args(["init"])
754768
.current_dir(&destination)
755769
.stdin(Stdio::null())
756770
.stdout(Stdio::null())
757-
.stderr(Stdio::null())
758-
.status();
771+
.stderr(Stdio::null());
772+
hide_console_window(&mut command);
773+
let _ = command.status();
759774
}
760775

761776
Ok(CreatedProject {
@@ -1015,7 +1030,7 @@ fn shell_command(script: &str) -> Command {
10151030
use std::os::windows::process::CommandExt;
10161031
let mut command = Command::new("cmd.exe");
10171032
command.args(["/D", "/S", "/C", script]);
1018-
command.creation_flags(0x08000000);
1033+
command.creation_flags(CREATE_NO_WINDOW);
10191034
command
10201035
}
10211036

@@ -1235,11 +1250,14 @@ fn start_process(
12351250
fn stop_process(pid: u32) -> Result<(), String> {
12361251
#[cfg(target_os = "windows")]
12371252
{
1238-
let status = Command::new("taskkill")
1253+
let mut command = Command::new("taskkill");
1254+
command
12391255
.args(["/PID", &pid.to_string(), "/T", "/F"])
12401256
.stdin(Stdio::null())
12411257
.stdout(Stdio::null())
1242-
.stderr(Stdio::null())
1258+
.stderr(Stdio::null());
1259+
hide_console_window(&mut command);
1260+
let status = command
12431261
.status()
12441262
.map_err(|error| format!("Prozess konnte nicht beendet werden: {error}"))?;
12451263
if status.success() {

src-tauri/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2+
13
fn main() {
24
code_deck_lib::run();
35
}

0 commit comments

Comments
 (0)