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) } }