flowy_board_plugin.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "flowy_board_plugin.h"
  2. // This must be included before many other Windows headers.
  3. #include <windows.h>
  4. // For getPlatformVersion; remove unless needed for your plugin implementation.
  5. #include <VersionHelpers.h>
  6. #include <flutter/method_channel.h>
  7. #include <flutter/plugin_registrar_windows.h>
  8. #include <flutter/standard_method_codec.h>
  9. #include <memory>
  10. #include <sstream>
  11. namespace flowy_board {
  12. // static
  13. void FlowyBoardPlugin::RegisterWithRegistrar(
  14. flutter::PluginRegistrarWindows *registrar) {
  15. auto channel =
  16. std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
  17. registrar->messenger(), "flowy_board",
  18. &flutter::StandardMethodCodec::GetInstance());
  19. auto plugin = std::make_unique<FlowyBoardPlugin>();
  20. channel->SetMethodCallHandler(
  21. [plugin_pointer = plugin.get()](const auto &call, auto result) {
  22. plugin_pointer->HandleMethodCall(call, std::move(result));
  23. });
  24. registrar->AddPlugin(std::move(plugin));
  25. }
  26. FlowyBoardPlugin::FlowyBoardPlugin() {}
  27. FlowyBoardPlugin::~FlowyBoardPlugin() {}
  28. void FlowyBoardPlugin::HandleMethodCall(
  29. const flutter::MethodCall<flutter::EncodableValue> &method_call,
  30. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
  31. if (method_call.method_name().compare("getPlatformVersion") == 0) {
  32. std::ostringstream version_stream;
  33. version_stream << "Windows ";
  34. if (IsWindows10OrGreater()) {
  35. version_stream << "10+";
  36. } else if (IsWindows8OrGreater()) {
  37. version_stream << "8";
  38. } else if (IsWindows7OrGreater()) {
  39. version_stream << "7";
  40. }
  41. result->Success(flutter::EncodableValue(version_stream.str()));
  42. } else {
  43. result->NotImplemented();
  44. }
  45. }
  46. } // namespace flowy_board