Skip to content

Commit

Permalink
fix: correctly load inputs for adapter devices w/set child
Browse files Browse the repository at this point in the history
  • Loading branch information
aolsenjazz committed Oct 15, 2024
1 parent 3c0ae11 commit 8d28de8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/main/ipc/initialize-device-config-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ipcMain.on(
) => {
const driver = getDriver(driverName || deviceName) || Anonymous;
const conf = configFromDriver(deviceName, siblingIdx, driver);
DeviceRegistry.register(conf.id, conf);

HardwarePortService.onConfigChange({ action: 'add', changed: [conf] });
VirtualPortService.onConfigChange({ action: 'add', changed: [conf] });
Expand Down Expand Up @@ -137,10 +138,19 @@ ipcMain.on(
const child = configFromDriver(
childDriverName,
0,
driver
driver,
config.id
) as SupportedDeviceConfig;
config.setChild(child);

const inputDTOs = config.inputs
.map((id) => getQualifiedInputId(config.id, id))
.map((qid) => InputRegistry.get(qid)!)
.map((i) => i.toDTO());

MainWindow.upsertInputConfigs(inputDTOs);
MainWindow.edited = true;

MainWindow.upsertConfiguredDevice(config.toDTO());
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/hardware-config/adapter-device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class AdapterDeviceConfig extends DeviceConfig {

public get inputs() {
if (this.child) {
return this.child!.inputs;
return this.child.inputs;
}
return [];
}
Expand Down
9 changes: 3 additions & 6 deletions src/shared/hardware-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { DeviceRegistry } from '@main/device-registry';

import { DeviceDriver } from '@shared/driver-types/device-driver';
import { InteractiveInputDriver } from '@shared/driver-types/input-drivers';

Expand All @@ -12,7 +10,8 @@ import { DeviceConfig } from './device-config';
export function configFromDriver(
portName: string,
siblingIndex: number,
driver: DeviceDriver
driver: DeviceDriver,
parentId?: string
) {
let config: DeviceConfig;

Expand All @@ -28,15 +27,13 @@ export function configFromDriver(
.filter((i) => i.interactive)
.map((i) => i as InteractiveInputDriver)
.forEach((d) => {
const inputs = create(config.id, d);
const inputs = create(parentId || config.id, d);

(config as SupportedDeviceConfig).inputs.push(
...inputs.map((i) => i.id)
);
});
}

DeviceRegistry.register(config.id, config);

return config;
}

0 comments on commit 8d28de8

Please sign in to comment.