Skip to content

Commit

Permalink
feat: add option to disable Bridge devices
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed May 4, 2023
1 parent 019e9f2 commit d53d08a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IPCServerContext } from '../../../../contexts/IPCServer'
import { ProjectContext } from '../../../../contexts/Project'
import { SelectEnum } from '../../../inputs/SelectEnum'
import { BooleanInput } from '../../../inputs/BooleanInput'
import Toggle from 'react-toggle'

const MIN_PORT = 1
const MAX_PORT = 65535
Expand Down Expand Up @@ -240,6 +241,18 @@ export const DeviceItemContent: React.FC<{
</div>
<div className="actions">
<TextBtn label="Delete" style="danger" onClick={removeDevice} />
<>
<label>Enabled&nbsp;</label>
<div className="sc-switch">
<Toggle
checked={!deviceSettings.disable}
onChange={() => {
deviceSettings.disable = !deviceSettings.disable
ipcServer.updateProject({ id: project.id, project }).catch(handleError)
}}
/>
</div>
</>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export const DeviceItemHeader: React.FC<{
<DeviceShortcut device={props.device} type={deviceSettings.type} />
<ScListItemLabel title={props.deviceName || props.deviceId} subtitle={deviceAddress} />
<div className="status">
{props.device.ok ? 'Connected' : props.device.message ? props.device.message : 'Not Connected'}
{deviceSettings.disable
? 'Disabled'
: props.device.ok
? 'Connected'
: props.device.message
? props.device.message
: 'Not Connected'}
</div>
</div>
)
Expand Down
5 changes: 4 additions & 1 deletion shared/packages/tsr-bridge/src/TSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class TSR {
// Added/updated:
for (const deviceId in newDevices) {
const newDevice = newDevices[deviceId]
if (newDevice.disable) continue

const existingDevice = this.devices[deviceId]

if (!existingDevice || !_.isEqual(existingDevice, newDevice)) {
Expand Down Expand Up @@ -105,7 +107,8 @@ export class TSR {
}
// Removed:
for (const deviceId in this.devices) {
if (!newDevices[deviceId]) {
const newDevice = newDevices[deviceId]
if (!newDevice || newDevice.disable) {
// Delete the sideloaded device, if any
if (deviceId in this.sideLoadedDevices) {
await this.sideLoadedDevices[deviceId].close()
Expand Down

0 comments on commit d53d08a

Please sign in to comment.