Skip to content

Commit

Permalink
toggle command log
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-Sch committed Jan 19, 2022
1 parent a0ec68f commit e78d35e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 68 deletions.
18 changes: 10 additions & 8 deletions html/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<div class="row">
<div class="col-xs-12 col-md-6">
<button type="button" class="btn btn-success btn-block" id="start-miner-cpu" onclick="startMiner('cpu', false)">Start the cpu miner</button>
<button type="button" class="btn btn-secondary btn-block" data-bs-toggle="modal" data-bs-target="#advancedcpu">Advanced CPU options</button>
<button type="button" class="btn btn-secondary btn-block" data-bs-toggle="modal" data-bs-target="#advanced-cpu">Advanced CPU options</button>
</div>
<div class="col-xs-12 col-md-6">
<button disabled type="button" class="btn btn-success btn-block" id="start-miner-gpu" onclick="startMiner('gpu', false)">Start the gpu miner</button>
<button type="button" class="btn btn-secondary btn-block" data-bs-toggle="modal" data-bs-target="#advancedgpu">Advanced GPU options</button>
<button type="button" class="btn btn-secondary btn-block" data-bs-toggle="modal" data-bs-target="#advanced-gpu">Advanced GPU options</button>
</div>
</div>
<div class="row">
Expand All @@ -47,15 +47,16 @@
</div>
</div>

