Fix windows deep link

This commit is contained in:
problematicconsumer
2024-01-10 17:28:08 +03:30
parent 6dcae6cff1
commit 3673689e32
8 changed files with 67 additions and 31 deletions

View File

@@ -4,6 +4,7 @@
#include <flutter_windows.h>
#include "resource.h"
#include <protocol_handler/protocol_handler_plugin.h>
namespace {
@@ -123,6 +124,11 @@ Win32Window::~Win32Window() {
bool Win32Window::Create(const std::wstring& title,
const Point& origin,
const Size& size) {
if (SendAppLinkToInstance(title))
{
return false;
}
Destroy();
const wchar_t* window_class =
@@ -155,6 +161,44 @@ bool Win32Window::Show() {
return ShowWindow(window_handle_, SW_SHOWNORMAL);
}
bool Win32Window::SendAppLinkToInstance(const std::wstring &title)
{
// Find our exact window
HWND hwnd = ::FindWindow(kWindowClassName, title.c_str());
if (hwnd)
{
// Dispatch new link to current window
DispatchToProtocolHandler(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);
// Window has been found, don't create another one.
return true;
}
return false;
}
// static
LRESULT CALLBACK Win32Window::WndProc(HWND const window,
UINT const message,