Skip to content

Commit

Permalink
Show only enabled devices in DeviceSelectorView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Dec 9, 2023
1 parent d2ab6ed commit f325340
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions src/apps/SettingsWindow/src/View/DeviceSelectorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct DeviceSelectorView: View {
@Binding var selectedDevice: LibKrbn.ConnectedDevice?
@ObservedObject private var connectedDevices = LibKrbn.ConnectedDevices.shared
@ObservedObject private var settings = LibKrbn.Settings.shared

var body: some View {
List {
Expand All @@ -25,46 +26,48 @@ struct DeviceSelectorView: View {
Divider()

ForEach(connectedDevices.connectedDevices) { connectedDevice in
Button(
action: {
selectedDevice = connectedDevice
},
label: {
let noId = connectedDevice.vendorId == 0 && connectedDevice.productId == 0
let label =
noId
? connectedDevice.deviceAddress
: "\(String(connectedDevice.vendorId)),\(String(connectedDevice.productId))"
HStack {
Text(
"""
\(connectedDevice.productName) \
(\(connectedDevice.manufacturerName)) \
\(label != "" ? "[\(label)]" : "")
"""
)
if settings.findConnectedDeviceSetting(connectedDevice)?.modifyEvents ?? false {
Button(
action: {
selectedDevice = connectedDevice
},
label: {
let noId = connectedDevice.vendorId == 0 && connectedDevice.productId == 0
let label =
noId
? connectedDevice.deviceAddress
: "\(String(connectedDevice.vendorId)),\(String(connectedDevice.productId))"
HStack {
Text(
"""
\(connectedDevice.productName) \
(\(connectedDevice.manufacturerName)) \
\(label != "" ? "[\(label)]" : "")
"""
)

Spacer()
Spacer()

VStack {
if connectedDevice.isKeyboard {
Image(systemName: "keyboard")
}
if connectedDevice.isPointingDevice {
Image(systemName: "capsule.portrait")
}
if connectedDevice.isGamePad {
Image(systemName: "gamecontroller")
VStack {
if connectedDevice.isKeyboard {
Image(systemName: "keyboard")
}
if connectedDevice.isPointingDevice {
Image(systemName: "capsule.portrait")
}
if connectedDevice.isGamePad {
Image(systemName: "gamecontroller")
}
}
}
.sidebarButtonLabelStyle()
}
.sidebarButtonLabelStyle()
}
)
.sidebarButtonStyle(
selected: selectedDevice?.id == connectedDevice.id)
)
.sidebarButtonStyle(
selected: selectedDevice?.id == connectedDevice.id)

Divider()
Divider()
}
}

Spacer()
Expand Down

0 comments on commit f325340

Please sign in to comment.