From 2ccef4e3a684904827fc0ad88bb6b5e40e243b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 17 Feb 2024 14:52:50 +0100 Subject: [PATCH] =?UTF-8?q?visionOS:=20add=20=E2=80=9Crun=20in=20backgroun?= =?UTF-8?q?d=E2=80=9D=20setting=20and=20respect=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mini vMac/AppDelegate.m | 6 +++++- Mini vMac/DefaultSceneDelegate.swift | 10 ++++++++++ Mini vMac/SettingsMenu.swift | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 3579b7f..34a9000 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -334,16 +334,20 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; } } if ([self sceneWithName:@"Default"] == nil) { + [[AppDelegate sharedEmulator] setRunning:YES]; return [UISceneConfiguration configurationWithName:@"Default" sessionRole:UIWindowSceneSessionRoleApplication]; } return nil; } - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { - // if only keyboard is left, close it too if ([self sceneWithName:@"Default"] == nil) { + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"runInBackground"] == NO) { + [[AppDelegate sharedEmulator] setRunning:NO]; + } UIScene *keyboardScene = [self sceneWithName:@"Keyboard"]; if (keyboardScene != nil) { + // if only keyboard is left, close it too [application requestSceneSessionDestruction:keyboardScene.session options:nil errorHandler:nil]; } } diff --git a/Mini vMac/DefaultSceneDelegate.swift b/Mini vMac/DefaultSceneDelegate.swift index 516c054..83d54a7 100644 --- a/Mini vMac/DefaultSceneDelegate.swift +++ b/Mini vMac/DefaultSceneDelegate.swift @@ -32,4 +32,14 @@ class DefaultSceneDelegate: UIResponder, UIWindowSceneDelegate { window.makeKeyAndVisible() } } + + func sceneDidEnterBackground(_ scene: UIScene) { + if UserDefaults.standard.bool(forKey: "runInBackground") == false { + AppDelegate.emulator.isRunning = false + } + } + + func sceneDidBecomeActive(_ scene: UIScene) { + AppDelegate.emulator.isRunning = true + } } diff --git a/Mini vMac/SettingsMenu.swift b/Mini vMac/SettingsMenu.swift index b76ccf2..85045ad 100644 --- a/Mini vMac/SettingsMenu.swift +++ b/Mini vMac/SettingsMenu.swift @@ -25,6 +25,7 @@ struct SettingsMenu: View { struct SpeedMenu: View { @AppStorage("speedValue") var currentSpeed: EmulatorSpeed = .speed1x + @AppStorage("runInBackground") var runInBackground: Bool = false private var currentSpeedImage: String { switch currentSpeed { case .speed1x: @@ -54,6 +55,8 @@ struct SpeedMenu: View { SpeedButton(label: "16x", speed: .speed16x) SpeedButton(label: "32x", speed: .speed32x) SpeedButton(label: "Unlimited", speed: .speedAllOut) + Divider() + Toggle("Run in Background", isOn: $runInBackground) }.menuOrder(.fixed) } }