Skip to content

Commit 781dfb5

Browse files
committed
Improvements for tvOS
1 parent c980969 commit 781dfb5

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

Sources/GameControllerKit/GCKControllerView.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ public struct GCKControllerView: View {
1515
@EnvironmentObject
1616
var GCKit: GameControllerKit
1717

18-
var controller: GCKController {
19-
GCKit.controller ?? .withExtendedGamepad()
20-
}
21-
2218
var action: GCKAction {
2319
GCKit.lastAction
2420
}
@@ -36,7 +32,8 @@ public struct GCKControllerView: View {
3632

3733
HStack {
3834
dPad
39-
if controller.hasTouchPad {
35+
if let controller = GCKit.controller,
36+
controller.hasTouchPad {
4037
touchPad
4138
}
4239
buttons
@@ -210,9 +207,9 @@ public struct GCKControllerView: View {
210207
.stroke()
211208
.foregroundStyle(
212209
Color(cgColor: .init(
213-
red: CGFloat(controller.light?.color.red ?? 0),
214-
green: CGFloat(controller.light?.color.green ?? 0),
215-
blue: CGFloat(controller.light?.color.blue ?? 0),
210+
red: CGFloat(GCKit.controller?.light?.color.red ?? 0),
211+
green: CGFloat(GCKit.controller?.light?.color.green ?? 0),
212+
blue: CGFloat(GCKit.controller?.light?.color.blue ?? 0),
216213
alpha: 1
217214
))
218215
)

Sources/GameControllerKit/GameControllerKit.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import CoreHaptics
1515
import OSLog
1616

1717
/// Game Controller Kit
18-
///
19-
/// GameControllerKit is a Swift package that makes it easy to work with
18+
///
19+
/// GameControllerKit is a Swift package that makes it easy to work with
2020
/// game controllers on iOS, macOS, and tvOS. It provides a simple API to
2121
/// connect to game controllers, read input from them, and control their
2222
/// lights and haptics.
@@ -184,11 +184,6 @@ public class GameControllerKit: ObservableObject {
184184
for (index, currentController) in controllers.enumerated() {
185185
currentController.playerIndex = GCControllerPlayerIndex(rawValue: index) ?? .indexUnset
186186

187-
if !isConnected {
188-
isConnected = true
189-
controller = currentController
190-
}
191-
192187
let currentControllerType: GCKControllerType = switch currentController.physicalInputProfile {
193188
case is GCDualSenseGamepad:
194189
.dualSense
@@ -208,6 +203,18 @@ public class GameControllerKit: ObservableObject {
208203
let contr = String(describing: currentControllerType)
209204
logger.info("Did connect controller \(currentController.productCategory) recognized as \(contr).")
210205

206+
logger.info("CONNECTED: \(self.controllers.count)")
207+
208+
// Disfavor Siri Remote over a external controller.
209+
if (currentControllerType == .siriRemote && controllers.count == 1) ||
210+
currentControllerType != .siriRemote {
211+
isConnected = true
212+
controller = currentController
213+
controllerType = currentControllerType
214+
215+
logger.info("Did set controller \(currentController.productCategory) as main (first) controller.")
216+
}
217+
211218
setupController(controller: currentController)
212219
}
213220
}

0 commit comments

Comments
 (0)