Skip to content

Commit

Permalink
feat: 🔥 add custom sets in preferences and default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dewiweb committed Feb 27, 2024
1 parent 45b6da9 commit 4c97d28
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 57 deletions.
31 changes: 17 additions & 14 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<option value="ad">AD</option>
<option value="xyz">XYZ</option>
<option value="xy">XY</option>
<option value="custom1">Custom1</option>
<option value="custom2">Custom2</option>
<option value="custom3">Custom3</option>
</select>
<br>
<script>
Expand Down Expand Up @@ -146,38 +149,38 @@
</td>
</tr>
<tr>
<td style="visibility: hidden">
<input type="text" id="at_tr_x" name="at_tr_y" value="/x++" />
<td class="at" style="visibility: hidden">
<input type="text" id="at_tr_x" name="at_tr_y" value="/x++" />
</td>
<td style="visibility: hidden">
<input type="text" id="at_tr_y" name="at_tr_y" value="/y++" />
<td class="at" style="visibility: hidden">
<input type="text" id="at_tr_y" name="at_tr_y" value="/y++" />
</td>
<td style="visibility: hidden">
<td class="at" style="visibility: hidden">
<input type="text" id="at_tr_z" name="at_tr_z" value="/z++" />
</td>
<td style="visibility: visible">
<td class="at" style="visibility: visible">
<input type="text" id="at_rt_x" name="at_rt_x" value="/elev++"/>
</td>
<td style="visibility: visible">
<td class="at" style="visibility: visible">
<input type="text" id="at_rt_y" name="at_rt_y" value="/azim++"/>
</td>
<td style="visibility: visible">
<td class="at" style="visibility: visible">
<input type="text" id="at_rt_z" name="at_rt_z" value="/dist++"/>
</td>
</tr>
<tr>
<td style="visibility: hidden">
<td class="value" style="visibility: hidden">
<input type="number" id="tr_x" name="tr_x" value="0" step="0.1"/>
</td>
<td style="visibility: hidden">
<td class="value" style="visibility: hidden">
<input type="number" id="tr_y" name="tr_y" value="0" step="0.1"/>
</td>
<td style="visibility: hidden">
<td class="value" style="visibility: hidden">
<input type="number" id="tr_z" name="tr_z" value="0" step="0.1"/>
</td>
<td style="visibility: visible"><input type="number" id="rt_x" name="rt_x" value="0" step="0.1"/></td>
<td style="visibility: visible"><input type="number" id="rt_y" name="rt_y" value="0" step="0.1"/></td>
<td style="visibility: visible"><input type="number" id="rt_z" name="rt_z" value="0" step="0.1"/></td>
<td class="value" style="visibility: visible"><input type="number" id="rt_x" name="rt_x" value="0" step="0.1"/></td>
<td class="value" style="visibility: visible"><input type="number" id="rt_y" name="rt_y" value="0" step="0.1"/></td>
<td class="value" style="visibility: visible"><input type="number" id="rt_z" name="rt_z" value="0" step="0.1"/></td>
</tr>
<tr>
<td>
Expand Down
71 changes: 67 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function createWindow() {
icon: `${__dirname}/assets/icons/64x64.png`
})
win.setMenu(null);
win.loadFile('src/index.html')
win.loadFile('src/index.html');
//win.webContents.openDevTools({ mode: "detach" });


