Skip to content

Commit 02bdf51

Browse files
committed
fix(toast): stabilize desktop voice toast window
修复 Windows/mac 独立 /toast 页面里的语音准备框与准备完成框计时器竞争。\n\n补齐蓝框与绿框的隐藏定时器管理,并在两者切换时互斥清理,避免旧回调误伤新的提示显示。
1 parent 6d74a0f commit 02bdf51

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

templates/toast.html

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
// ===== Voice Preparing Toast =====
103103
var voiceAnimInjected = false;
104104
var spinAnimInjected = false;
105+
var voicePreparingHideTimer = null;
106+
var voiceReadyToastTimer = null;
107+
var voiceReadyHideTimer = null;
105108

106109
function injectVoiceAnimations() {
107110
if (voiceAnimInjected) return;
@@ -125,6 +128,8 @@
125128
function showVoicePreparing(message) {
126129
injectVoiceAnimations();
127130
injectSpinAnimation();
131+
hideReadyToSpeak();
132+
clearVoicePreparingHideTimer();
128133

129134
var toast = document.getElementById('voice-preparing-toast');
130135
if (!toast) {
@@ -155,11 +160,33 @@
155160
toast.appendChild(span);
156161
}
157162

163+
function clearVoicePreparingHideTimer() {
164+
if (voicePreparingHideTimer) {
165+
clearTimeout(voicePreparingHideTimer);
166+
voicePreparingHideTimer = null;
167+
}
168+
}
169+
170+
function clearVoiceReadyTimers() {
171+
if (voiceReadyToastTimer) {
172+
clearTimeout(voiceReadyToastTimer);
173+
voiceReadyToastTimer = null;
174+
}
175+
if (voiceReadyHideTimer) {
176+
clearTimeout(voiceReadyHideTimer);
177+
voiceReadyHideTimer = null;
178+
}
179+
}
180+
158181
function hideVoicePreparing() {
159182
var toast = document.getElementById('voice-preparing-toast');
160183
if (toast) {
184+
clearVoicePreparingHideTimer();
161185
toast.style.animation = 'voiceToastFadeIn 0.3s ease reverse';
162-
setTimeout(function() { toast.style.display = 'none'; }, 300);
186+
voicePreparingHideTimer = setTimeout(function() {
187+
voicePreparingHideTimer = null;
188+
toast.style.display = 'none';
189+
}, 300);
163190
}
164191
}
165192

@@ -182,8 +209,18 @@
182209
}
183210

184211
// ===== Voice Ready Toast =====
212+
function hideReadyToSpeak() {
213+
var toast = document.getElementById('voice-ready-toast');
214+
if (toast) {
215+
clearVoiceReadyTimers();
216+
toast.style.display = 'none';
217+
}
218+
}
219+
185220
function showReadyToSpeak(message) {
186221
injectVoiceAnimations();
222+
hideVoicePreparing();
223+
clearVoiceReadyTimers();
187224

188225
var toast = document.getElementById('voice-ready-toast');
189226
if (!toast) {
@@ -216,9 +253,13 @@
216253
toast.appendChild(img);
217254
toast.appendChild(span);
218255

219-
setTimeout(function() {
256+
voiceReadyToastTimer = setTimeout(function() {
257+
voiceReadyToastTimer = null;
220258
toast.style.animation = 'voiceToastFadeIn 0.3s ease reverse';
221-
setTimeout(function() { toast.style.display = 'none'; }, 300);
259+
voiceReadyHideTimer = setTimeout(function() {
260+
voiceReadyHideTimer = null;
261+
toast.style.display = 'none';
262+
}, 300);
222263
}, 2000);
223264
}
224265

0 commit comments

Comments
 (0)