fix: separate voice credentials and refresh feature toggle

This commit is contained in:
2026-08-11 17:46:56 +08:00
parent fd2da26d10
commit 74213a363f
10 changed files with 97 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Mic, Send, Square, X } from "@lucide/vue";
import { nextTick, onMounted, ref } from "vue";
import { nextTick, onMounted, onUnmounted, ref } from "vue";
import { useVoiceRecorder } from "../composables/useVoiceRecorder";
import { api, transcribeVoice } from "../services/api";
@@ -37,7 +37,7 @@ const { recording, elapsedSeconds, start: startRecording, stop: stopRecording, c
},
);
onMounted(async () => {
async function refreshVoiceConfig() {
try {
const config = await api.voiceConfig();
voiceEnabled.value = config.enabled;
@@ -45,6 +45,25 @@ onMounted(async () => {
} catch {
voiceEnabled.value = false;
}
}
function refreshVoiceConfigWhenVisible() {
if (document.visibilityState === "visible") void refreshVoiceConfig();
}
let voiceConfigTimer: number | undefined;
onMounted(() => {
void refreshVoiceConfig();
window.addEventListener("focus", refreshVoiceConfigWhenVisible);
document.addEventListener("visibilitychange", refreshVoiceConfigWhenVisible);
voiceConfigTimer = window.setInterval(refreshVoiceConfigWhenVisible, 30_000);
});
onUnmounted(() => {
window.removeEventListener("focus", refreshVoiceConfigWhenVisible);
document.removeEventListener("visibilitychange", refreshVoiceConfigWhenVisible);
if (voiceConfigTimer !== undefined) window.clearInterval(voiceConfigTimer);
});
function resize() {