未验证 提交 04e434e2 编写于 作者: S Surge 提交者: GitHub

Fix TypeError with toplist modal (#930)

* Fix TypeError with toplist modal

* Remove check if modal is closed and use clearInterval to stop calling of function

* Redo check so if modal is removed it stops calling the functions
上级 a329b360
......@@ -54,6 +54,7 @@ class Toplist {
processList(){
let sortKey;
let ascending = false;
let removed = false;
function setSortKey(fieldName){
if (sortKey === fieldName){
......@@ -89,16 +90,16 @@ class Toplist {
return `${days < 10 ? "0" : ""}${days}:${hours < 10 ? "0" : ""}${hours}:${minutes < 10 ? "0" : ""}${minutes}:${seconds < 10 ? "0" : ""}${seconds}`;
}
function updateProcessList(){
function updateProcessList() {
window.si.processes().then(data => {
if (window.settings.excludeThreadsFromToplist === true) {
data.list = data.list.sort((a, b) => {
return (a.pid-b.pid);
return (a.pid - b.pid);
}).filter((e, index, a) => {
let i = a.findIndex(x => x.name === e.name);
if (i !== -1 && i !== index) {
a[i].pcpu = a[i].pcpu+e.pcpu;
a[i].pmem = a[i].pmem+e.pmem;
a[i].pcpu = a[i].pcpu + e.pcpu;
a[i].pmem = a[i].pmem + e.pmem;
return false;
}
return true;
......@@ -111,69 +112,72 @@ class Toplist {
let list = data.list.sort((a, b) => {
switch (sortKey) {
case "PID":
if (ascending) return a.pid - b.pid;
else return b.pid - a.pid;
case "Name":
if (ascending){
if (a.name > b.name) return -1;
if (a.name < b.name) return 1;
case "PID":
if (ascending) return a.pid - b.pid;
else return b.pid - a.pid;
case "Name":
if (ascending) {
if (a.name > b.name) return -1;
if (a.name < b.name) return 1;
return 0;
}
else {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
}
case "User":
if (ascending) {
if (a.user > b.user) return -1;
if (a.user < b.user) return 1;
return 0;
}
else {
if (a.user < b.user) return -1;
if (a.user > b.user) return 1;
return 0;
}
case "CPU":
if (ascending) return a.pcpu - b.pcpu;
else return b.pcpu - a.pcpu;
case "Memory":
if (ascending) return a.pmem - b.pmem;
else return b.pmem - a.pmem;
case "State":
if (a.state < b.state) return -1;
if (a.state > b.state) return 1;
return 0;
}
else {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
}
case "User":
if (ascending){
if (a.user > b.user) return -1;
if (a.user < b.user) return 1;
return 0;
}
else {
if (a.user < b.user) return -1;
if (a.user > b.user) return 1;
return 0;
}
case "CPU":
if (ascending) return a.pcpu - b.pcpu;
else return b.pcpu - a.pcpu;
case "Memory":
if (ascending) return a.pmem - b.pmem;
else return b.pmem - a.pmem;
case "State":
if (a.state < b.state) return -1;
if (a.state > b.state) return 1;
return 0;
case "Started":
if (ascending) return Date.parse(a.started) - Date.parse(b.started);
else return Date.parse(b.started) - Date.parse(a.started);
case "Runtime":
if (ascending) return a.runtime - b.runtime;
else return b.runtime - a.runtime;
default:
// default to the same sorting as the toplist
return ((b.pcpu-a.pcpu)*100 + b.pmem-a.pmem);
case "Started":
if (ascending) return Date.parse(a.started) - Date.parse(b.started);
else return Date.parse(b.started) - Date.parse(a.started);
case "Runtime":
if (ascending) return a.runtime - b.runtime;
else return b.runtime - a.runtime;
default:
// default to the same sorting as the toplist
return ((b.pcpu - a.pcpu) * 100 + b.pmem - a.pmem);
}
});
if (removed) clearInterval(updateInterval);
else {
document.querySelectorAll("#processList > tr").forEach(el => {
el.remove();
});
document.querySelectorAll("#processList > tr").forEach(el => {
el.remove();
});
list.forEach(proc => {
let el = document.createElement("tr");
el.innerHTML = `<td class="pid">${proc.pid}</td>
<td class="name">${proc.name}</td>
<td class="user">${proc.user}</td>
<td class="cpu">${Math.round(proc.pcpu*10)/10}%</td>
<td class="mem">${Math.round(proc.pmem*10)/10}%</td>
<td class="state">${proc.state}</td>
<td class="started">${proc.started}</td>
<td class="runtime">${formatRuntime(proc.runtime)}</td>`;
document.getElementById("processList").append(el);
});
list.forEach(proc => {
let el = document.createElement("tr");
el.innerHTML = `<td class="pid">${proc.pid}</td>
<td class="name">${proc.name}</td>
<td class="user">${proc.user}</td>
<td class="cpu">${Math.round(proc.pcpu * 10) / 10}%</td>
<td class="mem">${Math.round(proc.pmem * 10) / 10}%</td>
<td class="state">${proc.state}</td>
<td class="started">${proc.started}</td>
<td class="runtime">${formatRuntime(proc.runtime)}</td>`;
document.getElementById("processList").append(el);
});
}
});
}
......@@ -199,6 +203,10 @@ class Toplist {
<tbody id=\"processList\">
</tbody>
</table>`,
},
() => {
removed = true;
//clearInterval(updateInterval);
}
);
......@@ -219,7 +227,7 @@ class Toplist {
updateProcessList();
window.keyboard.attach();
window.term[window.currentTerm].term.focus();
setInterval(updateProcessList, 1000);
var updateInterval = setInterval(updateProcessList, 1000);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册