Skip to content

Commit

Permalink
feature: accurately refelct switch state in the render
Browse files Browse the repository at this point in the history
  • Loading branch information
aolsenjazz committed Oct 14, 2024
1 parent c230012 commit 1d93bfa
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 549 deletions.
1 change: 0 additions & 1 deletion src/main/ipc/initialize-device-config-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ 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
15 changes: 7 additions & 8 deletions src/main/ipc/initialize-input-config-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getQualifiedInputId } from '@shared/util';
import { PluginManifest } from '@shared/plugin-core/plugin-manifest';
import { BaseInputPlugin } from '@shared/plugin-core/base-input-plugin';
import { importInputSubcomponent } from '@plugins/plugin-loader';
import { MonoInputConfig } from '@shared/hardware-config/input-config/mono-input-config';

import { INPUT_CONFIG } from './ipc-channels';
import { WindowProvider } from '../window-provider';
Expand All @@ -25,8 +24,7 @@ ipcMain.on(
const onClick = async (m: PluginManifest) => {
const input = InputRegistry.get(qualifiedInputId);

if (!(input instanceof MonoInputConfig))
throw new Error(`Adding plugin to ${input} is not defined`);
if (!input) throw new Error(`Adding plugin to ${input} is not defined`);

const inputDriver = input.driver;
const Plugin = await importInputSubcomponent(m.title, 'plugin');
Expand All @@ -52,12 +50,13 @@ ipcMain.on(
(_e: IpcMainEvent, pluginId: string, qualifiedInputId: string) => {
const inputConfig = InputRegistry.get(qualifiedInputId);

if (inputConfig instanceof MonoInputConfig) {
inputConfig.plugins = inputConfig.plugins.filter((p) => p !== pluginId);
if (!inputConfig)
throw new Error(`no such config for id ${qualifiedInputId}`);

PluginRegistry.deregister(pluginId);
MainWindow.upsertInputConfig(inputConfig.toDTO());
}
inputConfig.plugins = inputConfig.plugins.filter((p) => p !== pluginId);

PluginRegistry.deregister(pluginId);
MainWindow.upsertInputConfig(inputConfig.toDTO());
}
);

Expand Down
1 change: 0 additions & 1 deletion src/main/port-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ export class HardwarePortServiceSingleton {

if (message) remoteTransport.send(message);

console.log(config.id, inputId);
MainWindow.sendRemoteMessage(config.id, inputId, msg);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type PropTypes = {
grid: InputGridDriver;
deviceWidth: number;
deviceHeight: number;
onClick: (e: React.MouseEvent, ids: string[]) => void;
onClick: (e: React.MouseEvent, id: string) => void;
};

const InputGridLayout = (props: PropTypes) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function SwitchLayout(props: PropTypes) {

const { steps } = driver;
const recentMessages = useAppSelector(selectRecentRemoteMessagesById(id, 1));
console.log(recentMessages);

const step = useMemo(() => {
if (!recentMessages.length) return driver.initialStep;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from 'react-redux';

import { selectSelectedInputs } from '@features/selected-inputs/selected-inputs-slice';
import { selectSelectedInput } from '@features/selected-input/selected-input-slice';
import { inputIdFromDriver, getQualifiedInputId } from '@shared/util';
import { selectSelectedDevice } from '@selectors/selected-device-selector';
import { BaseInputDriver } from '@shared/driver-types/input-drivers/base-input-driver';
Expand All @@ -13,24 +13,24 @@ type InputLayoutPropTypes = {
driver: BaseInputDriver;
width: string;
height: string;
onClick: (e: React.MouseEvent, ids: string[]) => void;
onClick: (e: React.MouseEvent, id: string) => void;
};

export default function InputLayout(props: InputLayoutPropTypes) {
const { driver, width, height, onClick } = props;
const selectedDevice = useSelector(selectSelectedDevice);
const selectedInputs = useSelector(selectSelectedInputs);
const selectedInput = useSelector(selectSelectedInput);

let Element;
if (driver.interactive) {
const inputId = inputIdFromDriver(driver as InteractiveInputDriver);
const qualifiedInputId = getQualifiedInputId(selectedDevice!.id, inputId);
const focus = selectedInputs.includes(qualifiedInputId);
const focus = selectedInput === qualifiedInputId;

Element = (
<div
className={`input-wrapper ${focus ? 'focus' : ''}`}
onClick={(e: React.MouseEvent) => onClick(e, [qualifiedInputId])}
onClick={(e: React.MouseEvent) => onClick(e, qualifiedInputId)}
role="presentation"
style={{
width,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/DevicePanel/DeviceLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputGridLayout from './InputGridLayout';

type PropTypes = {
driver: DeviceDriver;
onClick: (e: React.MouseEvent, ids: string[]) => void;
onClick: (e: React.MouseEvent, id: string) => void;
};

export default function DeviceLayout(props: PropTypes) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/DevicePanel/DeviceLayoutWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';

import { useAppDispatch } from '@hooks/use-app-dispatch';
import { DeviceDriver } from '@shared/driver-types/device-driver';
import { setSelectedInputs } from '@features/selected-inputs/selected-inputs-slice';
import { setSelectedInput } from '@features/selected-input/selected-input-slice';

import DeviceLayout from './DeviceLayout';
import WarningIcon from '../WarningIcon';
Expand All @@ -23,8 +23,8 @@ export default function DeviceLayoutWrapper(

// on input click (or ctrl+click) update selectedInputs
const onInputSelect = useCallback(
(_event: React.MouseEvent, ids: string[]) => {
dispatch(setSelectedInputs(ids));
(_event: React.MouseEvent, id: string) => {
dispatch(setSelectedInput(id));
},
[dispatch]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { MonoInputDTO } from '@shared/hardware-config/input-config/mono-input-dto';
import { MonoInputAggregate } from '../mono-input-aggregate';
import { InputDTO } from '@shared/hardware-config/input-config/base-input-config';

type PropTypes = {
inputs: MonoInputDTO[];
input: InputDTO;
};

export default function InputDefaultsSubpanel(props: PropTypes) {
const { inputs } = props;

const group = new MonoInputAggregate(inputs);
const { input } = props;

return (
<div className="subpanel input-defaults-subpanel">
<h1>Default MIDI Settings</h1>
<p>Output Response: {group.outputResponse}</p>
<p>Event Type: {group.statusString}</p>
<p>Channel: {group.channel}</p>
<p>Number: {group.number}</p>
<p>Output Response: {input.defaults.response}</p>
<p>Event Type: {input.defaults.statusString}</p>
<p>Channel: {input.defaults.channel}</p>
<p>Number: {input.defaults.number}</p>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
import { useCallback, useMemo } from 'react';
import { useCallback } from 'react';

import { InputDTO } from '@shared/hardware-config/input-config/base-input-config';

import ControlledInput from '../../ControlledInput';
import SectionHeader from '../../SectionHeader';

type PropTypes = {
configs: InputDTO[];
input: InputDTO;
};

const { InputConfigService } = window;

export default function InputDetailsSubpanel(props: PropTypes) {
const { configs } = props;
const { input } = props;

const name = useMemo(() => {
return configs.length > 1
? `${configs.length} Inputs Selected`
: `Input: ${configs[0].nickname || configs[0].id}`;
}, [configs]);

const nickname = useMemo(() => {
return configs.length > 1 ? '' : configs[0].nickname;
}, [configs]);
const name = `Input: ${input.nickname || input.id}`;
const { nickname } = input;

const onChange = useCallback(
(n: string) => {
const newConf = {
...configs[0],
...input,
nickname: n,
};
InputConfigService.updateInputs([newConf]);
},
[configs]
[input]
);

return (
<div className="details-panel input-details-panel">
<div>
<SectionHeader title="INPUT SETTINGS" size="large" />
<div
className={`subpanel nickname-subpanel ${
configs.length !== 1 ? 'deactivated' : ''
}`}
>
<div className="subpanel nickname-subpanel">
<div className="nickname-display">
<h1>{name}</h1>
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { useCallback } from 'react';

import { MonoInputDTO } from '@shared/hardware-config/input-config/mono-input-dto';
import { importInputSubcomponent } from '@plugins/plugin-loader';
import { getQualifiedInputId } from '@shared/util';
import { InputDTO } from '@shared/hardware-config/input-config/base-input-config';

import PluginSubpanel from 'renderer/components/PluginSubpanel';

import InputDefaultsSubpanel from '../InputDefaultsSubpanel';

type PropTypes = {
inputs: MonoInputDTO[];
input: InputDTO;
deviceId: string;
};

const { InputConfigService } = window;

export default function MonoInputConfigPanel(props: PropTypes) {
const { inputs, deviceId } = props;

const input = inputs[0];
const { input, deviceId } = props;

const showPluginMenu = useCallback(
(x: number, y: number) => {
Expand All @@ -43,12 +41,12 @@ export default function MonoInputConfigPanel(props: PropTypes) {

return (
<div>
<InputDefaultsSubpanel inputs={inputs} />
<InputDefaultsSubpanel input={input} />
<PluginSubpanel
plugins={input.plugins}
removePlugin={removePlugin}
showPluginMenu={showPluginMenu}
showAddPlugin={inputs.length === 1}
showAddPlugin={true}
deviceId={deviceId}
importPlugin={(title) => importInputSubcomponent(title, 'gui')}
/>
Expand Down
Loading

0 comments on commit 1d93bfa

Please sign in to comment.