Implement screen reader detection for everything but Android.

Android support is waiting on Godot 3.2.2 when the new plugin system lands.
This commit is contained in:
Nolan Darilek 2020-05-19 08:56:41 -05:00
parent 4495b89ff3
commit aa718c5fe6
3 changed files with 40 additions and 4 deletions

View File

@ -10,3 +10,6 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
gdnative = "0.8" gdnative = "0.8"
tts = { git = "https://gitlab.com/ndarilek/tts-rs" } tts = { git = "https://gitlab.com/ndarilek/tts-rs" }
[target.'cfg(windows)'.dependencies]
tolk = "0.2"

22
TTS.gd
View File

@ -127,13 +127,27 @@ func get_is_rate_supported():
var is_rate_supported setget , get_is_rate_supported var is_rate_supported setget , get_is_rate_supported
func get_can_detect_screen_reader(): func _get_can_detect_screen_reader():
if OS.get_name() == "Windows": if Engine.has_singleton("AndroidTTS"):
return true return true
else: elif OS.has_feature('JavaScript'):
return false return false
elif tts != null:
return tts.can_detect_screen_reader
return false
var can_detect_screen_reader setget , get_can_detect_screen_reader var can_detect_screen_reader setget , _get_can_detect_screen_reader
func _get_has_screen_reader():
if Engine.has_singleton("AndroidTTS"):
return tts.has_screen_reader()
elif OS.has_feature('JavaScript'):
return false
elif tts != null:
return tts.has_screen_reader
return false
var has_screen_reader setget , _get_has_screen_reader
func singular_or_plural(count, singular, plural): func singular_or_plural(count, singular, plural):
if count == 1: if count == 1:

View File

@ -79,6 +79,25 @@ impl TTS {
} }
}) })
.done(); .done();
builder
.add_property("can_detect_screen_reader")
.with_getter(|_: &TTS, _| {
#[cfg(windows)]
return true;
return false;
})
.done();
builder
.add_property("has_screen_reader")
.with_getter(|_: &TTS, _| {
#[cfg(windows)]
{
let tolk = tolk::Tolk::new();
tolk.detect_screen_reader().is_some()
}
false
})
.done();
} }
#[export] #[export]