Skip to content

Commit

Permalink
Merge pull request #1005 from Dygmalab/fixMacroLength
Browse files Browse the repository at this point in the history
fix: now macro length is limited to 100 in R2 & Dfy
  • Loading branch information
alexpargon authored Feb 13, 2025
2 parents ad48da0 + 131bf2c commit 3b5ba40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/renderer/components/organisms/Select/MacroSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { i18n } from "@Renderer/i18n";

import NameModal from "@Renderer/components/molecules/CustomModal/ModalName";
import MacrosMemoryUsage from "@Renderer/modules/Macros/MacrosMemoryUsage";
import CurrentMacroLength from "@Renderer/components/molecules/Indicators/CurrentMacroLength";

import {
IconDelete,
Expand Down Expand Up @@ -74,6 +75,22 @@ const MacroSelector: React.FC<MacroSelectorProps> = ({
const toggleShow = () => setShow(!show);
const [showAdd, setShowAdd] = useState(false);
const toggleShowAdd = () => setShowAdd(!showAdd);
const [macroLength, setMacroLength] = useState(0);

useState(() => {
if (
!Array.isArray(itemList) ||
selectedItem < 0 ||
selectedItem >= itemList.length ||
itemList.length === 0 ||
!Array.isArray(itemList[selectedItem].actions) ||
itemList[selectedItem].actions.length === 0
) {
setMacroLength(0);
} else {
setMacroLength(itemList[selectedItem].actions.length);
}
});

const handleSave = (data: string) => {
toggleShow();
Expand Down Expand Up @@ -179,6 +196,8 @@ const MacroSelector: React.FC<MacroSelectorProps> = ({

<MacrosMemoryUsage mem={mem} tMem={tMem} />

<CurrentMacroLength macroLenght={macroLength} />

{itemList === undefined || itemList.length === 0 || itemList.length <= selectedItem ? (
""
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/modules/Macros/MacrosMemoryUsage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ToastMessage from "@Renderer/components/atoms/ToastMessage";
import DotsProgressBar from "./DotsProgressBar";

const Styles = Styled.div`
margin: 0 24px;
margin: 0 24px 0 0;
border: 1px solid ${({ theme }) => theme.styles.memoryUsage.borderColor};
border-radius: 4px;
padding: 6px 12px;
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/views/MacroEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,19 @@ function MacroEditor(props: MacroEditorProps) {
const { state: deviceState } = useDevice();
const timelineRef = useRef(null);

const limitActions = (actions: MacroActionsType[]) => {
if (deviceState.currentDevice.device.info.product !== "Raise") {
return actions.slice(0, 100);
}
return actions;
};

const addToActions = (actions: MacroActionsType[]) => {
const { startContext } = props;
const { macros, selectedMacro } = state;

const macrosList: MacrosType[] = JSON.parse(JSON.stringify(macros));
macrosList[selectedMacro].actions = macrosList[selectedMacro].actions.concat(actions);
macrosList[selectedMacro].actions = limitActions(macrosList[selectedMacro].actions.concat(actions));
state.macros = macrosList;
state.modified = true;
setState({ ...state });
Expand All @@ -164,7 +171,7 @@ function MacroEditor(props: MacroEditorProps) {
const { macros, selectedMacro, modified } = state;

const macrosList = JSON.parse(JSON.stringify(macros));
macrosList[selectedMacro].actions = JSON.parse(JSON.stringify(actions));
macrosList[selectedMacro].actions = limitActions(JSON.parse(JSON.stringify(actions)));
if (!modified) {
state.macros = macrosList;
state.modified = true;
Expand Down

0 comments on commit 3b5ba40

Please sign in to comment.