Skip to content

Commit 549ceee

Browse files
committed
hide console when running git commands on windows
1 parent 2ab3d89 commit 549ceee

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

src-tauri/src/lib.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ use tauri::{command, Manager};
77
use tauri_plugin_window_state::{AppHandleExt, WindowExt, StateFlags};
88
use tokio::process::Command;
99

10+
fn create_hidden_command(program: &str) -> Command {
11+
#[cfg(target_os = "windows")]
12+
{
13+
use std::os::windows::process::CommandExt;
14+
let mut std_cmd = std::process::Command::new(program);
15+
const CREATE_NO_WINDOW: u32 = 0x08000000;
16+
std_cmd.creation_flags(CREATE_NO_WINDOW);
17+
18+
// Convert std::process::Command to tokio::process::Command
19+
Command::from(std_cmd)
20+
}
21+
22+
#[cfg(not(target_os = "windows"))]
23+
{
24+
Command::new(program)
25+
}
26+
}
27+
1028
#[derive(Debug, Serialize, Deserialize)]
1129
pub struct GitHunk {
1230
file_name: String,
@@ -53,7 +71,7 @@ pub struct GitRefs {
5371
}
5472

5573
async fn check_editor_available(cmd: &str, args: &[&str]) -> bool {
56-
Command::new(cmd)
74+
create_hidden_command(cmd)
5775
.args(args)
5876
.stdout(Stdio::piped())
5977
.stderr(Stdio::piped())
@@ -107,11 +125,11 @@ async fn find_available_editor() -> Result<&'static str, String> {
107125

108126
fn build_editor_command(editor: &str, file_path: &str, line_number: Option<u32>) -> Command {
109127
let mut command = if editor == "cmd-code" {
110-
let mut c = Command::new("cmd");
128+
let mut c = create_hidden_command("cmd");
111129
c.arg("/c").arg("code").arg("-r");
112130
c
113131
} else {
114-
Command::new(editor)
132+
create_hidden_command(editor)
115133
};
116134

117135
match editor {
@@ -148,7 +166,7 @@ fn build_editor_command(editor: &str, file_path: &str, line_number: Option<u32>)
148166
}
149167

150168
async fn run_git_command(args: &[&str], directory: &str) -> Result<String, String> {
151-
let output = Command::new("git")
169+
let output = create_hidden_command("git")
152170
.args(args)
153171
.current_dir(directory)
154172
.stdout(Stdio::piped())
@@ -331,7 +349,7 @@ async fn get_git_diff(
331349

332350
// git diff --no-index returns exit code 1 when files differ, which is expected
333351
// So we need to handle this manually instead of using run_git_command_optional
334-
let untracked_diff = Command::new("git")
352+
let untracked_diff = create_hidden_command("git")
335353
.args(&[
336354
"diff",
337355
"--no-index",

src-tauri/tauri.conf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
3-
"productName": "git-diff-viewer",
4-
"version": "1.0.0",
3+
"productName": "Git Diff Viewer",
4+
"version": "1.0.1",
55
"identifier": "com.antriel.git-diff-viewer",
66
"build": {
77
"beforeDevCommand": "npm run dev",
@@ -12,7 +12,7 @@
1212
"app": {
1313
"windows": [
1414
{
15-
"title": "git-diff-viewer",
15+
"title": "Git Diff Viewer",
1616
"width": 800,
1717
"height": 600
1818
}

vite.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const host = process.env.TAURI_DEV_HOST;
88
// https://vite.dev/config/
99
export default defineConfig(async () => ({
1010
plugins: [sveltekit()],
11+
12+
logLevel: 'warn', // Reduce verbose logging
1113

1214
define: {
1315
__APP_VERSION__: JSON.stringify(pkg.version),
@@ -18,6 +20,47 @@ export default defineConfig(async () => ({
1820
__APP_REPOSITORY__: JSON.stringify(pkg.repository.url),
1921
},
2022

23+
build: {
24+
chunkSizeWarningLimit: 5000, // 5MB - Tauri apps don't have web size constraints
25+
commonjsOptions: {
26+
include: [/highlight\.js/, /mark\.js/],
27+
transformMixedEsModules: true,
28+
strictRequires: false
29+
},
30+
rollupOptions: {
31+
onwarn(warning, warn) {
32+
// Suppress CommonJS resolver warnings for known packages
33+
if (warning.code === 'PLUGIN_WARNING' &&
34+
warning.message.includes('commonjs--resolver') &&
35+
warning.message.includes('resolveId')) {
36+
return;
37+
}
38+
warn(warning);
39+
},
40+
plugins: [
41+
{
42+
name: 'silence-commonjs-warnings',
43+
buildStart() {
44+
// Monkey patch console.warn to filter out CommonJS resolver warnings
45+
const originalWarn = console.warn;
46+
console.warn = function(...args) {
47+
const message = args.join(' ');
48+
if (message.includes('[plugin commonjs--resolver]') &&
49+
message.includes('resolveId')) {
50+
return; // Skip this warning
51+
}
52+
originalWarn.apply(console, args);
53+
};
54+
}
55+
}
56+
]
57+
}
58+
},
59+
60+
optimizeDeps: {
61+
include: ['highlight.js', 'mark.js']
62+
},
63+
2164
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
2265
//
2366
// 1. prevent Vite from obscuring rust errors

0 commit comments

Comments
 (0)