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: added check to know if it's the first hardware Defy that's bein… #471

Merged
merged 1 commit into from
Jul 21, 2023
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
42 changes: 25 additions & 17 deletions src/renderer/views/LayoutEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,18 @@ class LayoutEditor extends React.Component {
keymapDB = new KeymapDB();

onLayerNameChange(newName) {
const layerNames = this.state.layerNames.slice();
layerNames[this.state.currentLayer] = {
id: this.state.currentLayer,
const { layerNames, currentLayer, neuronID } = this.state;
const slicedLayerNames = layerNames.slice();
slicedLayerNames[currentLayer] = {
id: currentLayer,
name: newName,
};
this.setState({
layerNames,
layerNames: slicedLayerNames,
});
const neurons = store.get("neurons");
console.log(`changed layer ${this.state.currentLayer} name to: ${newName}`, layerNames);
neurons[this.state.neuronID].layers = layerNames;
console.log(`changed layer ${currentLayer} name to: ${newName}`, slicedLayerNames);
neurons[neuronID].layers = slicedLayerNames;
store.set("neurons", neurons);
}

Expand All @@ -504,29 +505,29 @@ class LayoutEditor extends React.Component {
if (neurons === undefined) {
neurons = [];
}
if (neurons.some(n => n.id == chipID)) {
finalNeuron = neurons.filter(n => n.id == chipID)[0];
if (neurons.some(n => n.id === chipID)) {
finalNeuron = neurons.find(n => n.id === chipID);
}
if (!neurons.some(n => n.id == chipID) && neurons.length == 0) {
if (!neurons.some(n => n.id === chipID) && neurons.length === 0) {
const neuron = {};
neuron.id = chipID;
neuron.name = "";
neuron.layers =
store.get("layerNames") != undefined
store.get("layerNames") !== undefined
? store.get("layerNames").map((name, id) => ({
id,
name,
}))
: this.defaultLayerNames;
neuron.macros =
store.get("macros") != undefined
store.get("macros") !== undefined
? store.get("macros").map(macro => ({
id: macro.id,
name: macro.name,
}))
: [];
neuron.superkeys =
store.get("superkeys") != undefined
store.get("superkeys") !== undefined
? store.get("superkeys").map(sk => ({
id: sk.id,
name: sk.name,
Expand All @@ -537,7 +538,8 @@ class LayoutEditor extends React.Component {
store.set("neurons", neurons);
finalNeuron = neuron;
}
if (!neurons.some(n => n.id == chipID) && neurons.length > 0) {
const existingDefy = neurons.some(n => n.id.length < 32);
if (!neurons.some(n => n.id === chipID) && neurons.length > 0) {
const neuron = {};
neuron.id = chipID;
neuron.name = "";
Expand All @@ -550,10 +552,16 @@ class LayoutEditor extends React.Component {
neuronCopy.layers = neurons[0].layers;
neuronCopy.macros = neurons[0].macros;
neuronCopy.superkeys = neurons[0].superkeys;
const focus = new Focus();
console.log("Additional neuron", neuron);
const result = await window.confirm(
"A new Neuron was detected and new settings need to be created. The names of the layers, macros and Superkeys are empty. If you want to copy the names of your default Neuron (first in the list) click ‘Ok’. If you prefer to reset all names click ‘Cancel’.",
);
let result;
if (focus.device.info.product === "Defy" && !existingDefy) {
result = false;
} else {
result = await window.confirm(
"A new Neuron was detected and new settings need to be created. The names of the layers, macros and Superkeys are empty. If you want to copy the names of your default Neuron (first in the list) click ‘Ok’. If you prefer to reset all names click ‘Cancel’.",
);
}
// var result = await userAction;
console.log(result, neuron, neuronCopy);
if (result === false) {
Expand All @@ -570,7 +578,7 @@ class LayoutEditor extends React.Component {
console.log("Final neuron", finalNeuron);
this.setState({
neurons,
neuronID: neurons.findIndex(n => n.id == chipID),
neuronID: neurons.findIndex(n => n.id === chipID),
layerNames: finalNeuron.layers,
storedMacros: finalNeuron.macros,
storedSuper: finalNeuron.superkeys,
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/views/SelectKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ const SelectKeyboard: React.FC<SelectKeyboardProps> = (props): JSX.Element => {
// }
try {
const serialDevices = await focus.find(...Hardware.serial);
console.log("Printing devices: ", serialDevices);
// console.log("Printing devices: ", serialDevices);
const supportedDevices = [];
let device;
for (let i = 0; i < serialDevices.length; i += 1) {
device = serialDevices[i];
/* eslint-disable no-await-in-loop */
device.accessible = await focus.isDeviceAccessible(device);
console.log("before checking device supported", device, focus);
// console.log("before checking device supported", device, focus);
if (device.accessible && (await focus.isDeviceSupported(device))) {
supportedDevices.push(device);
} else if (!device.accessible) {
Expand All @@ -273,9 +273,9 @@ const SelectKeyboard: React.FC<SelectKeyboardProps> = (props): JSX.Element => {
console.log("Non serial keyboards", list);
setIsLoading(false);
setDevices(list);
if(connected){
if (connected) {
const connectedDev = list.findIndex(dev => focus.serialNumber?.includes(dev.serialNumber));
console.log("check connected", connectedDev);
// console.log("check connected", connectedDev);
setSelectedPortIndex(connectedDev);
}
return list;
Expand Down Expand Up @@ -565,7 +565,7 @@ const SelectKeyboard: React.FC<SelectKeyboardProps> = (props): JSX.Element => {

const selectedDevice = devices && devices[selectedPortIndex];
const connectedDevice = devices && devices.findIndex(dev => focus.serialNumber?.includes(dev.serialNumber));
console.log("Checking connected Data: ", connectedDevice, selectedPortIndex);
// console.log("Checking connected Data: ", connectedDevice, selectedPortIndex);
return (
<Styles>
<Container fluid className="keyboard-select center-content">
Expand Down