import UIKit
import SwiftUI

class OutputDelegate: UIResponder, UIWindowSceneDelegate {
    
    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene, session.role == .windowExternalDisplay else { return }
        
        let window = UIWindow(windowScene: windowScene)
        let aspectRatio = window.bounds.width / window.bounds.height
        let hostingController = UIHostingController<CountdownView>(rootView: CountdownView(aspectRatio: aspectRatio))
        window.rootViewController = hostingController
        window.isHidden = false
        
        OutputDisplay.shared.isConnected = true
        self.window = window
    }
    
    func sceneDidDisconnect(_ scene: UIScene) {
        OutputDisplay.shared.isConnected = false
        window = nil
    }
}

class OutputDisplay: ObservableObject {
    static let shared = OutputDisplay()
    @Published var isConnected = false
}

import UIKit
import SwiftUI

class OutputDelegate: UIResponder, UIWindowSceneDelegate {
    
    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene, session.role == .windowExternalDisplay else { return }
        
        let window = UIWindow(windowScene: windowScene)
        let aspectRatio = window.bounds.width / window.bounds.height
        let hostingController = UIHostingController<CountdownView>(rootView: CountdownView(aspectRatio: aspectRatio))
        hostingController.view.backgroundColor = .black
        window.rootViewController = hostingController
        window.isHidden = false
        
        OutputDisplay.shared.isConnected = true
        self.window = window
    }
    
    func sceneDidDisconnect(_ scene: UIScene) {
        OutputDisplay.shared.isConnected = false
        window = nil
    }
}

class OutputDisplay: ObservableObject {
    static let shared = OutputDisplay()
    @Published var isConnected = false
}

Set the background colour of the output hosting controller to black in case of (unexpected) view resizes.
Set the background colour of the output hosting controller to black in case of (unexpected) view resizes.
