flutter_window.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef RUNNER_FLUTTER_WINDOW_H_
  2. #define RUNNER_FLUTTER_WINDOW_H_
  3. #include <flutter/dart_project.h>
  4. #include <flutter/flutter_view_controller.h>
  5. #include <flutter/method_channel.h>
  6. #include <flutter/standard_method_codec.h>
  7. #include <memory>
  8. #include "win32_window.h"
  9. #include "tray_icon.h"
  10. // A window that does nothing but host a Flutter view.
  11. class FlutterWindow : public Win32Window {
  12. public:
  13. // Creates a new FlutterWindow hosting a Flutter view running |project|.
  14. explicit FlutterWindow(const flutter::DartProject& project);
  15. virtual ~FlutterWindow();
  16. public:
  17. void SetMinimumSize(SIZE size);
  18. // App Events handler
  19. void onHideWindow();
  20. void onShowWindow();
  21. void onToggleWindow();
  22. void onActiveWindow();
  23. // Tray Events handler
  24. void onTrayIconLButtonDown();
  25. void onTrayIconLButtonUp();
  26. void onTrayIconRButtonDown();
  27. void onTrayIconRButtonUp();
  28. protected:
  29. // Win32Window:
  30. bool OnCreate() override;
  31. void OnDestroy() override;
  32. LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
  33. LPARAM const lparam) noexcept override;
  34. private:
  35. void createMenu(HMENU menu, flutter::EncodableMap args);
  36. std::optional<LRESULT> handleMessage(HWND window, UINT const message,
  37. WPARAM const wparam, LPARAM const lparam);
  38. void registerMethodChannel(flutter::FlutterEngine* engine);
  39. void handleAppMethodCall(
  40. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  41. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  42. void handleTrayMethodCall(
  43. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  44. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  45. void setSystemTray(
  46. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  47. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  48. void resetSystemTray(
  49. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  50. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  51. void setContextMenu(
  52. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  53. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  54. void popUpContextMenu(
  55. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  56. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  57. void extractFileIcon(
  58. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  59. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  60. void getFileDescription(
  61. const flutter::MethodCall<flutter::EncodableValue>& method_call,
  62. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
  63. private:
  64. SIZE min_window_size_ = {0, 0};
  65. // The project to run.
  66. flutter::DartProject project_;
  67. // The Flutter instance hosted by this window.
  68. std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
  69. // The system tray
  70. TrayIcon m_tray;
  71. HMENU m_menuHandle;
  72. };
  73. #endif // RUNNER_FLUTTER_WINDOW_H_