Fix cmd pop-up on background clipclear on Windows

This commit is contained in:
2026-02-17 20:10:24 -05:00
parent 8da2648664
commit e9f49fb98a
3 changed files with 7 additions and 1 deletions
+7 -1
View File
@@ -5,9 +5,11 @@ package clip
import ( import (
"errors" "errors"
"os/exec" "os/exec"
"syscall"
"github.com/rwinkhart/go-boilerplate/back" "github.com/rwinkhart/go-boilerplate/back"
"github.com/rwinkhart/go-boilerplate/security" "github.com/rwinkhart/go-boilerplate/security"
"golang.org/x/sys/windows"
) )
// CopyBytes copies a byte slice to the clipboard. // CopyBytes copies a byte slice to the clipboard.
@@ -28,7 +30,11 @@ func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
// getClipCommands returns the commands for pasting and clearing the clipboard contents. // getClipCommands returns the commands for pasting and clearing the clipboard contents.
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) { func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
sysProcAttr := &syscall.SysProcAttr{CreationFlags: windows.CREATE_NO_WINDOW}
pasteCMD := exec.Command("powershell.exe", "-c", "Get-Clipboard")
pasteCMD.SysProcAttr = sysProcAttr
clearCMD := exec.Command("clip.exe") clearCMD := exec.Command("clip.exe")
clearCMD.SysProcAttr = sysProcAttr
_ = back.WriteToStdin(clearCMD, nil, false) _ = back.WriteToStdin(clearCMD, nil, false)
return exec.Command("powershell.exe", "-c", "Get-Clipboard"), clearCMD, nil return pasteCMD, clearCMD, nil
} }