Expand All @@ -80,6 +80,15 @@ function createWindow() {
"default_precision": "100000",
"default_send_rate": "33",
"default_factor": "1",
},
"paths_sets": {
"aed": "[,,,elev++,azim++,dist++]",
"ad": "[,,,,azim++,dist++]",
"xyz": "[x++,y++,z++,,,]",
"xy": "[x++,y++,,,,]",
"custom1": "[x,y,z,pitch,roll,yaw]",
"custom2": "[,,,,,]",
"custom3": "[,,,,,]",
}
},
sections: [
Expand All @@ -102,6 +111,9 @@ function createWindow() {
{ label: 'AD', value: 'ad' },
{ label: 'XYZ', value: 'xyz' },
{ label: 'XY', value: 'xy' },
{ label: 'Custom1', value: 'custom1' },
{ label: 'Custom2', value: 'custom2' },
{ label: 'Custom3', value: 'custom3' },
],
help: 'AED is default',
},
Expand Down Expand Up @@ -175,6 +187,56 @@ function createWindow() {
],
},
},
{
id: 'paths_sets',
label: 'Paths Settings ',
icon: 'preferences',
form: {
groups: [
{
label: 'SETS',
fields: [
{
label: 'AED',
key: 'aed',
type: 'text',
},
{
label: 'AD',
key: 'ad',
type: 'text',
},
{
label: 'XYZ',
key: 'xyz',
type: 'text',
},
{
label: 'XY',
key: 'xy',
type: 'text',
},
{
label: 'Custom set 1',
key: 'custom1',
type: 'text',
},
{
label: 'Custom set 2',
key: 'custom2',
type: 'text',
},
{
label: 'Custom set 3',
key: 'custom3',
type: 'text',
}

],
},

],},
},
{
id: 'other_settings',
label: 'Other Settings',
Expand Down Expand Up @@ -463,10 +525,11 @@ function oscListening() {
function handleMode(args) {
// Function implementation for handling "/mode" address
const modeValue = args[0].value;
if (modeValue === "aed"|| modeValue === "ad"|| modeValue === "xyz"|| modeValue === "xy") {
win.webContents.send("modeChanged", modeValue);
if (modeValue === "aed"|| modeValue === "ad"|| modeValue === "xyz"|| modeValue === "xy" || modeValue ==="custom1" || modeValue ==="custom2" || modeValue ==="custom3") {
modeSet = preferences.value('paths_sets.' + modeValue);
win.webContents.send("modeChanged", modeValue, modeSet);
}else{
win.webContents.send("logInfo", "Invalid mode value: " + modeValue);
win.webContents.send("logInfo", "Invalid mode value: " + modeValue + modeSet);
}
}

Expand Down
117 changes: 78 additions & 39 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ const preferences = ipcRenderer.sendSync('getPreferences');
const log = require('electron-log');
const _ = require('lodash');
const modeFunctions = {
aed: aedMode,
ad: adMode,
xyz: xyzMode,
xy: xyMode
aed: customMode,
ad: customMode,
xyz: customMode,
xy: customMode,
custom1: customMode,
custom2: customMode,
custom3: customMode
};

function initInputs() {
Expand Down Expand Up @@ -211,9 +214,13 @@ function displayForm3(event) {

function modeChange(event) {
selection = event.target.value;
console.log("modeChange_selection: ",selection)
document.getElementById("mode").value = selection;
console.log("preferencesOnRendererSide",preferences)
set = preferences.paths_sets[selection];
console.log("set: ",set)
if (modeFunctions[selection]) {
modeFunctions[selection]();
modeFunctions[selection](selection,set);
}
}

Expand All @@ -230,48 +237,80 @@ function updateButtons(bypButtons, start, end, className, text) {
}
}

function aedMode() {
setVisibility(["tr_x", "tr_y", "tr_z","at_tr_x", "at_tr_y", "at_tr_z"], "hidden");
setVisibility(["rt_x", "rt_y", "rt_z","at_rt_x", "at_rt_y", "at_rt_z"], "visible");

const bypButtons = document.querySelectorAll(".byp");
updateButtons(bypButtons, 1, 4, "button byp", "Enable");
updateButtons(bypButtons, 4, 7, "button_up byp", "Bypass");
}

function adMode() {
setVisibility(["tr_x", "tr_y", "tr_z", "rt_x", "at_tr_x", "at_tr_y", "at_tr_z","at_rt_x"], "hidden");
setVisibility(["rt_y", "rt_z", "at_rt_y", "at_rt_z"], "visible");
//function aedMode() {
// setVisibility(["tr_x", "tr_y", "tr_z","at_tr_x", "at_tr_y", "at_tr_z"], "hidden");
// setVisibility(["rt_x", "rt_y", "rt_z","at_rt_x", "at_rt_y", "at_rt_z"], "visible");
//
// const bypButtons = document.querySelectorAll(".byp");
// updateButtons(bypButtons, 1, 4, "button byp", "Enable");
// updateButtons(bypButtons, 4, 7, "button_up byp", "Bypass");
//}
//
//function adMode() {
// setVisibility(["tr_x", "tr_y", "tr_z", "rt_x", "at_tr_x", "at_tr_y", "at_tr_z","at_rt_x"], "hidden");
// setVisibility(["rt_y", "rt_z", "at_rt_y", "at_rt_z"], "visible");
//
// const bypButtons = document.querySelectorAll(".byp");
// updateButtons(bypButtons, 1, 5, "button byp", "Enable");
// updateButtons(bypButtons, 5, 7, "button_up byp", "Bypass");
//}
//
//function xyzMode() {
// setVisibility(["rt_x", "rt_y", "rt_z","at_rt_x", "at_rt_y", "at_rt_z"], "hidden");
// setVisibility(["tr_x", "tr_y", "tr_z","at_tr_x", "at_tr_y", "at_tr_z"], "visible");
//
// const bypButtons = document.querySelectorAll(".byp");
// updateButtons(bypButtons, 1, 4, "button_up byp", "Bypass");
// updateButtons(bypButtons, 4, 7, "button byp", "Enable");
//}
//
//function xyMode() {
// setVisibility(["rt_x", "rt_y","rt_z" ,"tr_z", "at_rt_x", "at_rt_y", "at_rt_z", "at_tr_z"], "hidden");
// setVisibility(["tr_x", "tr_y", "at_tr_x", "at_tr_y"], "visible");
//
// const bypButtons = document.querySelectorAll(".byp");
// updateButtons(bypButtons, 1, 4, "button_up byp", "Bypass");
// updateButtons(bypButtons, 4, 7, "button byp", "Enable");
// bypButtons[3].className = "button byp";
// bypButtons[3].innerHTML = "Enable";
//}

const bypButtons = document.querySelectorAll(".byp");
updateButtons(bypButtons, 1, 5, "button byp", "Enable");
updateButtons(bypButtons, 5, 7, "button_up byp", "Bypass");
function setAtVisibility(elementIds, visibility) {
elementIds.forEach((id) => {
document.getElementById(id).style.visibility = visibility;
});
}

function xyzMode() {
setVisibility(["rt_x", "rt_y", "rt_z","at_rt_x", "at_rt_y", "at_rt_z"], "hidden");
setVisibility(["tr_x", "tr_y", "tr_z","at_tr_x", "at_tr_y", "at_tr_z"], "visible");

const bypButtons = document.querySelectorAll(".byp");
updateButtons(bypButtons, 1, 4, "button_up byp", "Bypass");
updateButtons(bypButtons, 4, 7, "button byp", "Enable");
function customMode(mode,set) {
console.log("set: ",set)
modeArray = JSON.parse(set);
atArray = document.querySelectorAll(".at");
valueArray = document.querySelectorAll(".value");
bypArray = document.querySelectorAll(".byp");
quadrupletArray = (modeArray.map((element,index)=>[element,atArray[index],valueArray[index],bypArray[index+1]]));
for (i=0;i<quadrupletArray.length;i++){
if (!quadrupletArray[i][0]){
bypArray[i+1].className = "button byp";
bypArray[i+1].innerHTML = "Enable";
atArray[i].style.visibility = 'hidden';
valueArray[i].style.visibility = 'hidden';
}else{
bypArray[i+1].className = "button_up byp";
bypArray[i+1].innerHTML = "Bypass";
atArray[i].style.visibility = 'visible';
atArray[i].firstElementChild.value = "/"+quadrupletArray[i][0];
valueArray[i].style.visibility = 'visible';
}
}

}

function xyMode() {
setVisibility(["rt_x", "rt_y","rt_z" ,"tr_z", "at_rt_x", "at_rt_y", "at_rt_z", "at_tr_z"], "hidden");
setVisibility(["tr_x", "tr_y", "at_tr_x", "at_tr_y"], "visible");

const bypButtons = document.querySelectorAll(".byp");
updateButtons(bypButtons, 1, 4, "button_up byp", "Bypass");
updateButtons(bypButtons, 4, 7, "button byp", "Enable");
bypButtons[3].className = "button byp";
bypButtons[3].innerHTML = "Enable";
}

ipcRenderer.on("modeChanged", (event, mode) => {
ipcRenderer.on("modeChanged", (event, mode,set) => {
if (modeFunctions[mode]) {
//modeSet = preferences.value('paths_sets.' + modeValue)
document.getElementById("mode").value = mode;
modeFunctions[mode]();
modeFunctions[mode](mode,set);
} else {
// Handle the case where the mode is not found
logger("Unknown mode:", mode);
Expand Down

0 comments on commit 4c97d28

Please sign in to comment.