Skip to content

Commit 8b7b454

Browse files
author
sowens-csd
committed
feat: first attempt at foreground thread Windows
1 parent b21260c commit 8b7b454

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

speech_to_text_windows/windows/speech_to_text_windows_plugin.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ void SpeechToTextWindowsPlugin::RegisterWithRegistrar(
2424

2525
auto plugin = std::make_unique<SpeechToTextWindowsPlugin>();
2626
plugin->m_channel = std::move(channel);
27-
27+
plugin->m_registrar = registrar;
28+
2829
plugin->m_channel->SetMethodCallHandler(
2930
[plugin_pointer = plugin.get()](const auto &call, auto result) {
3031
plugin_pointer->HandleMethodCall(call, std::move(result));
@@ -330,12 +331,14 @@ void SpeechToTextWindowsPlugin::GetLocales(
330331
}
331332

332333
void SpeechToTextWindowsPlugin::SendTextRecognition(const std::string& text, bool is_final) {
333-
if (m_channel) {
334+
if (m_channel && m_registrar) {
334335
std::string json_result = "{\"alternates\":[{\"recognizedWords\":\"" + text +
335336
"\",\"confidence\":0.85}],\"resultType\":" + (is_final ? std::to_string(FINAL_RESULT) : std::to_string(PARTIAL_RESULT)) + "}";
336337
std::cout << "Sending to Flutter: " << json_result << std::endl;
337-
m_channel->InvokeMethod("textRecognition",
338-
std::make_unique<flutter::EncodableValue>(json_result));
338+
m_registrar->GetTaskRunner()->PostTask([channel = m_channel, json_result]() {
339+
channel->InvokeMethod("textRecognition",
340+
std::make_unique<flutter::EncodableValue>(json_result));
341+
});
339342
}
340343
}
341344

speech_to_text_windows/windows/speech_to_text_windows_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SpeechToTextWindowsPlugin : public flutter::Plugin {
5050
bool m_listening;
5151

5252
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> m_channel;
53+
flutter::PluginRegistrarWindows* m_registrar;
5354
};
5455

5556
} // namespace speech_to_text_windows

0 commit comments

Comments
 (0)