Repository: flutter
Issue: How to keep a cached instance of the FlutterEngine on macOS
Labels: engine,platform-mac,has reproducible steps,P2,found in release: 3.3,found in release: 3.5,team-engine,triaged-engine

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Problem

I am trying to use Flutter as a status bar application for macOS, an application that is bound to a status bar button that shows a `NSPopover` when pressed. But the problem I am having is that when I run my application it initially starts correctly but once I open the `NSPopover`, which has a `FlutterViewController` attached, and close it after the whole process gets killed.

It seems this is happening because the `FlutterViewController` holds the `FlutterEngine` and when it gets disposed, so will the engine.

On iOS we can create a new instance of a `FlutterViewController` by passing our instance of an engine to it as seen [here](https://docs.flutter.dev/development/add-to-app/ios/add-flutter-screen?tab=vc-swift-tab) but on macOS it seems we can't.

On top of that the `RegisterGeneratedPlugins` expects a registry on macOS while on iOS we can just pass the engine. Having access to the engine and caching it would allow me to keep the current state and just recreate the window whenever my users press the action bar button.

I have created an [example repo](https://github.com/wolfenrain/flutter_in_status_bar) that works sort off. It keeps a `NSWindow` alive and therefore the process wont be killed and magically the engine instance, I assume that Flutter binds to the `NSWindow` and it also has an engine instance running.

## Steps to Reproduce

1. Clone the above repo
2. Delete line 16 to 18 in [AppDelegate](https://github.com/wolfenrain/flutter_in_status_bar/blob/main/macos/Runner/AppDelegate.swift#L16)
3. Remove the window section from [MainMenu.xib](https://github.com/wolfenrain/flutter_in_status_bar/blob/main/macos/Runner/Base.lproj/MainMenu.xib#L333)
4. Run the application  in debug mode on a MacBook, it will infinitely wait for an attach
5. A button will appear in your status bar called `Flutter Demo`, click it
6. The Flutter process will finally attach and you see a popover
7. Click outside of it, the popover and button in the statusbar disappears and the debug process is killed

**Expected results:** That the process was still running, because I was able to hold an instance of the engine

**Actual results:** The process gets killed because the view controller, that holds the engine, got disposed

<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->