From 4f011e6895c5a499173e3aecc5ebd71072cd1d80 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 11 Jun 2020 13:00:24 -0500 Subject: [PATCH] Get Tolk working again. Two Tolk instances were being created. One checked for the presence of a screen reader. The other actually performed the speech, and was returned as part of the `TTS` instance. Unfortunately, Tolk doesn't seem to appreciate being called twice. So here we check if a screen reader is detected and, if one is, return the instance that did the detection. Otherwise, error out and return the WinRT backend. --- src/backends/tolk.rs | 9 ++++++--- src/lib.rs | 17 +++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs index 18ccd13..ae877fc 100644 --- a/src/backends/tolk.rs +++ b/src/backends/tolk.rs @@ -7,11 +7,14 @@ use crate::{Backend, Error, Features}; pub struct Tolk(TolkPtr); impl Tolk { - pub fn new() -> Self { + pub fn new() -> Option { info!("Initializing Tolk backend"); let tolk = TolkPtr::new(); - tolk.try_sapi(true); - Tolk(tolk) + if tolk.detect_screen_reader().is_some() { + Some(Tolk(tolk)) + } else { + None + } } } diff --git a/src/lib.rs b/src/lib.rs index 6a9ca6f..587b20f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,11 @@ impl TTS { #[cfg(windows)] Backends::Tolk => { let tts = backends::Tolk::new(); - Ok(TTS(Box::new(tts))) + if let Some(tts) = tts { + Ok(TTS(Box::new(tts))) + } else { + Err(Error::NoneError) + } } #[cfg(windows)] Backends::WinRT => { @@ -107,13 +111,10 @@ impl TTS { #[cfg(target_os = "linux")] let tts = TTS::new(Backends::SpeechDispatcher); #[cfg(windows)] - let tts = { - let tolk = tolk::Tolk::new(); - if tolk.detect_screen_reader().is_some() { - TTS::new(Backends::Tolk) - } else { - TTS::new(Backends::WinRT) - } + let tts = if let Some(tts) = TTS::new(Backends::Tolk).ok() { + Ok(tts) + } else { + TTS::new(Backends::WinRT) }; #[cfg(target_arch = "wasm32")] let tts = TTS::new(Backends::Web);