Skip to content

Commit

Permalink
Merge pull request #336 from arene-os-services-cockpit-tmc-wa/jw/keyh…
Browse files Browse the repository at this point in the history
…ook_send_event_fix

KeyboardHook segfault fix
  • Loading branch information
Joel Winarske authored and GitHub Enterprise committed Dec 17, 2024
2 parents 639cb72 + c564160 commit bd892a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions shell/platform/homescreen/flutter_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@ std::future<bool> PostMessengerSendWithReply(
void* user_data) {
const auto promise(std::make_shared<std::promise<bool>>());
auto promise_future(promise->get_future());
const auto flutter_engine = messenger->GetEngine()->flutter_engine;
post(*messenger->GetEngine()->platform_task_runner->GetStrandContext(),
[&, promise, channel, message, message_size, reply, user_data]() {
[flutter_engine, promise, channel, message, message_size, reply,
user_data]() {
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
if (reply != nullptr && user_data != nullptr) {
const FlutterEngineResult result =
LibFlutterEngine->PlatformMessageCreateResponseHandle(
messenger->GetEngine()->flutter_engine, reply, user_data,
&response_handle);
flutter_engine, reply, user_data, &response_handle);
if (result != kSuccess) {
spdlog::error("Failed to create response handle");
promise->set_value(false);
Expand All @@ -184,13 +185,12 @@ std::future<bool> PostMessengerSendWithReply(
platform_message->response_handle = response_handle;

const FlutterEngineResult message_result =
LibFlutterEngine->SendPlatformMessage(
messenger->GetEngine()->flutter_engine,
platform_message.release());
LibFlutterEngine->SendPlatformMessage(flutter_engine,
platform_message.release());

if (response_handle != nullptr) {
LibFlutterEngine->PlatformMessageReleaseResponseHandle(
messenger->GetEngine()->flutter_engine, response_handle);
flutter_engine, response_handle);
}

promise->set_value(message_result == kSuccess);
Expand All @@ -204,8 +204,8 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,
const size_t message_size,
const FlutterDesktopBinaryReply reply,
void* user_data) {
auto task_runner = messenger->GetEngine()->platform_task_runner;
if (task_runner->IsThreadEqual(pthread_self())) {
if (const auto task_runner = messenger->GetEngine()->platform_task_runner;
task_runner->IsThreadEqual(pthread_self())) {
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
if (reply != nullptr && user_data != nullptr) {
const FlutterEngineResult result =
Expand Down
1 change: 1 addition & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_subdirectory(cxxopts)
# tomlplusplus
#
add_subdirectory(tomlplusplus)
target_compile_options(tomlplusplus_tomlplusplus INTERFACE -Wno-conversion)

#
# Vulkan-Headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <iostream>
#include <string>
#include <utility>

#include "binary_messenger.h"
#include "message_codec.h"
Expand Down Expand Up @@ -37,9 +38,9 @@ class BasicMessageChannel {
// Creates an instance that sends and receives method calls on the channel
// named |name|, encoded with |codec| and dispatched via |messenger|.
BasicMessageChannel(BinaryMessenger* messenger,
const std::string& name,
std::string name,
const MessageCodec<T>* codec)
: messenger_(messenger), name_(name), codec_(codec) {}
: messenger_(messenger), name_(std::move(name)), codec_(codec) {}

~BasicMessageChannel() = default;

Expand All @@ -49,16 +50,16 @@ class BasicMessageChannel {

// Sends a message to the Flutter engine on this channel.
void Send(const T& message) {
std::unique_ptr<std::vector<uint8_t>> raw_message =
const std::unique_ptr<std::vector<uint8_t>> raw_message =
codec_->EncodeMessage(message);
messenger_->Send(name_, raw_message->data(), raw_message->size());
}

// Sends a message to the Flutter engine on this channel expecting a reply.
void Send(const T& message, BinaryReply reply) {
std::unique_ptr<std::vector<uint8_t>> raw_message =
const std::unique_ptr<std::vector<uint8_t>> raw_message =
codec_->EncodeMessage(message);
messenger_->Send(name_, raw_message->data(), raw_message->size(), reply);
messenger_->Send(name_, raw_message->data(), raw_message->size(), std::move(reply));
}

// Registers a handler that should be called any time a message is
Expand All @@ -77,7 +78,7 @@ class BasicMessageChannel {
BinaryMessageHandler binary_handler = [handler, codec, channel_name](
const uint8_t* binary_message,
const size_t binary_message_size,
BinaryReply binary_reply) {
const BinaryReply& binary_reply) {
// Use this channel's codec to decode the message and build a reply
// handler.
std::unique_ptr<T> message =
Expand Down

0 comments on commit bd892a6

Please sign in to comment.