mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2025-02-16 03:31:04 +00:00
visionOS: add “run in background” setting and respect it
This commit is contained in:
parent
fca6943bfe
commit
2ccef4e3a6
@ -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<UISceneSession *> *)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];
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user