From f36e553a0e719ba0391912c01b7de69cdbd1c08c Mon Sep 17 00:00:00 2001 From: helgoboss Date: Mon, 6 Nov 2023 05:48:59 +0100 Subject: [PATCH] macOS: Obtain NSWindow from FlutterPluginRegistrar (#298) This makes desktop_drop work even if Flutter is embedded into another application. In that case, the Flutter NSWindow is not the application main window. --- packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift b/packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift index ba2ac5bb..655b915f 100644 --- a/packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift +++ b/packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift @@ -19,8 +19,8 @@ private func findFlutterViewController(_ viewController: NSViewController?) -> F public class DesktopDropPlugin: NSObject, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { - guard let app = NSApplication.shared.delegate as? FlutterAppDelegate else { return } - guard let flutterWindow = app.mainFlutterWindow else { return } + guard let flutterView = registrar.view else { return } + guard let flutterWindow = flutterView.window else { return } guard let vc = findFlutterViewController(flutterWindow.contentViewController) else { return } let channel = FlutterMethodChannel(name: "desktop_drop", binaryMessenger: registrar.messenger)