display(visionOS): disable background auto-suspend on visionOS

The auto-suspend can trigger any time user does not focus on view.
This commit is contained in:
osy 2024-02-21 10:57:28 -08:00
parent 689367a9c3
commit 9a871c0c7d
2 changed files with 8 additions and 0 deletions

View File

@ -25,6 +25,8 @@
<array> <array>
<string>iOS-Remote</string> <string>iOS-Remote</string>
</array> </array>
<key>Platform</key>
<string>iOS</string>
</dict> </dict>
<dict> <dict>
<key>Type</key> <key>Type</key>
@ -35,6 +37,8 @@
<string>AutosaveBackground</string> <string>AutosaveBackground</string>
<key>DefaultValue</key> <key>DefaultValue</key>
<true/> <true/>
<key>Platform</key>
<string>iOS</string>
</dict> </dict>
<dict> <dict>
<key>Type</key> <key>Type</key>

View File

@ -499,6 +499,7 @@ extension VMSessionState {
} }
func didEnterBackground() { func didEnterBackground() {
#if !os(visionOS)
logger.info("Entering background") logger.info("Entering background")
let shouldAutosaveBackground = UserDefaults.standard.bool(forKey: "AutosaveBackground") let shouldAutosaveBackground = UserDefaults.standard.bool(forKey: "AutosaveBackground")
if shouldAutosaveBackground && vmState == .started { if shouldAutosaveBackground && vmState == .started {
@ -521,14 +522,17 @@ extension VMSessionState {
task = .invalid task = .invalid
} }
} }
#endif
} }
func didEnterForeground() { func didEnterForeground() {
#if !os(visionOS)
logger.info("Entering foreground!") logger.info("Entering foreground!")
if (hasAutosave && vmState == .started) { if (hasAutosave && vmState == .started) {
logger.info("Deleting snapshot") logger.info("Deleting snapshot")
vm.requestVmDeleteState() vm.requestVmDeleteState()
} }
#endif
} }
} }