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.
This commit is contained in:
Nolan Darilek 2020-06-11 13:00:24 -05:00
parent e0863c7b6a
commit 4f011e6895
2 changed files with 15 additions and 11 deletions

View File

@ -7,11 +7,14 @@ use crate::{Backend, Error, Features};
pub struct Tolk(TolkPtr); pub struct Tolk(TolkPtr);
impl Tolk { impl Tolk {
pub fn new() -> Self { pub fn new() -> Option<Self> {
info!("Initializing Tolk backend"); info!("Initializing Tolk backend");
let tolk = TolkPtr::new(); let tolk = TolkPtr::new();
tolk.try_sapi(true); if tolk.detect_screen_reader().is_some() {
Tolk(tolk) Some(Tolk(tolk))
} else {
None
}
} }
} }

View File

@ -93,7 +93,11 @@ impl TTS {
#[cfg(windows)] #[cfg(windows)]
Backends::Tolk => { Backends::Tolk => {
let tts = backends::Tolk::new(); 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)] #[cfg(windows)]
Backends::WinRT => { Backends::WinRT => {
@ -107,13 +111,10 @@ impl TTS {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let tts = TTS::new(Backends::SpeechDispatcher); let tts = TTS::new(Backends::SpeechDispatcher);
#[cfg(windows)] #[cfg(windows)]
let tts = { let tts = if let Some(tts) = TTS::new(Backends::Tolk).ok() {
let tolk = tolk::Tolk::new(); Ok(tts)
if tolk.detect_screen_reader().is_some() { } else {
TTS::new(Backends::Tolk) TTS::new(Backends::WinRT)
} else {
TTS::new(Backends::WinRT)
}
}; };
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
let tts = TTS::new(Backends::Web); let tts = TTS::new(Backends::Web);