diff --git a/src/renderer/src/components/settings/VoiceSpeechModelSection.test.tsx b/src/renderer/src/components/settings/VoiceSpeechModelSection.test.tsx
index b6e061994..4825397fb 100644
--- a/src/renderer/src/components/settings/VoiceSpeechModelSection.test.tsx
+++ b/src/renderer/src/components/settings/VoiceSpeechModelSection.test.tsx
@@ -8,6 +8,7 @@ import type { SpeechModelManifest, SpeechModelState } from '../../../../shared/s
import { getDefaultVoiceSettings } from '../../../../shared/constants'
const toastErrorMock = vi.hoisted(() => vi.fn())
+const menuDismissMock = vi.hoisted(() => vi.fn())
vi.mock('sonner', () => ({
toast: {
@@ -32,7 +33,7 @@ vi.mock('../ui/dropdown-menu', () => ({
}: {
children: ReactNode
disabled?: boolean
- onSelect?: () => void
+ onSelect?: (event: Event) => void
className?: string
}) => (
({
role="option"
onClick={() => {
if (!disabled) {
- onSelect?.()
+ const selectEvent = new Event('select', { cancelable: true })
+ onSelect?.(selectEvent)
+ if (!selectEvent.defaultPrevented) {
+ menuDismissMock()
+ }
}
}}
>
@@ -73,6 +78,7 @@ const secondLocalModel: SpeechModelManifest = {
function renderSection(args: {
deleteModel: (modelId: string) => Promise
+ downloadModel?: (modelId: string) => Promise
catalog?: SpeechModelManifest[]
modelStates?: SpeechModelState[]
refreshModelStates?: () => void
@@ -81,7 +87,7 @@ function renderSection(args: {
api: {
speech: {
deleteModel: vi.fn(args.deleteModel),
- downloadModel: vi.fn()
+ downloadModel: vi.fn(args.downloadModel ?? (() => Promise.resolve()))
}
}
})
@@ -111,6 +117,7 @@ function renderSection(args: {
describe('VoiceSpeechModelSection', () => {
beforeEach(() => {
toastErrorMock.mockReset()
+ menuDismissMock.mockReset()
})
afterEach(() => {
@@ -218,4 +225,21 @@ describe('VoiceSpeechModelSection', () => {
expect(refreshModelStates).not.toHaveBeenCalled()
root.unmount()
})
+
+ it('keeps the model menu open when starting a local model download', async () => {
+ const { container, root } = renderSection({
+ deleteModel: () => Promise.resolve(),
+ modelStates: [{ id: localModel.id, status: 'not-downloaded' }]
+ })
+ const modelOption = container.querySelector('[role="option"]')
+
+ await act(async () => {
+ modelOption!.dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ await Promise.resolve()
+ })
+
+ expect(window.api.speech.downloadModel).toHaveBeenCalledWith(localModel.id)
+ expect(menuDismissMock).not.toHaveBeenCalled()
+ root.unmount()
+ })
})
diff --git a/src/renderer/src/components/settings/VoiceSpeechModelSection.tsx b/src/renderer/src/components/settings/VoiceSpeechModelSection.tsx
index 0380bbc0c..ea96c68fd 100644
--- a/src/renderer/src/components/settings/VoiceSpeechModelSection.tsx
+++ b/src/renderer/src/components/settings/VoiceSpeechModelSection.tsx
@@ -82,12 +82,14 @@ export function VoiceSpeechModelSection({
{
+ onSelect={(event) => {
if (isReady) {
onUpdateVoiceSettings({ sttModel: manifest.id })
} else if (isCloud) {
onOpenOpenAiDialog(manifest.id)
} else if (!isDownloading) {
+ // Why: download progress appears in this menu, so starting one should not dismiss it.
+ event.preventDefault()
void window.api.speech
.downloadModel(manifest.id)
.catch(() =>