From e7f26ba250e25308a028f65c4d98f5bbed540dc5 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Mon, 25 Mar 2024 22:02:58 +0530 Subject: [PATCH] fix: setup for app_links and window_manager --- auth/windows/runner/flutter_window.cpp | 3 +- auth/windows/runner/main.cpp | 45 ++++++++++++++++++++++++++ auth/windows/runner/win32_window.cpp | 3 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/auth/windows/runner/flutter_window.cpp b/auth/windows/runner/flutter_window.cpp index 955ee3038f..1672f9cbf7 100644 --- a/auth/windows/runner/flutter_window.cpp +++ b/auth/windows/runner/flutter_window.cpp @@ -28,7 +28,8 @@ bool FlutterWindow::OnCreate() { SetChildContent(flutter_controller_->view()->GetNativeWindow()); flutter_controller_->engine()->SetNextFrameCallback([&]() { - this->Show(); + // [window_manager] + // this->Show(); }); // Flutter can complete the first frame before the "show window" callback is diff --git a/auth/windows/runner/main.cpp b/auth/windows/runner/main.cpp index 2fbc969c5c..546bc77e6e 100644 --- a/auth/windows/runner/main.cpp +++ b/auth/windows/runner/main.cpp @@ -5,9 +5,54 @@ #include "flutter_window.h" #include "utils.h" +// [app_links] +#include "app_links/app_links_plugin_c_api.h" +bool SendAppLinkToInstance(const std::wstring &title) +{ + // Find our exact window + HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", title.c_str()); + + if (hwnd) + { + // Dispatch new link to current window + SendAppLink(hwnd); + + // (Optional) Restore our window to front in same state + WINDOWPLACEMENT place = {sizeof(WINDOWPLACEMENT)}; + GetWindowPlacement(hwnd, &place); + + switch (place.showCmd) + { + case SW_SHOWMAXIMIZED: + ShowWindow(hwnd, SW_SHOWMAXIMIZED); + break; + case SW_SHOWMINIMIZED: + ShowWindow(hwnd, SW_RESTORE); + break; + default: + ShowWindow(hwnd, SW_NORMAL); + break; + } + + SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE); + SetForegroundWindow(hwnd); + // END Restore + + // Window has been found, don't create another one. + return true; + } + + return false; +} + int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + // [app_links] + if (SendAppLinkToInstance(L"ente Auth")) + { + return EXIT_SUCCESS; + } // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) diff --git a/auth/windows/runner/win32_window.cpp b/auth/windows/runner/win32_window.cpp index feb7acd3b4..d3e9d1c60a 100644 --- a/auth/windows/runner/win32_window.cpp +++ b/auth/windows/runner/win32_window.cpp @@ -149,7 +149,8 @@ bool Win32Window::Create(const std::wstring &title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW, + window_class, title.c_str(), + WS_OVERLAPPEDWINDOW, // [window_manager] do not add WS_VISIBLE since the window will be shown later Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this);