fix: catch get voice error

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-24 17:22:26 +08:00
parent f7afd373de
commit aefe8d9e32
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 16 additions and 3 deletions

View File

@ -45,9 +45,22 @@ export const readerRoute = {
}
}),
getVoices: t.procedure.action(async () => {
const voices = await tts.getVoices()
return voices
getVoices: t.procedure.action(async ({ context: { sender } }) => {
const window = BrowserWindow.fromWebContents(sender)
try {
const voices = await tts.getVoices()
return voices
} catch (error: any) {
if (!window) {
return
}
callGlobalContextMethod(window, "toast.error", [
error.message,
{
duration: 1000,
},
])
}
}),
setVoice: t.procedure.input<string>().action(async ({ input, context: { sender } }) => {