mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-11-24 16:31:04 +00:00
iPad: when creating a new window, take over and close the previous one
This commit is contained in:
parent
19c0072d4c
commit
fdbf6aab7e
@ -9,7 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class DefaultSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
class DefaultSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
var window: UIWindow?
|
var window: UIWindow? // keep window reference to be able to set background colour before destroying
|
||||||
|
|
||||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||||
guard let windowScene = scene as? UIWindowScene else {
|
guard let windowScene = scene as? UIWindowScene else {
|
||||||
@ -24,17 +24,32 @@ class DefaultSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
windowScene.sizeRestrictions?.maximumSize = size
|
windowScene.sizeRestrictions?.maximumSize = size
|
||||||
|
|
||||||
window = UIWindow(windowScene: windowScene)
|
window = UIWindow(windowScene: windowScene)
|
||||||
let rootViewController = appDelegate.window?.rootViewController ?? UIStoryboard(name: "Main", bundle: .main).instantiateInitialViewController()
|
|
||||||
|
|
||||||
if let window {
|
if let window {
|
||||||
appDelegate.window = window
|
appDelegate.window = window
|
||||||
window.rootViewController = rootViewController
|
window.rootViewController = UIStoryboard(name: "Main", bundle: .main).instantiateInitialViewController()
|
||||||
window.makeKeyAndVisible()
|
window.makeKeyAndVisible()
|
||||||
}
|
}
|
||||||
|
self.destroyOtherSessions(not: session)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func destroyOtherSessions(not session: UISceneSession) {
|
||||||
|
let app = UIApplication.shared
|
||||||
|
let options = UIWindowSceneDestructionRequestOptions()
|
||||||
|
options.windowDismissalAnimation = .decline
|
||||||
|
for otherSession in app.openSessions.filter({ $0 != session && $0.configuration.name == "Default"}) {
|
||||||
|
if let window = (otherSession.scene as? UIWindowScene)?.windows.first {
|
||||||
|
window.rootViewController?.view.removeFromSuperview()
|
||||||
|
window.backgroundColor = .darkGray
|
||||||
|
app.requestSceneSessionRefresh(otherSession)
|
||||||
|
}
|
||||||
|
app.requestSceneSessionDestruction(otherSession, options: options)
|
||||||
|
// window will remain visible until window switcher is dismissed!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneDidEnterBackground(_ scene: UIScene) {
|
func sceneDidEnterBackground(_ scene: UIScene) {
|
||||||
if UserDefaults.standard.bool(forKey: "runInBackground") == false {
|
let app = UIApplication.shared
|
||||||
|
if UserDefaults.standard.bool(forKey: "runInBackground") == false && app.connectedScenes.filter({ $0 != scene && $0.session.configuration.name == "Default"}).isEmpty {
|
||||||
AppDelegate.emulator.isRunning = false
|
AppDelegate.emulator.isRunning = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user