//go:build windows package main import ( "context" "fmt" "os" "os/exec" "golang.org/x/sys/windows" ) const createNoWindow = 0x08000000 // newGitCmd crée une commande git sans fenêtre console. func newGitCmd(ctx context.Context, args []string, cwd string) *exec.Cmd { cmd := exec.CommandContext(ctx, "git", args...) if cwd != "" { cmd.Dir = cwd } cmd.SysProcAttr = &windows.SysProcAttr{ CreationFlags: createNoWindow, } return cmd } // relaunchAfterUpdate crée un batch qui attend 1s, relance l'exe et nettoie le .old. func relaunchAfterUpdate(exePath string) { oldPath := exePath + ".old" batPath := exePath + "_update.bat" content := fmt.Sprintf( "@echo off\r\ntimeout /t 1 /nobreak >nul\r\nstart \"\" \"%s\"\r\ndel \"%s\" 2>nul\r\ndel \"%%~f0\"\r\n", exePath, oldPath, ) os.WriteFile(batPath, []byte(content), 0644) cmd := exec.Command("cmd", "/c", batPath) cmd.SysProcAttr = &windows.SysProcAttr{CreationFlags: createNoWindow} cmd.Start() }