diff --git a/Overlord-Client/cmd/agent/capture/backstage_kill_windows_test.go b/Overlord-Client/cmd/agent/capture/backstage_kill_windows_test.go new file mode 100644 index 0000000..ba66814 --- /dev/null +++ b/Overlord-Client/cmd/agent/capture/backstage_kill_windows_test.go @@ -0,0 +1,27 @@ +//go:build windows + +package capture + +import "testing" + +func TestBackstageShouldKillPID(t *testing.T) { + const currentPID uint32 = 42 + + tests := []struct { + name string + pid uint32 + want bool + }{ + {name: "invalid pid", pid: 0, want: false}, + {name: "agent process", pid: currentPID, want: false}, + {name: "backstage process", pid: 99, want: true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := backstageShouldKillPID(tt.pid, currentPID); got != tt.want { + t.Fatalf("backstageShouldKillPID(%d, %d) = %v, want %v", tt.pid, currentPID, got, tt.want) + } + }) + } +} diff --git a/Overlord-Client/cmd/agent/capture/backstage_windows.go b/Overlord-Client/cmd/agent/capture/backstage_windows.go index 0293371..19adfc1 100644 --- a/Overlord-Client/cmd/agent/capture/backstage_windows.go +++ b/Overlord-Client/cmd/agent/capture/backstage_windows.go @@ -7,6 +7,7 @@ import ( "image" "log" "math" + "os" "runtime" "strings" "sync" @@ -653,6 +654,7 @@ func BackstageKillAll() error { return fmt.Errorf("backstage desktop not initialized") } + currentPID := uint32(os.Getpid()) pids := make(map[uint32]struct{}) cb := syscall.NewCallback(func(hwnd, _ uintptr) uintptr { if backstageIsDWMHost(hwnd) { @@ -660,7 +662,7 @@ func BackstageKillAll() error { } var pid uint32 procGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid))) - if pid != 0 { + if backstageShouldKillPID(pid, currentPID) { pids[pid] = struct{}{} } return 1 // continue enumeration @@ -681,6 +683,10 @@ func BackstageKillAll() error { return nil } +func backstageShouldKillPID(pid, currentPID uint32) bool { + return pid != 0 && pid != currentPID +} + func BackstageAutoStartExplorer() error { if backstageExplorerStarted { return nil