Skip to content

Commit

Permalink
Switches and dropdown now keep their values when pages are switched
Browse files Browse the repository at this point in the history
  • Loading branch information
ejj28 committed Apr 13, 2020
1 parent 3ac9a72 commit c605ebe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
26 changes: 24 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var midiConfig;

var advancedDebug = false;
var keysMode = false;
var isMidiSelected = false;
var selectedMidiPort = "";

var win;

Expand Down Expand Up @@ -55,7 +57,7 @@ function createWindow () {
});

win.loadFile('src/index.html');
win.setMenu(null);
//win.setMenu(null);
}

ipcMain.on('getVjoyStatus', (event, arg) => {
Expand All @@ -79,6 +81,10 @@ ipcMain.on('debugTypeChange', (event, arg) => {
}
});

ipcMain.on('getDebugType', (event, arg) => {
event.returnValue = advancedDebug;
});

ipcMain.on('inputTypeChange', (event, arg) => {
if (arg == true) {
keysMode = true;
Expand All @@ -87,6 +93,20 @@ ipcMain.on('inputTypeChange', (event, arg) => {
}
});

ipcMain.on('getKeysSwitchState', (event, arg) => {
event.returnValue = keysMode;
});

ipcMain.on('getIsMidiSelected', (event, arg) => {
event.returnValue = isMidiSelected;
});

ipcMain.on('getMidiSelected', (event, arg) => {
event.returnValue = selectedMidiPort;
});



ipcMain.on('saveDrumPad', (event, arg) => {
storage.get('config', (error, data) => {
if (error) throw error;
Expand Down Expand Up @@ -128,7 +148,9 @@ ipcMain.on('getMidiDevices', (event, arg) => {

ipcMain.on('openMidi', (event, arg) => {
input.closePort()
input.openPort(arg)
input.openPort(arg[0])
isMidiSelected = true;
selectedMidiPort = arg[1]
});

function vJoySetButton(button, state) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h5 class="modal-title" id="staticBackdropLabel">New Drum Pad</h5>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
<div class="dropdown">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<button class="btn btn-secondary btn-sm dropdown-toggle" id="midiDropdownButton" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Midi Device
<span class="caret"></span>
</button>
Expand Down
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ $(document).ready(() => {
alert("vJoy is either not installed or enabled, please fix this and then reopen MidiDrumHero")
}

var keysSwitchState = ipcRenderer.sendSync('getKeysSwitchState');
document.getElementById("keysSwitch").checked = keysSwitchState;



//var keysSwitchState = ipcRenderer.sendSync('getKeysSwitchState');

// Add drumpads to the table for the user to see
var data = ipcRenderer.sendSync('getDrumPads');
for (drumPad in data) {
Expand All @@ -40,6 +47,14 @@ $(document).ready(() => {
// Remove the message in dropdown if there are Midi Devices available
if (Object.keys(midiDevices).length > 0) {
$('#dropdownMidi').children("li").remove();

if (ipcRenderer.sendSync('getIsMidiSelected') == true) {
selectedMidi = ipcRenderer.sendSync('getMidiSelected')
$("#midiDropdownButton").html(selectedMidi + ' <span class="caret"></span>');

//$(this).parents(".dropdown").find('.btn').val($(this).data('value'));
}

}

var midiDeviceKeys = Object.keys(midiDevices)
Expand All @@ -54,7 +69,7 @@ $(document).ready(() => {
$("#dropdownMidi li a").click(function(){
$(this).parents(".dropdown").find('.btn').html($(this).text() + ' <span class="caret"></span>');
$(this).parents(".dropdown").find('.btn').val($(this).data('value'));
ipcRenderer.send('openMidi', $(this).data('value'));
ipcRenderer.send('openMidi', [$(this).data('value'), $(this).text()]);
});

});
Expand Down
5 changes: 5 additions & 0 deletions src/monitor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const {ipcRenderer} = require('electron');
const shell = require('electron').shell;

$(document).ready(() => {
var advSwitchState = ipcRenderer.sendSync('getDebugType');
document.getElementById("advSwitch").checked = advSwitchState;
})

$('#advSwitch').click(() => {
var checkedValue = document.querySelector('#advSwitch').checked;
if (checkedValue == true) {
Expand Down

0 comments on commit c605ebe

Please sign in to comment.