Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat macros delays modifiable #940

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api/flash/defyFlasher/sideFlasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class SideFlaser {
const seal = recoverSeal(this.firmwareSides.slice(0, 28));
// log.info("This is the seal from the FW file");
// eslint-disable-next-line no-console
console.info("This is the seal from the Neuron");
console.info("This is the seal from the FW File");
// eslint-disable-next-line no-console
console.table(seal);

Expand Down Expand Up @@ -152,6 +152,7 @@ export default class SideFlaser {
}
if (selectedDev === undefined) throw new Error("Flashable device not found");
log.info("Found this device:", selectedDev);
await delay(1000);

this.serialport = new SerialPort({
path: selectedDev?.path,
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/components/atoms/icons/IconCheckmark.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as React from "react";

interface IconProps {
size?: "sm";
size?: "sm" | "md";
}

function IconCheckmark({ size = "sm" }: IconProps) {
return (
<>
{size === "md" ? (
<svg width={28} height={28} fill="none" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path d="M3.333 10l4.583 4.583 8.75-8.75" stroke="currentColor" strokeWidth={1.2} />
</svg>
) : (
""
)}
{size === "sm" ? (
<svg width={20} height={20} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3.333 10l4.583 4.583 8.75-8.75" stroke="currentColor" strokeWidth={1.2} />
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/controller/FlashingProcedure/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const restoreSettings = async (
try {
let device: Device | undefined;
const list = (await DeviceTools.list()) as Device[];
log.info(list);
log.info("Found these devices", list);
await delay(1000);

const selected = list.find(x => parseInt(x.productId, 16) === context.originalDevice?.device?.usb.productId);
if (selected !== undefined) device = await DeviceTools.connect(selected);
for (let i = 0; i < backup.backup.length; i += 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ const English = {
pasteSuccess: "Pasted!",
importSuccessCurrentLayerTitle: "Imported successfully!",
importSuccessCurrentLayer: "Imported to current Layer successfully",
importSuccessCurrentMacro: "Imported to current Macro successfully",
importSuccessCurrentMacro: "The imported macro has been added as a new macro",
importSuccessAllLayers: "Imported all Layers successfully",
exportSuccessCurrentLayer: "Ready to share!",
exportSuccessCurrentLayerContent: "Your layer has been successfully exported.",
Expand Down
66 changes: 61 additions & 5 deletions src/renderer/modules/Macros/KeyMacro.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useCallback } from "react";
import React, { useMemo, useCallback, useState } from "react";
import { withTheme, DefaultTheme } from "styled-components";
import { Popover, PopoverContent, PopoverTrigger } from "@Renderer/components/atoms/Popover";
import { i18n } from "@Renderer/i18n";
Expand All @@ -11,6 +11,8 @@ import {
IconStopWatch,
IconDragAndDrop,
IconDelete,
IconPen,
IconCheckmark,
} from "@Renderer/components/atoms/icons";
import Heading from "@Renderer/components/atoms/Heading";
import { Button } from "@Renderer/components/atoms/Button";
Expand All @@ -36,6 +38,7 @@ interface KeyMacroProps {
updateAction: (id: number, actionType: number) => void;
onDeleteRow: (id: number) => void;
onCloneRow: (id: number) => void;
editDelay: (id: number, delay: number | number[]) => void;
theme: DefaultTheme;
}

Expand All @@ -49,6 +52,7 @@ const KeyMacro: React.FC<KeyMacroProps> = ({
updateAction,
onDeleteRow,
onCloneRow,
editDelay,
theme,
}) => {
const getItemStyle = useCallback(
Expand All @@ -64,8 +68,35 @@ const KeyMacro: React.FC<KeyMacroProps> = ({
}),
[theme.styles.macroKey],
);

const isModifier = useMemo(() => (item.keyCode as number) > 223 && (item.keyCode as number) < 232 && item.type !== 2, [item]);
const [delay, setDelay] = useState<number | number[]>(item.keyCode);
const [enableEdit, setEnableEdit] = useState(false);

const setDelayHandler = (value: string) => {
const randomDelay = Array.isArray(item.keyCode);
const allNumbers = randomDelay ? value.split("-").filter(v => v !== "").length === 2 : value !== "";

if (allNumbers) {
if (randomDelay) {
const newDelay = value
.trim()
.split("-")
.map(s => parseInt(s, 10));
setDelay(newDelay);
} else {
setDelay(parseInt(value, 10));
}
} else {
setDelay(randomDelay ? [0, 0] : 0);
}
};

const finishDelayEdit = () => {
editDelay(item.id, delay);
setEnableEdit(false);
};

const visualKeycode = Array.isArray(item.keyCode) ? item.keyCode.join("-") : item.keyCode;

return (
<div>
Expand Down Expand Up @@ -108,9 +139,34 @@ const KeyMacro: React.FC<KeyMacroProps> = ({
>
{item.type === 1 || item.type === 2 ? i18n.editor.macros.delay : i18n.general.key}
</Heading>
<p className="keyValue text-2xl">
{item.symbol} {item.type === 1 || item.type === 2 ? <small>ms</small> : ""}
</p>
<div className="keyValue text-2xl">
{(item.type === 1 || item.type === 2) && enableEdit ? (
<input
id="changeDelay"
type="text"
value={Array.isArray(delay) ? `${delay[0]}-${delay[1]}` : `${delay}`}
onChange={event => setDelayHandler(event.target.value)}
className="form-input form-input-lg p-3 align-top"
/>
) : (
visualKeycode
)}
{(item.type === 1 || item.type === 2) && !enableEdit ? <small>ms</small> : ""}
{(item.type === 1 || item.type === 2) && !enableEdit ? (
<Button variant="ghost" onClick={() => setEnableEdit(true)}>
<IconPen />{" "}
</Button>
) : (
""
)}
{(item.type === 1 || item.type === 2) && enableEdit ? (
<Button variant="ghost" onClick={() => finishDelayEdit()} className="pl-3">
<IconCheckmark size="md" />{" "}
</Button>
) : (
""
)}
</div>
</div>
<div className="keyFunctions py-[12px] px-[12px] bg-gray-50/40 dark:bg-gray-800 border-t-[1px] border-gray-50 dark:border-gray-700">
<Heading
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/modules/Macros/TimelineEditorMacroTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ const TimelineEditorMacroTable = (props: Props) => {
updateRows(aux);
};

const editDelay = (id: number, delay: number | number[]) => {
log.info("Delay launched", id, delay);
const aux = rows;
aux[id].keyCode = delay;
updateRows(aux);
};

const addModifier = (rowID: number, modifierID: number) => {
log.info("Called addModifier", rowID, modifierID);
const { name, keyCode, color } = modifiers[modifierID];
Expand Down Expand Up @@ -275,6 +282,7 @@ const TimelineEditorMacroTable = (props: Props) => {
onDeleteRow={onDeleteRow}
onCloneRow={onCloneRow}
addModifier={addModifier}
editDelay={editDelay}
/>
)}
</Draggable>
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/views/MacroEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ function MacroEditor(props: MacroEditorProps) {

const importMacro = async () => {
const options = {
title: "Load Macro file",
buttonLabel: "Load Macro",
title: "Import Macro",
buttonLabel: "Import Macro",
filters: [
{ name: "Json", extensions: ["json"] },
{ name: "All Files", extensions: ["*"] },
Expand Down Expand Up @@ -572,9 +572,9 @@ function MacroEditor(props: MacroEditorProps) {
const { macros, selectedMacro } = state;
const data = JSON.stringify(macros[selectedMacro]);
const options = {
title: "Save Macro file",
defaultPath: `Macro${selectedMacro}-${macros[selectedMacro].name}.json`,
buttonLabel: "Save Macro",
title: "Export Macro",
defaultPath: `Macro${selectedMacro + 1}-${macros[selectedMacro].name}.json`,
buttonLabel: "Export Macro",
filters: [
{ name: "Json", extensions: ["json"] },
{ name: "All Files", extensions: ["*"] },
Expand Down
Loading