Skip to content

Commit

Permalink
Add a new property to set a default bootloader type for each buildabl…
Browse files Browse the repository at this point in the history
…e firmware.
  • Loading branch information
yoichiro committed Nov 12, 2023
1 parent ef050a2 commit 9c10be0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/actions/storage.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1685,16 +1685,19 @@ export const storageActionsThunk = {
}
},

updateBuildableFirmwareEnabled:
(definitionId: string, enabled: boolean): ThunkPromiseAction<void> =>
updateBuildableFirmware:
(
definitionId: string,
options: { enabled?: boolean; defaultBootloaderType?: IBootloaderType }
): ThunkPromiseAction<void> =>
async (
dispatch: ThunkDispatch<RootState, undefined, ActionTypes>,
getState: () => RootState
) => {
const { storage } = getState();
const result = await storage.instance!.updateBuildableFirmwareEnabled(
const result = await storage.instance!.updateBuildableFirmware(
definitionId,
enabled
options
);
if (isError(result)) {
console.error(result.cause);
Expand All @@ -1705,6 +1708,7 @@ export const storageActionsThunk = {
dispatch(
KeyboardsEditDefinitionActions.updateBuildableFirmwareFile(null, null)
);
dispatch(NotificationActions.addSuccess('Updated successfully.'));
},

updateBuildableFirmwareFile:
Expand Down
10 changes: 8 additions & 2 deletions src/components/catalog/keyboard/build/CatalogBuild.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../../actions/catalog.action';
import { storageActionsThunk } from '../../../../actions/storage.action';
import {
IBuildableFirmware,
IFirmwareBuildingTask,
IKeyboardDefinitionDocument,
} from '../../../../services/storage/Storage';
Expand Down Expand Up @@ -66,18 +67,23 @@ const mapDispatchToProps = (dispatch: any) => {
},
flashFirmware: (
keyboardDefinitionDocument: IKeyboardDefinitionDocument,
buildableFirmware: IBuildableFirmware,
task: IFirmwareBuildingTask
) => {
dispatch(FlashFirmwareDialogActions.clear());
dispatch(FlashFirmwareDialogActions.updateBootloaderType('caterina'));
dispatch(
FlashFirmwareDialogActions.updateBootloaderType(
buildableFirmware.defaultBootloaderType
)
);
const firmwareName = `Built for ${keyboardDefinitionDocument.name}`;
dispatch(FlashFirmwareDialogActions.updateKeyboardName(''));
dispatch(FlashFirmwareDialogActions.updateFlashMode('build_and_flash'));
dispatch(FlashFirmwareDialogActions.updateBuildingFirmwareTask(task));
dispatch(
FlashFirmwareDialogActions.updateFirmware({
name: firmwareName,
default_bootloader_type: 'caterina',
default_bootloader_type: buildableFirmware.defaultBootloaderType,
flash_support: true,
filename: firmwareName,
description: '',
Expand Down
6 changes: 5 additions & 1 deletion src/components/catalog/keyboard/build/CatalogBuild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export default function CatalogBuild(props: CatalogBuildProps) {
};

const onClickFlash = (task: IFirmwareBuildingTask) => {
props.flashFirmware!(props.definitionDocument!, task);
props.flashFirmware!(
props.definitionDocument!,
props.buildableFirmware!,
task
);
};

const onClickDelete = (task: IFirmwareBuildingTask) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IBuildableFirmwareFileType,
} from '../../../../services/storage/Storage';
import { KeyboardsEditDefinitionActions } from '../../../../actions/keyboards.actions';
import { IBootloaderType } from '../../../../services/firmware/Types';

const mapStateToProps = (state: RootState) => {
return {
Expand All @@ -35,10 +36,19 @@ const mapDispatchToProps = (dispatch: any) => {
enabled: boolean
) => {
dispatch(
storageActionsThunk.updateBuildableFirmwareEnabled(
keyboardDefinitionId,
enabled
)
storageActionsThunk.updateBuildableFirmware(keyboardDefinitionId, {
enabled,
})
);
},
updateBuildableFirmwareDefaultBootloaderType: (
keyboardDefinitionId: string,
defaultBootloaderType: IBootloaderType
) => {
dispatch(
storageActionsThunk.updateBuildableFirmware(keyboardDefinitionId, {
defaultBootloaderType,
})
);
},
createNewFirmwareKeyboardFile: (
Expand Down
41 changes: 41 additions & 0 deletions src/components/keyboards/editdefinition/buildform/BuildForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import {
Breadcrumbs,
Button,
Container,
FormControl,
FormControlLabel,
FormGroup,
Grid,
IconButton,
InputLabel,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
ListSubheader,
MenuItem,
Paper,
Select,
SelectChangeEvent,
Stack,
Switch,
Table,
Expand All @@ -40,6 +45,10 @@ import {
import ConfirmDialog from '../../../common/confirm/ConfirmDialog';
import { extractBuildableFirmwareCodeParameters } from '../../../../services/build/FirmwareCodeParser';
import { IBuildableFirmwareCodeParameter } from '../../../../store/state';
import {
ALL_BOOTLOADER_TYPE,
IBootloaderType,
} from '../../../../services/firmware/Types';

type OwnProps = {};
type BuildFormProps = OwnProps &
Expand Down Expand Up @@ -145,6 +154,15 @@ export default function BuildForm(props: BuildFormProps) {
setOpenConfirmDialog(false);
};

const onChangeDefaultBootloaderType = (
event: SelectChangeEvent<IBootloaderType>
) => {
props.updateBuildableFirmwareDefaultBootloaderType!(
props.keyboardDefinition!.id,
event.target.value as IBootloaderType
);
};

return (
<React.Fragment>
<div className="edit-definition-build-form-container">
Expand All @@ -155,6 +173,29 @@ export default function BuildForm(props: BuildFormProps) {
onChange={onClickSupportBuildingFirmware}
label="Support building QMK Firmware"
/>
<FormControl
fullWidth
size="small"
variant="standard"
sx={{ mt: 1 }}
disabled={!props.buildableFirmware!.enabled}
>
<InputLabel id="building-firmware-type">
Default Bootloader Type
</InputLabel>
<Select
labelId="building-firmware-type"
value={props.buildableFirmware!.defaultBootloaderType}
label="Default Bootloader Type"
onChange={onChangeDefaultBootloaderType}
>
{ALL_BOOTLOADER_TYPE.map((type) => (
<MenuItem key={`bootloader-type-${type}`} value={type}>
{type}
</MenuItem>
))}
</Select>
</FormControl>
</FormGroup>
</div>
<div className="edit-definition-build-form-row">
Expand Down
14 changes: 11 additions & 3 deletions src/services/provider/Firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,7 @@ export class FirebaseProvider implements IStorage, IAuth {
keyboardDefinitionId: doc.data()!.keyboardDefinitionId,
uid: doc.data()!.uid,
enabled: doc.data()!.enabled,
defaultBootloaderType: doc.data()!.defaultBootloaderType,
createdAt: doc.data()!.createdAt.toDate(),
updatedAt: doc.data()!.updatedAt.toDate(),
});
Expand All @@ -1589,6 +1590,7 @@ export class FirebaseProvider implements IStorage, IAuth {
keyboardDefinitionId,
uid: this.getCurrentAuthenticatedUser()!.uid,
enabled: false,
defaultBootloaderType: 'caterina',
createdAt: now,
updatedAt: now,
};
Expand Down Expand Up @@ -1623,6 +1625,7 @@ export class FirebaseProvider implements IStorage, IAuth {
keyboardDefinitionId: doc.data()!.keyboardDefinitionId,
uid: doc.data()!.uid,
enabled: doc.data()!.enabled,
defaultBootloaderType: doc.data()!.defaultBootloaderType,
createdAt: doc.data()!.createdAt.toDate(),
updatedAt: doc.data()!.updatedAt.toDate(),
});
Expand Down Expand Up @@ -1727,9 +1730,9 @@ export class FirebaseProvider implements IStorage, IAuth {
}
}

async updateBuildableFirmwareEnabled(
async updateBuildableFirmware(
keyboardDefinitionId: string,
enabled: boolean
options: { enabled?: boolean; defaultBootloaderType?: IBootloaderType }
): Promise<IResult<IBuildableFirmware>> {
try {
const fetchBuildableFirmwareResult =
Expand All @@ -1741,7 +1744,12 @@ export class FirebaseProvider implements IStorage, IAuth {
);
}
const buildableFirmware = fetchBuildableFirmwareResult.value;
buildableFirmware.enabled = enabled;
if (options.enabled !== undefined) {
buildableFirmware.enabled = options.enabled;
}
if (options.defaultBootloaderType !== undefined) {
buildableFirmware.defaultBootloaderType = options.defaultBootloaderType;
}
buildableFirmware.updatedAt = new Date();
await this.db
.collection('build')
Expand Down
5 changes: 3 additions & 2 deletions src/services/storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export type IBuildableFirmware = {
keyboardDefinitionId: string;
uid: string;
enabled: boolean;
defaultBootloaderType: IBootloaderType;
createdAt: Date;
updatedAt: Date;
};
Expand Down Expand Up @@ -474,9 +475,9 @@ export interface IStorage {
keyboardDefinitionId: string,
fileType: IBuildableFirmwareFileType
): Promise<IResult<IBuildableFirmwareFile[]>>;
updateBuildableFirmwareEnabled(
updateBuildableFirmware(
keyboardDefinitionId: string,
enabled: boolean
options: { enabled?: boolean; defaultBootloaderType?: IBootloaderType }
): Promise<IResult<IBuildableFirmware>>;
createBuildableFirmwareFile(
keyboardDefinitionId: string,
Expand Down

0 comments on commit 9c10be0

Please sign in to comment.