tam thoi
This commit is contained in:
@@ -2,5 +2,8 @@
|
||||
|
||||
package guard
|
||||
|
||||
import "time"
|
||||
|
||||
func Start(onViolation func(reason string)) {}
|
||||
func Stop() {}
|
||||
func SuppressFor(_ time.Duration) {}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user