main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <flutter/dart_project.h>
  2. #include <flutter/flutter_view_controller.h>
  3. #include <windows.h>
  4. #include "flutter_window.h"
  5. #include "utils.h"
  6. #include <protocol_handler/protocol_handler_plugin.h>
  7. int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
  8. _In_ wchar_t *command_line, _In_ int show_command) {
  9. HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"naiyouwl");
  10. if (hwnd != NULL) {
  11. DispatchToProtocolHandler(hwnd);
  12. ::ShowWindow(hwnd, SW_NORMAL);
  13. ::SetForegroundWindow(hwnd);
  14. return EXIT_FAILURE;
  15. }
  16. // https://github.com/flutter/flutter/issues/47891#issuecomment-708850435
  17. // https://github.com/flutter/flutter/issues/47891#issuecomment-869729956
  18. // https://github.com/dart-lang/sdk/issues/39945#issuecomment-870428151
  19. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
  20. CreateAndAttachConsole();
  21. }
  22. // } else {
  23. // AllocConsole();
  24. // ShowWindow(GetConsoleWindow(), SW_HIDE);
  25. // }
  26. // Initialize COM, so that it is available for use in the library and/or
  27. // plugins.
  28. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  29. flutter::DartProject project(L"data");
  30. std::vector<std::string> command_line_arguments =
  31. GetCommandLineArguments();
  32. project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
  33. FlutterWindow window(project);
  34. Win32Window::Point origin(10, 10);
  35. Win32Window::Size size(1280, 720);
  36. if (!window.Create(L"naiyouwl", origin, size)) {
  37. return EXIT_FAILURE;
  38. }
  39. window.SetQuitOnClose(true);
  40. ::MSG msg;
  41. while (::GetMessage(&msg, nullptr, 0, 0)) {
  42. ::TranslateMessage(&msg);
  43. ::DispatchMessage(&msg);
  44. }
  45. ::CoUninitialize();
  46. return EXIT_SUCCESS;
  47. }