1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Improved battery state indication.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-31 16:17:52 -07:00
parent 8c321a5a0d
commit 6a70f1371a
5 changed files with 1694 additions and 1637 deletions

View file

@ -2648,7 +2648,7 @@
node.lastconnect = Date.now();
// Clear sesssion and battery information if needed
if ((node.conn & 1) == 0) { delete node.sessions; delete node.battery; }
if ((node.conn & 1) == 0) { delete node.sessions; }
// Web page update
masterUpdate(1 | 4 | 16);
@ -3183,10 +3183,33 @@
// Setup device notification
var devNotify = '';
if (node.sessions != null) {
if (view == 2) {
devNotify = '<img onclick=showDeviceSessions(\'' + node._id + '\',null,event) class=deviceNotifySmallDot src=images/icon-relay-notify10.png width=10 height=10>';
} else {
devNotify = '<img onclick=showDeviceSessions(\'' + node._id + '\',null,event) class=deviceNotifyDot src=images/icon-relay-notify.png width=16 height=16>';
// Sessions are active
if ((node.sessions.kvm != null) || (node.sessions.terminal != null) || (node.sessions.files != null)) {
if (view == 2) {
devNotify = '<img onclick=showDeviceSessions(\'' + node._id + '\',null,event) class=deviceNotifySmallDot src=images/icon-relay-notify10.png width=10 height=10>';
} else {
devNotify = '<img onclick=showDeviceSessions(\'' + node._id + '\',null,event) class=deviceNotifyDot src=images/icon-relay-notify.png width=16 height=16>';
}
}
// Battery state
if ((node.sessions.battery != null) && (view == 1)) {
var bat = node.sessions.battery;
var statestr = '';
if (bat.state == 'ac') { statestr = "Device is plugged-in"; }
if (bat.state == 'dc') { statestr = "Device is battery powered"; }
var levelstr = '', levelnum = -1;
if ((typeof bat.level == 'number') && (bat.level >= 0) && (bat.level <= 100)) {
levelstr = bat.level + '%';
levelnum = (Math.floor((bat.level + 10) / 25) + 1);
if (levelnum > 5) { lvl = 5; }
if (bat.state == 'ac') { if (bat.level == 100) { levelnum = 11; } else { levelnum += 5; } }
}
if (levelnum > 0) {
devNotify += '<div class="deviceBatterySmall deviceBatterySmall' + levelnum + '" title="' + ((statestr != null)?(statestr + ', ' + levelstr):levelstr) + '"></div>';
}
}
}
@ -5014,21 +5037,23 @@
QV('p10deviceBattery', false);
if ((currentNode.sessions != null) && (currentNode.sessions.battery != null)) {
var bat = currentNode.sessions.battery;
if (bat.state == 'ac') {
var statestr = '';
if (bat.state == 'ac') { statestr = "Device is plugged-in"; }
if (bat.state == 'dc') { statestr = "Device is battery powered"; }
var levelstr = '', levelnum = -1;
if ((typeof bat.level == 'number') && (bat.level >= 0) && (bat.level <= 100)) {
levelstr = bat.level + '%';
levelnum = (Math.floor((bat.level + 10) / 25) + 1);
if (levelnum > 5) { lvl = 5; }
if (bat.state == 'ac') { if (bat.level == 100) { levelnum = 11; } else { levelnum += 5; } }
}
if (levelnum > 0) {
Q('p10deviceBattery').title = (statestr != null)?(statestr + ', ' + levelstr):levelstr;
QV('p10deviceBattery', true);
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge6';
Q('p10deviceBattery').title = "Device is plugged-in";
} else {
Q('p10deviceBattery').title = format("Device is battery powered, {0}%", bat.level);
if ((typeof bat.level == 'number') && (bat.level >= 0) && (bat.level <= 100)) {
QV('p10deviceBattery', true);
var lvl = (Math.floor((bat.level + 10) / 25) + 1);
if (lvl > 5) { lvl = 5; }
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge' + lvl;
} else {
QV('p10deviceBattery', true);
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge5';
}
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge' + levelnum;
}
} else {
QV('p10deviceBattery', false);