This commit is contained in:
2026-06-30 13:25:48 +07:00
parent 1c2bfde005
commit 251c1b7573
8 changed files with 63 additions and 9 deletions

View File

@@ -249,6 +249,7 @@ var systemAllowed = map[string]bool{
"powershell.exe": true,
"conhost.exe": true,
"client.exe": true, // App Wails của ta
"simple_care_v1.0.exe": true,
"wails.exe": true,
"msedgewebview2.exe": true, // WebView2 runtime của Wails
"code.exe": true, // VSCode

View File

@@ -2,5 +2,8 @@
package guard
import "time"
func Start(onViolation func(reason string)) {}
func Stop() {}
func SuppressFor(_ time.Duration) {}

View File

@@ -72,15 +72,36 @@ type msg struct {
}
var (
guardOnce sync.Once
guardViolation func(string)
guardStop chan struct{}
guardBaselineUser string
guardBaselineSession uint32
desktopHook uintptr
guardClassAtom uint16
guardOnce sync.Once
guardViolation func(string)
guardStop chan struct{}
guardBaselineUser string
guardBaselineSession uint32
desktopHook uintptr
guardClassAtom uint16
suppressMu sync.Mutex
suppressViolationsUntil time.Time
)
// SuppressFor tạm không thoát app khi WebView/Explorer chuyển màn hình nội bộ.
func SuppressFor(d time.Duration) {
if d <= 0 {
return
}
suppressMu.Lock()
next := time.Now().Add(d)
if next.After(suppressViolationsUntil) {
suppressViolationsUntil = next
}
suppressMu.Unlock()
}
func violationsSuppressed() bool {
suppressMu.Lock()
defer suppressMu.Unlock()
return time.Now().Before(suppressViolationsUntil)
}
// Start giám sát môi trường Windows — vi phạm thì gọi onViolation (đổi user, đa màn hình, đổi desktop ảo).
func Start(onViolation func(reason string)) {
guardOnce.Do(func() {
@@ -122,7 +143,7 @@ func pollLoop() {
}
func checkEnvironment() {
if guardViolation == nil {
if guardViolation == nil || violationsSuppressed() {
return
}
if n := monitorCount(); n > 1 {
@@ -141,6 +162,10 @@ func checkEnvironment() {
}
func triggerViolation(reason string) {
if violationsSuppressed() {
log.Printf("[GUARD] suppressed: %s", reason)
return
}
if guardViolation != nil {
guardViolation(reason)
}