Skip to content

Commit

Permalink
Display current active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang Ning committed Apr 11, 2016
1 parent ee340e4 commit 833c6f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<header class="toolbar toolbar-header">
<div class="toolbar-actions">
<div class="btn-group">
<button class="btn btn-default" onclick="switchDisplay('cpu')">
<button id="cpu-btn" class="btn btn-default" onclick="switchDisplay('cpu')">
<i class="icon-processorthree"></i>
CPU
</button>
<button class="btn btn-default" onclick="switchDisplay('mem')">
<button id="mem-btn" class="btn btn-default" onclick="switchDisplay('mem')">
<i class="icon-sd"></i>
RAM
</button>
Expand Down
39 changes: 21 additions & 18 deletions js/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,48 +127,51 @@ function showMemStats() {
}

var currentDisplay = 'cpu';
showCpuStats();
switchDisplay(currentDisplay);

ipc.on('show', function() {
if (currentDisplay === 'cpu')
showCpuStats();
else if (currentDisplay === 'mem')
showMemStats();
switchDisplay(currentDisplay);
});

ipc.on('after_hide', function() {
exitTopProcs();
exitAllMonitors();

cpu_monitor = null;
mem_monitor = null;
cpu_chart = null;
});

function exitTopProcs() {
if (cpu_monitor)
cpu_monitor.emit('exit');
function exitMonitor(monitor) {
if (monitor) {
monitor.emit('exit');
monitor = null;
}
}

if (mem_monitor)
mem_monitor.emit('exit');
function exitAllMonitors() {
exitMonitor(cpu_monitor);
exitMonitor(mem_monitor);
}

function switchDisplay(display) {
currentDisplay = display;

if (currentDisplay === 'cpu') {
showCpuStats();
mem_monitor.emit('exit');
mem_monitor = null;
exitMonitor(mem_monitor);

document.getElementById('mem-btn').classList.remove('active');
}
else if (currentDisplay === 'mem') {
showMemStats();
cpu_monitor.emit('exit');
cpu_monitor = null;
exitMonitor(cpu_monitor);

document.getElementById('cpu-btn').classList.remove('active');
}

document.getElementById(display + '-btn').classList.add('active');
}

function quit() {
exitTopProcs();
exitAllMonitors();
ipc.send('quit');
}

Expand Down

0 comments on commit 833c6f9

Please sign in to comment.