Skip to content

Commit

Permalink
windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan committed Nov 20, 2024
1 parent f965c8b commit 8cf4ca9
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions packages/pigeon/example/app/windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

#include "flutter_window.h"

#include <flutter/binary_messenger.h>

#include <memory>
#include <optional>

#include "flutter/generated_plugin_registrant.h"
#include "messages.g.h"

namespace {
using pigeon_example::Code;
using pigeon_example::ErrorOr;
using pigeon_example::ExampleHostApi;
using pigeon_example::FlutterError;
using pigeon_example::MessageData;
using pigeon_example::MessageFlutterApi;

// #docregion cpp-class
class PigeonApiImplementation : public ExampleHostApi {
Expand All @@ -29,14 +35,34 @@ class PigeonApiImplementation : public ExampleHostApi {
}
void SendMessage(const MessageData& message,
std::function<void(ErrorOr<bool> reply)> result) {
if (message.code == Code.kOne) {
if (message.code() == Code::kOne) {
result(FlutterError("code", "message", "details"));
return;
}
result(true);
}
};
// #enddocregion cpp-class

// #docregion cpp-method-flutter
class PigeonFlutterApi {
public:
PigeonFlutterApi(flutter::BinaryMessenger* messenger)
: flutterApi_(std::make_unique<MessageFlutterApi>(messenger)) {}

void CallFlutterMethod(
const std::string& a_string,
std::function<void(ErrorOr<std::string> reply)> result) {
flutterApi_->FlutterMethod(
&a_string, [result](const std::string& echo) { result(echo); },
[result](const FlutterError& error) { result(error); });
}

private:
std::unique_ptr<MessageFlutterApi> flutterApi_;
};
// #enddocregion cpp-method-flutter

} // namespace

FlutterWindow::FlutterWindow(const flutter::DartProject& project)
Expand All @@ -49,15 +75,6 @@ bool FlutterWindow::OnCreate() {
return false;
}

// #docregion cpp-method-flutter
void TestPlugin::CallFlutterMethod(
String aString, std::function<void(ErrorOr<int64_t> reply)> result) {
MessageFlutterApi->FlutterMethod(
aString, [result](String echo) { result(echo); },
[result](const FlutterError& error) { result(error); });
}
// #enddocregion cpp-method-flutter

RECT frame = GetClientArea();

// The size here must match the window dimensions to avoid unnecessary surface
Expand Down

0 comments on commit 8cf4ca9

Please sign in to comment.