Skip to content

Commit

Permalink
fix: deregister and remove from frontend device children
Browse files Browse the repository at this point in the history
  • Loading branch information
aolsenjazz committed Oct 15, 2024
1 parent 8d28de8 commit dda368f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/ipc/initialize-device-config-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ ipcMain.on(
(_e: IpcMainEvent, deviceId: string) => {
const conf = DeviceRegistry.get(deviceId)!;

if (
conf instanceof SupportedDeviceConfig ||
conf instanceof AdapterDeviceConfig
) {
const qInputIds = conf.inputs.map((id) =>
getQualifiedInputId(conf.id, id)
);
const pluginIds: string[] = [];

qInputIds.forEach((i) => {
const input = InputRegistry.get(getQualifiedInputId(conf.id, i))!;

input?.plugins.forEach((p) => {
PluginRegistry.deregister(p);
pluginIds.push(p);
});

InputRegistry.deregister(i);
});

MainWindow.removePlugins(pluginIds);
MainWindow.removeInputs(qInputIds);
}

DeviceRegistry.deregister(deviceId);

HardwarePortService.onConfigChange({ action: 'remove', changed: [conf] });
Expand Down
14 changes: 14 additions & 0 deletions src/main/window-provider/main-window-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ export class MainWindowActions extends StatefulWindowActions {
payload: dto,
});
}

public removePlugins(plugins: string[]) {
this.sendReduxEvent({
type: 'plugins/removeMany',
payload: plugins,
});
}

public removeInputs(inputs: string[]) {
this.sendReduxEvent({
type: 'inputConfigs/removeMany',
payload: inputs,
});
}
}
2 changes: 1 addition & 1 deletion src/renderer/components/InputConfigDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function InputConfigDrawer() {
Element = (
<BasicMessage msg="This device isn't supported yet, so you can't customize individual knob and buttons. However, you can still add Device Plugins in the left panel." />
);
} else if (selectedInput === null) {
} else if (!inputConfig) {
Element = <BasicMessage msg="No inputs selected." />;
} else if (config && inputConfig) {
Element = <InputConfigPanel input={inputConfig} />;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/features/plugins/plugins-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const pluginsSlice = createAppSlice({
upsertMany: pluginsEntityAdapter.upsertMany,
upsertOne: pluginsEntityAdapter.upsertOne,
removeOne: pluginsEntityAdapter.removeOne,
removeMany: pluginsEntityAdapter.removeMany,
},
});

Expand Down

0 comments on commit dda368f

Please sign in to comment.