How do I use NotificationCenter in mac catalyst to detect and connect an external display?

I can successfully connect and show ExternalView() on the external display on IOS target.

However, mac catalyst is unable to detect the display connection in NotificationCenter.

How do I use NotificationCenter in mac catalyst to detect and connect an external display?

import Combine
import SwiftUI

@main
struct ScreensApp: App {

  @ObservedObject var externalDisplayContent = ExternalDisplayContent()
  @State var additionalWindows: [UIWindow] = []

  private var screenDidConnectPublisher: AnyPublisher<UIScreen, Never> {
    NotificationCenter.default
      .publisher(for: UIScreen.didConnectNotification)
      .compactMap { $0.object as? UIScreen }
      .receive(on: RunLoop.main)
      .eraseToAnyPublisher()
  }

  private var screenDidDisconnectPublisher: AnyPublisher<UIScreen, Never> {
    NotificationCenter.default
      .publisher(for: UIScreen.didDisconnectNotification)
      .compactMap { $0.object as? UIScreen }
      .receive(on: RunLoop.main)
      .eraseToAnyPublisher()
  }

  var body: some Scene {
    WindowGroup {
      ContentView()
        .environmentObject(externalDisplayContent)
        .onReceive(
          screenDidConnectPublisher,
          perform: screenDidConnect
        )
        .onReceive(
          screenDidDisconnectPublisher,
          perform: screenDidDisconnect
        )
    }
  }

  private func screenDidConnect(_ screen: UIScreen) {
    print("connected")
    let window = UIWindow(frame: screen.bounds)

    window.windowScene = UIApplication.shared.connectedScenes
      .first { ($0 as? UIWindowScene)?.screen == screen }
      as? UIWindowScene

    let view = ExternalView()
      .environmentObject(externalDisplayContent)
    let controller = UIHostingController(rootView: view)
    window.rootViewController = controller
    window.isHidden = false
    additionalWindows.append(window)
    externalDisplayContent.isShowingOnExternalDisplay = true
  }

  private func screenDidDisconnect(_ screen: UIScreen) {
    print("disconnected")
    additionalWindows.removeAll { $0.screen == screen }
    externalDisplayContent.isShowingOnExternalDisplay = false
  }

}

Do you have a duel display on the Mac already connected?

https://developer.apple.com/documentation/uikit/uiscreen/1617812-screens

UIScreen.screens

Discussion

The returned array includes the main screen plus any additional screens connected to the device. The main screen is always at index 0. Not all devices support external displays. Currently, external displays are supported by iPhone and iPod touch devices with Retina displays and iPad. Older devices, such as the iPhone 3GS do not support external displays.

didConnectNotification

This notification is posted when a new screen is connected to the device. 

Discussion

Connection notifications are not sent for screens that are already present when the application is launched. The application can instead use the screens method to get the current set of screens at launch time. The object of the notification is the UIScreen object representing the new screen. There is no userInfo dictionary.

How do I use NotificationCenter in mac catalyst to detect and connect an external display?
 
 
Q