From e86df221fa8f9d6796fb7fe59020767d7c806fac Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sun, 14 Jun 2026 20:57:40 +0800
Subject: [PATCH] Fix X-ASR hold pre-capture
---
privatevoice.src/app_live_caption_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/privatevoice.src/app_live_caption_test.go b/privatevoice.src/app_live_caption_test.go
index b8804c1..7dd3a0a 100644
--- a/privatevoice.src/app_live_caption_test.go
+++ b/privatevoice.src/app_live_caption_test.go
@@ -38,6 +38,56 @@
}
}
+func TestHoldPreCaptureUsesEngineCapability(t *testing.T) {
+ a := &App{}
+ a.replaceEngine(holdPreCaptureTestEngine{enabled: true})
+
+ if !a.holdPreCaptureEnabled.Load() {
+ t.Fatal("hold pre-capture should be enabled by engine capability")
+ }
+}
+
+func TestHoldPreCaptureDefaultsToFalse(t *testing.T) {
+ a := &App{}
+ a.replaceEngine(plainTestEngine{})
+
+ if a.holdPreCaptureEnabled.Load() {
+ t.Fatal("hold pre-capture should default to false")
+ }
+}
+
+func TestShouldStartHoldPreCaptureLocked(t *testing.T) {
+ a := &App{}
+ a.holdPreCaptureEnabled.Store(true)
+
+ if !a.shouldStartHoldPreCaptureLocked() {
+ t.Fatal("expected hold pre-capture to start when enabled and idle")
+ }
+
+ a.isRecording = true
+ if a.shouldStartHoldPreCaptureLocked() {
+ t.Fatal("should not pre-capture while already recording")
+ }
+ a.isRecording = false
+
+ a.isStoppingRecording = true
+ if a.shouldStartHoldPreCaptureLocked() {
+ t.Fatal("should not pre-capture while stopping")
+ }
+ a.isStoppingRecording = false
+
+ a.isFreetalking = true
+ if a.shouldStartHoldPreCaptureLocked() {
+ t.Fatal("should not pre-capture while tap recording is active")
+ }
+ a.isFreetalking = false
+
+ a.lastStopTime = time.Now()
+ if a.shouldStartHoldPreCaptureLocked() {
+ t.Fatal("should not pre-capture during post-stop debounce")
+ }
+}
+
func TestStartRecordingIgnoredWhileStoppingRecording(t *testing.T) {
a := &App{isStoppingRecording: true}
@@ -72,3 +122,12 @@
func (e tailCaptureTestEngine) ReleaseTailCaptureDelay() time.Duration {
return e.delay
}
+
+type holdPreCaptureTestEngine struct {
+ plainTestEngine
+ enabled bool
+}
+
+func (e holdPreCaptureTestEngine) HoldPreCaptureEnabled() bool {
+ return e.enabled
+}
--
Gitblit v1.9.3