main.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
  7. _In_ wchar_t *command_line, _In_ int show_command)
  8. {
  9. HANDLE hMutexInstance = CreateMutex(NULL, TRUE, L"AppFlowyMutex");
  10. HWND handle = FindWindowA(NULL, "AppFlowy");
  11. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  12. WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
  13. GetWindowPlacement(handle, &place);
  14. ShowWindow(handle, SW_NORMAL);
  15. return 0;
  16. }
  17. // Attach to console when present (e.g., 'flutter run') or create a
  18. // new console when running with a debugger.
  19. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent())
  20. {
  21. CreateAndAttachConsole();
  22. }
  23. // Initialize COM, so that it is available for use in the library and/or
  24. // plugins.
  25. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  26. flutter::DartProject project(L"data");
  27. std::vector<std::string> command_line_arguments =
  28. GetCommandLineArguments();
  29. project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
  30. FlutterWindow window(project);
  31. Win32Window::Point origin(10, 10);
  32. Win32Window::Size size(1280, 720);
  33. if (!window.CreateAndShow(L"AppFlowy", origin, size))
  34. {
  35. return EXIT_FAILURE;
  36. }
  37. window.SetQuitOnClose(true);
  38. ::MSG msg;
  39. while (::GetMessage(&msg, nullptr, 0, 0))
  40. {
  41. ::TranslateMessage(&msg);
  42. ::DispatchMessage(&msg);
  43. }
  44. ::CoUninitialize();
  45. ReleaseMutex(hMutexInstance);
  46. return EXIT_SUCCESS;
  47. }