Skip to content

Commit

Permalink
Merge pull request #592 from Dygmalab/fixMacroLoadWhen1
Browse files Browse the repository at this point in the history
fix: Macros where being read erroneously when only 1
  • Loading branch information
alexpargon authored Nov 17, 2023
2 parents 0267e6c + dca4a9d commit 5bca465
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/renderer/views/MacroEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { LogoLoaderCentered } from "@Renderer/component/Loader";

import { RegularButton } from "@Renderer/component/Button";
import Callout from "@Renderer/component/Callout";
import { IconFloppyDisk } from "@Renderer/component/Icon";
import { IconFloppyDisk, IconLoader } from "@Renderer/component/Icon";
import { MacroSelector } from "@Renderer/component/Select";
import ToastMessage from "@Renderer/component/ToastMessage";
import { PageHeader } from "@Renderer/modules/PageHeader";
Expand Down Expand Up @@ -126,7 +126,7 @@ class MacroEditor extends React.Component {
(superkeys.length === 1 && superkeys[0].length === 0) ||
(superkeys.length === 1 && superkeys[0].length === 1 && superkeys[0] === 0)
) {
return Array.from({ length: 512 }, 65535).join(" ");
return Array(512).fill("65535").join(" ");
}
let keyMap = [...superkeys];
// console.log("First", keyMap);
Expand Down Expand Up @@ -280,7 +280,14 @@ class MacroEditor extends React.Component {

macrosMap = macros => {
const { macrosEraser } = this.state;
if (macros.length === 0 || (macros.length === 1 && Array.isArray(macros[0].actions))) {
console.log(
"Macros map function",
macros,
macrosEraser,
macros.length === 0,
macros.length === 1 && Array.isArray(macros[0].actions),
);
if (macros.length === 0 || (macros.length === 1 && !Array.isArray(macros[0].actions))) {
return macrosEraser;
}
const mapAction = action => {
Expand All @@ -302,12 +309,14 @@ class MacroEditor extends React.Component {
return [[action.type], [action.keyCode]];
}
};
return macros
const result = macros
.map(macro => macro.actions.map(action => mapAction(action)).concat([0]))
.concat([0])
.flat()
.join(" ")
.replaceAll(",", " ");
console.log("MACROS GOING TO BE SAVED", result);
return result;
};

updateMacros(recievedMacros) {
Expand Down Expand Up @@ -349,7 +358,9 @@ class MacroEditor extends React.Component {
cancelContext();
setLoading(false);
} catch (error) {
toast.error(<ToastMessage title={error} icon={<IconFloppyDisk />} />, { icon: "" });
console.log("error when writing macros");
console.error(error);
toast.error(<ToastMessage title="Error when sending macros to the device" icon={<IconFloppyDisk />} />, { icon: "" });
cancelContext();
setLoading(false);
}
Expand Down Expand Up @@ -548,8 +559,10 @@ class MacroEditor extends React.Component {
try {
kbtype = focus.device && focus.device.info.keyboardType === "ISO" ? "iso" : "ansi";
} catch (error) {
console.log("error when reading focus.device and kbType for Macros");
console.error(error);
setLoading(false);
return false;
throw Error(error);
}

let tMem = await focus.command("macros.memory");
Expand All @@ -574,8 +587,10 @@ class MacroEditor extends React.Component {
cancelContext();
setLoading(false);
return true;
} catch (e) {
toast.error(<ToastMessage title={e} icon={<IconFloppyDisk />} />, { icon: "" });
} catch (error) {
console.log("error when loading macros");
console.error(error);
toast.error(<ToastMessage title="Error when loading macros from the device" icon={<IconLoader />} />, { icon: "" });
cancelContext();
setLoading(false);
onDisconnect();
Expand Down

0 comments on commit 5bca465

Please sign in to comment.