Skip to content

Commit

Permalink
macOS: Obtain NSWindow from FlutterPluginRegistrar (#298)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
helgoboss committed Nov 6, 2023
1 parent 68dad7b commit f36e553
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/desktop_drop/macos/Classes/DesktopDropPlugin.swift
Expand Up @@ -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)
Expand Down

0 comments on commit f36e553

Please sign in to comment.