Skip to content
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
17 changes: 13 additions & 4 deletions windows/window_manager_plus_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/window_manager_plus/window_manager_plus_plugin.h"
#include "include/window_manager_plus/window_manager_plus_plugin.h"

// This must be included before many other Windows headers.
#include <windows.h>
Expand Down Expand Up @@ -455,13 +455,22 @@ void WindowManagerPlusPlugin::HandleMethodCall(

if (method_name.compare("ensureInitialized") == 0) {
if (windowId >= 0) {
// if this method is called when window manager already exists, this may be due to a hot restart in flutter.
// Clear the old channel if applicable.
auto it = WindowManagerPlus::windowManagers_.find(windowId);
if (it != WindowManagerPlus::windowManagers_.end()) {
auto existing_manager = it->second;
if (existing_manager->channel) {
existing_manager->channel->SetMethodCallHandler(nullptr);
existing_manager->channel.reset(); // clear old channel
}
}

window_manager->id = windowId;
window_manager->native_window =
::GetAncestor(registrar->GetView()->GetNativeWindow(), GA_ROOT);

if (window_manager->channel) {
window_manager->channel->SetMethodCallHandler(nullptr);
}
// create new channel
window_manager->channel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(),
Expand Down