<div class="modal fade" id="advancedcpu" tabindex="-1" aria-labelledby="advancedcpuLabel" aria-hidden="true">
<div class="modal fade" id="advanced-cpu" tabindex="-1" aria-labelledby="advanced-cpuLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="advancedcpuLabel">Advanced CPU options</h5>
<h5 class="modal-title" id="advanced-cpuLabel">Advanced CPU options</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">x</button>
</div>
<div class="modal-body">
<button class="btn btn-danger btn-block" type="button" onclick="resetXmrig('cpu')">Reset CPU configuration</button>
<button class="btn btn-danger btn-block" type="button" onclick="resetConfig('cpu')">Reset CPU configuration</button>
<button id="show-cpu-logs" class="btn btn-danger btn-block" type="button" onclick="showLog('cpu', false)">Hide CPU logs</button>
<hr>
<p>DON'T CHANGE this unless you know what you're doing (which you DON'T). To save, start the miner at least once.</p>
<div class="input-group mb-3">
Expand All @@ -79,15 +80,16 @@ <h5 class="modal-title" id="advancedcpuLabel">Advanced CPU options</h5>
</div>
</div>

<div class="modal fade" id="advancedgpu" tabindex="-1" aria-labelledby="advancedgpuLabel" aria-hidden="true">
<div class="modal fade" id="advanced-gpu" tabindex="-1" aria-labelledby="advanced-gpuLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="advancedgpuLabel">Advanced GPU options</h5>
<h5 class="modal-title" id="advanced-gpuLabel">Advanced GPU options</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">x</button>
</div>
<div class="modal-body">
<button class="btn btn-danger btn-block" type="button" onclick="resetXmrig('gpu')">Reset GPU configuration</button>
<button class="btn btn-danger btn-block" type="button" onclick="resetConfig('gpu')">Reset GPU configuration</button>
<button id="show-gpu-logs" class="btn btn-danger btn-block" type="button" onclick="showLog('gpu', false)">Hide GPU logs</button>
<hr>
<p>DON'T CHANGE this unless you know what you're doing (which you DON'T). To save, start the miner at least once.</p>
<div class="input-group mb-3">
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ if (!gotTheLock && app.isPackaged) {
const userDataPath = electron.app.getPath('userData');

const xmrigFolderPath = join(userDataPath, 'xmrig');
if (!existsSync(xmrigFolderPath)) return currentWindow.webContents.send('resetXmrigStatus', { type, message: 'There is no existing config'});
if (!existsSync(xmrigFolderPath)) return currentWindow.webContents.send('resetXmrigStatus', { type, message: 'Reset the config'});

const configPath = join(userDataPath, `xmrig/${type}.json`);
if (!existsSync(configPath)) return currentWindow.webContents.send('resetXmrigStatus', { type, message: 'There is no existing config' });
if (!existsSync(configPath)) return currentWindow.webContents.send('resetXmrigStatus', { type, message: 'Reset the config' });

unlinkSync(configPath);
return currentWindow.webContents.send('resetXmrigStatus', { type, message: `Deleted the config` });
return currentWindow.webContents.send('resetXmrigStatus', { type, message: `Reset the config` });
});

ipcMain.on('startMiner', async (event, { username, type, reload, command }) => {
Expand Down
133 changes: 77 additions & 56 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,18 @@ const currentData = new SaveData({
configName: 'current',
});

let oldUsername = undefined;
let oldCpuCommand = undefined;
let oldCpuCommandChecked = undefined;
let oldGpuCommand = undefined;
let oldGpuCommandChecked = undefined;
let mining = { cpu: false, gpu: false };

const userNameInput = document.getElementById('username');
const cpuMinerButton = document.getElementById('start-miner-cpu');
const log = document.getElementById('log');

const getPrevious = setInterval(() => {
if (!oldUsername) {
oldUsername = savedata.get('username');
if (oldUsername) {
userNameInput.value = oldUsername;
}
}

if (!oldCpuCommand) {
oldCpuCommand = savedata.get('cpu-command');
if (oldCpuCommand) {
command = oldCpuCommand.split(' ');
document.getElementById('custom-command-cpu-file').value = command[0];
document.getElementById('custom-command-cpu-flags').value = command.slice(1).join(' ');
}
}

if (!oldCpuCommandChecked) {
oldCpuCommandChecked = savedata.get('cpu-command-checked');
if (oldCpuCommandChecked) {
document.getElementById('custom-command-cpu-enabled').checked = true;
}
}

if (!oldGpuCommand) {
oldGpuCommand = savedata.get('gpu-command');
if (oldGpuCommand) {
command = oldGpuCommand.split(' ');
document.getElementById('custom-command-gpu-file').value = command[0];
document.getElementById('custom-command-gpu-flags').value = command.slice(1).join(' ');
}
}

if (!oldGpuCommandChecked) {
oldGpuCommandChecked = savedata.get('gpu-command-checked');
if (oldGpuCommandChecked) {
document.getElementById('custom-command-gpu-enabled').checked = true;
}
}

if (!!oldUsername && !!oldCpuCommand && !!oldGpuCommand) {
return clearInterval(getPrevious);
}
}, 500);

const startMiner = (type, reload) => {
cpuMinerButton.onclick = () => { startMiner('cpu', false) };
const username = getUsername();
if (!username || typeof username !== 'string') return logFunction('username', 'An invalid username is specified');

let command = false;
let command = null;

const enabled = document.getElementById(`custom-command-${type}-enabled`).checked;
if (enabled) {
Expand Down Expand Up @@ -104,9 +54,7 @@ ipcRenderer.on('miner-status', (event, { type, status, reload }) => {
});

ipcRenderer.on('resetXmrigStatus', (event, { type, message }) => {
const myModalEl = document.getElementById(`advanced${type}`);
const modal = bootstrap.Modal.getInstance(myModalEl);
modal.hide();
closeModal(type);

return logFunction(type, message);
});
Expand All @@ -131,12 +79,85 @@ const getUsername = () => {
return username;
}

const resetXmrig = (type) => {
const resetConfig = (type) => {
if (mining[type]) return alert('You can not reset the configuration while mining!');

showLog(type, true);
document.getElementById(`custom-command-${type}-enabled`).checked = false;
document.getElementById(`custom-command-${type}-file`).value = null;
document.getElementById(`custom-command-${type}-flags`).value = null;

savedata.set(`${type}-command`, null);
savedata.set(`${type}-command-checked`, false);

return ipcRenderer.send('resetXmrig', { type });
}

const showLog = (type, show) => {
const logEl = document.getElementById(`${type}-log`);
const buttonEl = document.getElementById(`show-${type}-logs`);

savedata.set(`show-${type}-log`, show);
closeModal(type);


if (show) {
logEl.style = "display: block";
buttonEl.innerHTML = `Hide ${type.toUpperCase()} logs`;
return buttonEl.onclick = () => { showLog(type, !show) };
} else {
logEl.style = "display: none";
buttonEl.innerHTML = `Show ${type.toUpperCase()} logs`;
return buttonEl.onclick = () => { showLog(type, !show) };
}
}

const logFunction = (type, message) => {
return log.innerHTML = `<tr><th scope=\"row\">${type}</th><th>${message}</th></tr>` + log.innerHTML;
}
}

const loadSaved = () => {
const oldUsername = savedata.get('username');
if (oldUsername !== null) userNameInput.value = oldUsername;

const oldCpuCommand = savedata.get('cpu-command');
if (oldCpuCommand !== null && oldGpuCommand !== undefined) {
const command = oldCpuCommand.split(' ');
document.getElementById('custom-command-cpu-file').value = command[0];
document.getElementById('custom-command-cpu-flags').value = command.slice(1).join(' ');
}

const oldCpuCommandChecked = savedata.get('cpu-command-checked');
if (oldCpuCommandChecked !== null) document.getElementById('custom-command-cpu-enabled').checked = oldCpuCommandChecked;

const oldCpuShowLog = savedata.get('show-cpu-log');
if (oldCpuShowLog !== null) showLog('cpu', oldCpuShowLog);

const oldGpuCommand = savedata.get('gpu-command');
if (oldGpuCommand !== null && oldGpuCommand !== undefined) {
const command = oldGpuCommand.split(' ');
document.getElementById('custom-command-gpu-file').value = command[0];
document.getElementById('custom-command-gpu-flags').value = command.slice(1).join(' ');
}

const oldGpuCommandChecked = savedata.get('gpu-command-checked');
if (oldGpuCommandChecked !== null) document.getElementById('custom-command-gpu-enabled').checked = true;

const oldGpuShowLog = savedata.get('show-gpu-log');
if (oldCpuShowLog !== null) showLog('gpu', oldCpuShowLog);

return logFunction('config', 'Configuration loaded');
}

const closeModal = (type) => {
const myModalEl = document.getElementById(`advanced-${type}`);
const modal = bootstrap.Modal.getInstance(myModalEl);

if (!modal) return;
return modal.hide();
}


setTimeout(() => {
loadSaved();
}, 2000);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "robinsch-miner",
"version": "1.1.4",
"version": "1.1.5",
"description": "My GUI crypto miner",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e78d35e

Please sign in to comment.