Skip to content

Fix crash when using window_manager by multiwin on windows platform #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/window_manager/windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ bool IsWindows11OrGreater() {
return dwBuild < 22000;
}

std::unique_ptr<
flutter::MethodChannel<flutter::EncodableValue>,
std::default_delete<flutter::MethodChannel<flutter::EncodableValue>>>
channel = nullptr;

class WindowManagerPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar);
Expand All @@ -45,6 +40,12 @@ class WindowManagerPlugin : public flutter::Plugin {
virtual ~WindowManagerPlugin();

private:
std::unique_ptr<
flutter::MethodChannel<flutter::EncodableValue>,
std::default_delete<flutter::MethodChannel<flutter::EncodableValue>>>
channel = nullptr;


WindowManager* window_manager;
flutter::PluginRegistrarWindows* registrar;

Expand Down Expand Up @@ -95,17 +96,8 @@ class WindowManagerPlugin : public flutter::Plugin {
// static
void WindowManagerPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarWindows* registrar) {
channel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "window_manager",
&flutter::StandardMethodCodec::GetInstance());

auto plugin = std::make_unique<WindowManagerPlugin>(registrar);

channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto& call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
});

registrar->AddPlugin(std::move(plugin));
}

Expand All @@ -117,6 +109,14 @@ WindowManagerPlugin::WindowManagerPlugin(
[this](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
return HandleWindowProc(hWnd, message, wParam, lParam);
});
channel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "window_manager",
&flutter::StandardMethodCodec::GetInstance());

channel->SetMethodCallHandler(
[this](const auto& call, auto result) {
HandleMethodCall(call, std::move(result));
});
}

WindowManagerPlugin::~WindowManagerPlugin() {
Expand Down