main.cpp 1.9 KB

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