From 066993db676850480e2ce86ed3f9489ef3f4e78e Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 12 Jan 2024 14:04:01 -0600 Subject: [PATCH] Displays Touch/Touch Screen instead of iPhone/iPad when using touch controls --- Delta.xcodeproj/project.pbxproj | 8 +++++ Delta/Extensions/ProcessInfo+visionOS.swift | 25 +++++++++++++++ .../ControllersSettingsViewController.swift | 16 ---------- .../Controllers/LocalDeviceController.swift | 32 +++++++++++++++++++ Delta/Settings/SettingsViewController.swift | 2 +- 5 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 Delta/Extensions/ProcessInfo+visionOS.swift create mode 100644 Delta/Settings/Controllers/LocalDeviceController.swift diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index 1f90379..26aad19 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -188,6 +188,8 @@ D54A4BB329E4D27E004C7D57 /* FeatureDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D54A4BB229E4D27E004C7D57 /* FeatureDetailView.swift */; }; D54F710229E89DCB009C069A /* SettingsUserInfoKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D54F710129E89DCB009C069A /* SettingsUserInfoKey.swift */; }; D54F710429E89DFC009C069A /* NotificationName+Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D54F710329E89DFC009C069A /* NotificationName+Settings.swift */; }; + D55917D82B51CF7D007B7DC0 /* ProcessInfo+visionOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55917D72B51CF7D007B7DC0 /* ProcessInfo+visionOS.swift */; }; + D55917DA2B51D097007B7DC0 /* LocalDeviceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55917D92B51D097007B7DC0 /* LocalDeviceController.swift */; }; D55C468F29E761C000EA6DE9 /* AnyFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55C468E29E761C000EA6DE9 /* AnyFeature.swift */; }; D55C469129E7631000EA6DE9 /* AnyOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55C469029E7631000EA6DE9 /* AnyOption.swift */; }; D560BD8629EDC45600289847 /* ExternalDisplaySceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D560BD8529EDC45600289847 /* ExternalDisplaySceneDelegate.swift */; }; @@ -462,6 +464,8 @@ D54F710129E89DCB009C069A /* SettingsUserInfoKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsUserInfoKey.swift; sourceTree = ""; }; D54F710329E89DFC009C069A /* NotificationName+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationName+Settings.swift"; sourceTree = ""; }; D554C3822A58D89700E93359 /* Delta 7.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Delta 7.xcdatamodel"; sourceTree = ""; }; + D55917D72B51CF7D007B7DC0 /* ProcessInfo+visionOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProcessInfo+visionOS.swift"; sourceTree = ""; }; + D55917D92B51D097007B7DC0 /* LocalDeviceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalDeviceController.swift; sourceTree = ""; }; D55C468E29E761C000EA6DE9 /* AnyFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyFeature.swift; sourceTree = ""; }; D55C469029E7631000EA6DE9 /* AnyOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyOption.swift; sourceTree = ""; }; D560BD8529EDC45600289847 /* ExternalDisplaySceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalDisplaySceneDelegate.swift; sourceTree = ""; }; @@ -571,6 +575,7 @@ D5CDCCEA2A8593FC00E22131 /* UserDefaults+Delta.swift */, AC1AE30B2A6A068F00956EB9 /* Bundle+AppIconImage.swift */, D5D39E782AF2D624004BE3F7 /* GameView+AirPlay.swift */, + D55917D72B51CF7D007B7DC0 /* ProcessInfo+visionOS.swift */, ); path = Extensions; sourceTree = ""; @@ -581,6 +586,7 @@ BF11734F1DA32CF600047DF8 /* ControllersSettingsViewController.swift */, BF616A121F08184A0077F8B2 /* ControllerInputsViewController.swift */, BF8DDD231F4F6C880088A21B /* InputCalloutView.swift */, + D55917D92B51D097007B7DC0 /* LocalDeviceController.swift */, ); path = Controllers; sourceTree = ""; @@ -1553,6 +1559,7 @@ BF59427C1E09BC830051894B /* Cheat.swift in Sources */, BFBAB2E31EB685A2004E0B0E /* DeltaCoreProtocol+Delta.swift in Sources */, D5CDCCF22A859E7500E22131 /* RepairDatabaseViewController.swift in Sources */, + D55917D82B51CF7D007B7DC0 /* ProcessInfo+visionOS.swift in Sources */, BF3540081C5DAFAD00C1184C /* PauseTransitionCoordinator.swift in Sources */, BF525EEA1FF6CD12004AA849 /* DeepLink.swift in Sources */, AC1C991029F8B8C30020E6E4 /* ToastNotificationOptions.swift in Sources */, @@ -1669,6 +1676,7 @@ D56F7ABC2B05988700490ACB /* AttributedHeaderFooterView.swift in Sources */, BFAB9F7D219A43380080EC7D /* SyncManager.swift in Sources */, BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */, + D55917DA2B51D097007B7DC0 /* LocalDeviceController.swift in Sources */, BF1173501DA32CF600047DF8 /* ControllersSettingsViewController.swift in Sources */, BFFC461E1D59823500AF2CC6 /* GamesPresentationController.swift in Sources */, BF99A5971DC2F9C400468E9E /* ControllerSkinTableViewCell.swift in Sources */, diff --git a/Delta/Extensions/ProcessInfo+visionOS.swift b/Delta/Extensions/ProcessInfo+visionOS.swift new file mode 100644 index 0000000..b1714e6 --- /dev/null +++ b/Delta/Extensions/ProcessInfo+visionOS.swift @@ -0,0 +1,25 @@ +// +// ProcessInfo+visionOS.swift +// Delta +// +// Created by Riley Testut on 1/12/24. +// Copyright © 2024 Riley Testut. All rights reserved. +// + +import Foundation +import LocalAuthentication + +extension ProcessInfo +{ + var isRunningOnVisionPro: Bool { + // Returns true even when running on iOS :/ + // guard #available(visionOS 1, *) else { return false } + // return true + + let context = LAContext() + _ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) // Sets .biometryType when called. + + // Can't reference `.opticID` due to bug with #available, so check if .biometryType isn't one of the other types instead. + return context.biometryType != .faceID && context.biometryType != .touchID && context.biometryType != .none + } +} diff --git a/Delta/Settings/Controllers/ControllersSettingsViewController.swift b/Delta/Settings/Controllers/ControllersSettingsViewController.swift index 523df21..adc5dc4 100644 --- a/Delta/Settings/Controllers/ControllersSettingsViewController.swift +++ b/Delta/Settings/Controllers/ControllersSettingsViewController.swift @@ -22,22 +22,6 @@ extension ControllersSettingsViewController } } -private class LocalDeviceController: NSObject, GameController -{ - var name: String { - return UIDevice.current.name - } - - var playerIndex: Int? { - set { Settings.localControllerPlayerIndex = newValue } - get { return Settings.localControllerPlayerIndex } - } - - let inputType: GameControllerInputType = .standard - - var defaultInputMapping: GameControllerInputMappingProtocol? -} - class ControllersSettingsViewController: UITableViewController { var playerIndex: Int! { diff --git a/Delta/Settings/Controllers/LocalDeviceController.swift b/Delta/Settings/Controllers/LocalDeviceController.swift new file mode 100644 index 0000000..cdf6265 --- /dev/null +++ b/Delta/Settings/Controllers/LocalDeviceController.swift @@ -0,0 +1,32 @@ +// +// LocalDeviceController.swift +// Delta +// +// Created by Riley Testut on 1/12/24. +// Copyright © 2024 Riley Testut. All rights reserved. +// + +import DeltaCore + +class LocalDeviceController: NSObject, GameController +{ + var name: String { + if ProcessInfo.processInfo.isRunningOnVisionPro + { + return NSLocalizedString("Touch", comment: "") + } + else + { + return NSLocalizedString("Touch Screen", comment: "") + } + } + + var playerIndex: Int? { + set { Settings.localControllerPlayerIndex = newValue } + get { return Settings.localControllerPlayerIndex } + } + + let inputType: GameControllerInputType = .standard + + var defaultInputMapping: GameControllerInputMappingProtocol? +} diff --git a/Delta/Settings/SettingsViewController.swift b/Delta/Settings/SettingsViewController.swift index bb12483..267f690 100644 --- a/Delta/Settings/SettingsViewController.swift +++ b/Delta/Settings/SettingsViewController.swift @@ -442,7 +442,7 @@ extension SettingsViewController case .controllers: if indexPath.row == Settings.localControllerPlayerIndex { - cell.detailTextLabel?.text = UIDevice.current.name + cell.detailTextLabel?.text = LocalDeviceController().name } else if let index = ExternalGameControllerManager.shared.connectedControllers.firstIndex(where: { $0.playerIndex == indexPath.row }) {