kopia lustrzana https://github.com/c9/core
Merge pull request +15340 from c9/process-list
backport preview changes from v4pull/198/merge
commit
11ab9610b9
|
@ -192,7 +192,7 @@ define(function(require, exports, module) {
|
||||||
var panels = navigation && navigation.$ext && navigation.$ext.children;
|
var panels = navigation && navigation.$ext && navigation.$ext.children;
|
||||||
if (panels) {
|
if (panels) {
|
||||||
for (var i = 0; i < panels.length; i++) {
|
for (var i = 0; i < panels.length; i++) {
|
||||||
if (panels[i].name == panel) {
|
if (panels[i].name == panel || panels[i].name == "preferences." + panel) {
|
||||||
panel = panels[i].hostPlugin;
|
panel = panels[i].hostPlugin;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,27 +64,8 @@ define(function(require, exports, module) {
|
||||||
if (!options.hideButton) {
|
if (!options.hideButton) {
|
||||||
var submenu = new ui.menu({
|
var submenu = new ui.menu({
|
||||||
"onprop.visible": function(e) {
|
"onprop.visible": function(e) {
|
||||||
var tab = tabs.focussedTab;
|
if (e.value)
|
||||||
var isKnown = false;
|
updatePreviewMenu(e, submenu);
|
||||||
|
|
||||||
if (tab && tab.path) {
|
|
||||||
var path = tab.path;
|
|
||||||
for (var name in previewers) {
|
|
||||||
if (previewers[name].matcher(path)) {
|
|
||||||
isKnown = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
liveMenuItem.setAttribute("caption", isKnown
|
|
||||||
? "Live Preview File (" + basename(path) + ")"
|
|
||||||
: "Raw Content of " + basename(path)
|
|
||||||
);
|
|
||||||
liveMenuItem.enable();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
liveMenuItem.disable();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -99,7 +80,7 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
menus.addItemByPath("Tools/Preview/", submenu, 1000, handle);
|
menus.addItemByPath("Tools/Preview/", submenu, 1000, handle);
|
||||||
liveMenuItem = new ui.item({
|
liveMenuItem = new ui.item({
|
||||||
onclick: function(e) { commands.exec("preview", { newTab: e && e.button == 1 }); }
|
onclick: function(e) { commands.exec("preview", null, { newTab: e && e.button == 1 }); }
|
||||||
});
|
});
|
||||||
menus.addItemByPath("Tools/Preview/Live Preview Files",
|
menus.addItemByPath("Tools/Preview/Live Preview Files",
|
||||||
liveMenuItem, 100, handle);
|
liveMenuItem, 100, handle);
|
||||||
|
@ -111,6 +92,14 @@ define(function(require, exports, module) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}), 200, handle);
|
}), 200, handle);
|
||||||
|
menus.addItemByPath("Tools/Preview/~", new ui.divider({}), 2000, handle);
|
||||||
|
menus.addItemByPath("Tools/Preview/~", new ui.divider({}), 4000, handle);
|
||||||
|
menus.addItemByPath("Tools/Preview/Configure Preview URL...", new ui.item({
|
||||||
|
onclick: function(e) { commands.exec("openpreferences", null, {panel: "project", section: "Run & Debug"}); }
|
||||||
|
}), 4200, handle);
|
||||||
|
menus.addItemByPath("Tools/Preview/Show Active Servers...", new ui.item({
|
||||||
|
onclick: function(e) { commands.exec("showprocesslist", null, { mode: "lsof" }); }
|
||||||
|
}), 4300, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.on("read", function(e) {
|
settings.on("read", function(e) {
|
||||||
|
@ -122,18 +111,18 @@ define(function(require, exports, module) {
|
||||||
}, handle);
|
}, handle);
|
||||||
|
|
||||||
// Context menu for tree
|
// Context menu for tree
|
||||||
var itemCtxTreePreview = new ui.item({
|
|
||||||
match: "file",
|
|
||||||
caption: "Preview",
|
|
||||||
isAvailable: function() {
|
|
||||||
return tree.selectedNode && !tree.selectedNode.isFolder
|
|
||||||
&& (options.local || util.normalizePath(tree.selectedNode.path).charAt(0) != "~");
|
|
||||||
},
|
|
||||||
onclick: function() {
|
|
||||||
openPreview(tree.selected);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
tree.getElement("mnuCtxTree", function(mnuCtxTree) {
|
tree.getElement("mnuCtxTree", function(mnuCtxTree) {
|
||||||
|
var itemCtxTreePreview = new ui.item({
|
||||||
|
match: "file",
|
||||||
|
caption: "Preview",
|
||||||
|
isAvailable: function() {
|
||||||
|
return tree.selectedNode && !tree.selectedNode.isFolder
|
||||||
|
&& (options.local || util.normalizePath(tree.selectedNode.path).charAt(0) != "~");
|
||||||
|
},
|
||||||
|
onclick: function() {
|
||||||
|
openPreview(tree.selected);
|
||||||
|
}
|
||||||
|
});
|
||||||
ui.insertByIndex(mnuCtxTree, itemCtxTreePreview, 160, handle);
|
ui.insertByIndex(mnuCtxTree, itemCtxTreePreview, 160, handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -163,70 +152,30 @@ define(function(require, exports, module) {
|
||||||
var nodes = tab.pane.group;
|
var nodes = tab.pane.group;
|
||||||
if (!nodes)
|
if (!nodes)
|
||||||
pane = tab.pane.hsplit(true);
|
pane = tab.pane.hsplit(true);
|
||||||
else {
|
else
|
||||||
pane = nodes[nodes.indexOf(tab.pane) === 0 ? 1 : 0];
|
pane = nodes[nodes.indexOf(tab.pane) === 0 ? 1 : 0];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pane;
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.server) {
|
if (args.server) {
|
||||||
var hostname = c9.hostname || "localhost:8080";
|
var openInNewTab = args.newTab;
|
||||||
|
path = args.url;
|
||||||
|
|
||||||
var cb = function(err, stderr, stdout) {
|
if (!path)
|
||||||
if (err && err.code != 1)
|
path = "https://$C9_HOSTNAME";
|
||||||
showError("Could not check if server is running.");
|
|
||||||
else if (stderr || !stdout || !stdout.length) {
|
|
||||||
|
|
||||||
// Check for project run config
|
path = expandUrl(path);
|
||||||
var json = settings.getJson("project/run/configs") || {};
|
|
||||||
for (var name in json) {
|
|
||||||
if (json[name]["default"]) {
|
|
||||||
commands.exec("run", null, {
|
|
||||||
callback: function(proc) {
|
|
||||||
proc.on("started", function() {
|
|
||||||
setTimeout(done, 1000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
warnNoServer(hostname);
|
if (window.location.protocol == "https:" && !path.startsWith("https:"))
|
||||||
}
|
openInNewTab = true;
|
||||||
|
|
||||||
done();
|
if (openInNewTab)
|
||||||
};
|
return util.openNewWindow(path);
|
||||||
|
|
||||||
function done() {
|
pane = findPane();
|
||||||
var path = (options.local ? "http" : "https")
|
return openPreview(path, pane, args && args.active);
|
||||||
+ "://" + hostname;
|
|
||||||
if (args.newTab)
|
|
||||||
return util.openNewWindow(path);
|
|
||||||
|
|
||||||
// Open Pane
|
|
||||||
pane = findPane();
|
|
||||||
|
|
||||||
// Open Preview
|
|
||||||
openPreview(path, pane, args && args.active);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.nocheck)
|
|
||||||
done();
|
|
||||||
else if (options.local) {
|
|
||||||
proc.execFile("lsof", {
|
|
||||||
args: ["-i", ":8080"]
|
|
||||||
}, cb);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
proc.execFile("nc", {
|
|
||||||
args: ["-zv", hostname, "80"]
|
|
||||||
}, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (args.path) {
|
else if (args.path) {
|
||||||
path = args.path;
|
path = args.path;
|
||||||
|
@ -284,6 +233,20 @@ define(function(require, exports, module) {
|
||||||
var key = commands.getHotkey("reloadpreview");
|
var key = commands.getHotkey("reloadpreview");
|
||||||
if (commands.platform == "mac")
|
if (commands.platform == "mac")
|
||||||
key = apf.hotkeys.toMacNotation(key);
|
key = apf.hotkeys.toMacNotation(key);
|
||||||
|
|
||||||
|
prefs.add({
|
||||||
|
"Project": {
|
||||||
|
position: 100,
|
||||||
|
"Run & Debug": {
|
||||||
|
position: 300,
|
||||||
|
"Preview URL": {
|
||||||
|
type: "textbox",
|
||||||
|
path: "project/preview/@url"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, handle);
|
||||||
|
|
||||||
prefs.add({
|
prefs.add({
|
||||||
"Run": {
|
"Run": {
|
||||||
position: 600,
|
position: 600,
|
||||||
|
@ -312,7 +275,7 @@ define(function(require, exports, module) {
|
||||||
{ caption: "Only on " + key, value: "false" },
|
{ caption: "Only on " + key, value: "false" },
|
||||||
{ caption: "Always", value: "true" },
|
{ caption: "Always", value: "true" },
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, handle);
|
}, handle);
|
||||||
|
@ -357,6 +320,13 @@ define(function(require, exports, module) {
|
||||||
return pane;
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expandUrl(url) {
|
||||||
|
var hostname = c9.hostname;
|
||||||
|
if (!c9.hosted && !hostname)
|
||||||
|
hostname = window.location.hostname;
|
||||||
|
return url.replace(/\$C9_HOSTNAME\b/, hostname);
|
||||||
|
}
|
||||||
|
|
||||||
function registerPlugin(plugin, matcher) {
|
function registerPlugin(plugin, matcher) {
|
||||||
previewers[plugin.name] = {
|
previewers[plugin.name] = {
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
|
@ -409,6 +379,73 @@ define(function(require, exports, module) {
|
||||||
+ "and change the hostname in the location bar.");
|
+ "and change the hostname in the location bar.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePreviewMenu(e, submenu) {
|
||||||
|
var tab = tabs.focussedTab;
|
||||||
|
var isKnown = false;
|
||||||
|
var title = "Live Preview File";
|
||||||
|
if (tab && tab.path) {
|
||||||
|
var path = tab.path;
|
||||||
|
for (var name in previewers) {
|
||||||
|
if (previewers[name].matcher(path)) {
|
||||||
|
isKnown = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isKnown) {
|
||||||
|
title = "Raw Content of " + basename(path);
|
||||||
|
isKnown = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
title += " (" + basename(path) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
liveMenuItem.setAttribute("caption", title);
|
||||||
|
if (isKnown)
|
||||||
|
liveMenuItem.enable();
|
||||||
|
else
|
||||||
|
liveMenuItem.disable();
|
||||||
|
// user configured elements
|
||||||
|
var url = settings.get("project/preview/@url");
|
||||||
|
if (!Array.isArray(url)) url = [url];
|
||||||
|
var added = false;
|
||||||
|
var index = 0;
|
||||||
|
var children = submenu.childNodes;
|
||||||
|
while (children[index] && children[index].localName != "divider") {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
var appMenu = children[index - 1];
|
||||||
|
var firstDivider = children[index];
|
||||||
|
index++;
|
||||||
|
for (var i = 0; i < url.length; i++) {
|
||||||
|
if (typeof url[i] != "string" || !url[i]) continue;
|
||||||
|
var oldNode = children[index];
|
||||||
|
if (!oldNode || oldNode.localName != "item") {
|
||||||
|
oldNode = submenu.insertBefore(new ui.item({
|
||||||
|
onclick: openUrl
|
||||||
|
}), oldNode);
|
||||||
|
}
|
||||||
|
oldNode.value = url[i];
|
||||||
|
var caption = "Open " + expandUrl(url[i]);
|
||||||
|
oldNode.setAttribute("caption", caption);
|
||||||
|
added = true;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
while(index < children.length - 3)
|
||||||
|
submenu.removeChild(children[index]);
|
||||||
|
|
||||||
|
appMenu.setAttribute("visible", !added);
|
||||||
|
firstDivider.setAttribute("visible", added);
|
||||||
|
|
||||||
|
function openUrl(e) {
|
||||||
|
commands.exec("preview", null, {
|
||||||
|
newTab: e.button == 1,
|
||||||
|
url: e.currentTarget.value,
|
||||||
|
server: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The preview handle, responsible for managing preview plugins.
|
* The preview handle, responsible for managing preview plugins.
|
||||||
* This is the object you get when you request the preview
|
* This is the object you get when you request the preview
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
main.consumes = [
|
main.consumes = [
|
||||||
"ui", "layout", "commands", "Dialog", "proc", "util", "menus"
|
"ui", "layout", "commands", "Dialog", "proc", "util", "menus", "dialog.error"
|
||||||
];
|
];
|
||||||
main.provides = ["processlist"];
|
main.provides = ["processlist"];
|
||||||
return main;
|
return main;
|
||||||
|
@ -15,6 +15,7 @@ define(function(require, exports, module) {
|
||||||
var proc = imports.proc;
|
var proc = imports.proc;
|
||||||
var util = imports.util;
|
var util = imports.util;
|
||||||
var menus = imports.menus;
|
var menus = imports.menus;
|
||||||
|
var showError = imports["dialog.error"].show;
|
||||||
|
|
||||||
var search = require("../c9.ide.navigate/search");
|
var search = require("../c9.ide.navigate/search");
|
||||||
var Tree = require("ace_tree/tree");
|
var Tree = require("ace_tree/tree");
|
||||||
|
@ -47,6 +48,8 @@ define(function(require, exports, module) {
|
||||||
var INTERVAL = 5000;
|
var INTERVAL = 5000;
|
||||||
var model, datagrid, btnKill, btnForceKill, tbFilter, timer;
|
var model, datagrid, btnKill, btnForceKill, tbFilter, timer;
|
||||||
|
|
||||||
|
var mode = "ps";
|
||||||
|
|
||||||
var loaded = false;
|
var loaded = false;
|
||||||
function load() {
|
function load() {
|
||||||
if (loaded) return false;
|
if (loaded) return false;
|
||||||
|
@ -55,8 +58,8 @@ define(function(require, exports, module) {
|
||||||
commands.addCommand({
|
commands.addCommand({
|
||||||
name: "showprocesslist",
|
name: "showprocesslist",
|
||||||
bindKey: { mac: "Command-Option-P", win: "Ctrl-Alt-P" },
|
bindKey: { mac: "Command-Option-P", win: "Ctrl-Alt-P" },
|
||||||
exec: function() {
|
exec: function(editor, args) {
|
||||||
plugin.show();
|
plugin.show(args.mode || "ps");
|
||||||
}
|
}
|
||||||
}, plugin);
|
}, plugin);
|
||||||
|
|
||||||
|
@ -82,10 +85,11 @@ define(function(require, exports, module) {
|
||||||
model.$sortNodes = true;
|
model.$sortNodes = true;
|
||||||
|
|
||||||
model.$sorted = true;
|
model.$sorted = true;
|
||||||
model.columns = [{
|
model.columnsPs = [{
|
||||||
caption: "Process Name",
|
caption: "Process Name",
|
||||||
value: "name",
|
value: "name",
|
||||||
width: "100%"
|
width: "100%",
|
||||||
|
type: "tree",
|
||||||
}, {
|
}, {
|
||||||
caption: "CPU",
|
caption: "CPU",
|
||||||
// value: "cpu",
|
// value: "cpu",
|
||||||
|
@ -99,7 +103,7 @@ define(function(require, exports, module) {
|
||||||
}, {
|
}, {
|
||||||
caption: "Process Time",
|
caption: "Process Time",
|
||||||
value: "ptime",
|
value: "ptime",
|
||||||
width: "100",
|
width: "50",
|
||||||
}, {
|
}, {
|
||||||
caption: "PID",
|
caption: "PID",
|
||||||
value: "pid",
|
value: "pid",
|
||||||
|
@ -110,6 +114,30 @@ define(function(require, exports, module) {
|
||||||
width: "80",
|
width: "80",
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
model.columnsLsof = [{
|
||||||
|
caption: "Address",
|
||||||
|
value: "address",
|
||||||
|
width: "100%",
|
||||||
|
}, {
|
||||||
|
caption: "Process Name",
|
||||||
|
value: "command",
|
||||||
|
width: "80",
|
||||||
|
}, {
|
||||||
|
caption: "Status",
|
||||||
|
value: "status",
|
||||||
|
width: "50",
|
||||||
|
}, {
|
||||||
|
caption: "PID",
|
||||||
|
value: "pid",
|
||||||
|
width: "50",
|
||||||
|
}, {
|
||||||
|
caption: "Type",
|
||||||
|
value: "type",
|
||||||
|
width: "50",
|
||||||
|
}];
|
||||||
|
|
||||||
|
model.columns = model.columnsPs;
|
||||||
|
|
||||||
var datagridDiv = pNode.appendChild(document.createElement("div"));
|
var datagridDiv = pNode.appendChild(document.createElement("div"));
|
||||||
datagrid = new Tree(datagridDiv);
|
datagrid = new Tree(datagridDiv);
|
||||||
datagrid.renderer.setTheme({ cssClass: "blackdg" });
|
datagrid.renderer.setTheme({ cssClass: "blackdg" });
|
||||||
|
@ -148,50 +176,112 @@ define(function(require, exports, module) {
|
||||||
applyFilter();
|
applyFilter();
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProcessList();
|
update();
|
||||||
|
|
||||||
emit("draw");
|
emit("draw");
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Methods *****/
|
/***** Methods *****/
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
if (mode == "ps")
|
||||||
|
updateProcessList();
|
||||||
|
else
|
||||||
|
updateServerList();
|
||||||
|
}
|
||||||
|
|
||||||
function updateProcessList() {
|
function updateProcessList() {
|
||||||
var sel = datagrid.selection.getSelectedNodes();
|
setModel(null, model.columnsPs);
|
||||||
|
proc.execFile("ps", { args: ["axh", "-ouser,pid:1,ppid:1,pcpu:1,pmem:1,time:1,command:1"] }, function(err, stdout, stderr) {
|
||||||
proc.execFile("ps", { args: ["auxc"]}, function(err, stdout, stderr) {
|
|
||||||
if (err) return;
|
if (err) return;
|
||||||
|
var hiddenRegex = /^\[kthreadd|/
|
||||||
|
|
||||||
var lines = stdout.substr(0, stdout.length - 1).split("\n"); lines.shift();
|
var oldNodes = model.pidMap;
|
||||||
|
if (!oldNodes || oldNodes.mode != mode)
|
||||||
|
oldNodes = { mode: mode };
|
||||||
|
var pidMap = model.pidMap = { mode: mode };
|
||||||
|
|
||||||
|
var lines = stdout.substr(0, stdout.length - 1).split("\n");
|
||||||
var json = lines.map(function(line) {
|
var json = lines.map(function(line) {
|
||||||
var item = line.split(/\s+/);
|
var item = line.split(/\s+/);
|
||||||
var name = item.splice(10).join(" ");
|
var name = item.slice(6).join(" ");
|
||||||
return {
|
var pid = item[1];
|
||||||
name: name,
|
var node = oldNodes[pid] || { pid: pid, isOpen: hiddenRegex.test(name) };
|
||||||
cpu: item[2],
|
pidMap[pid] = node;
|
||||||
mem: item[3],
|
|
||||||
ptime: item[9],
|
node.cpu = item[3];
|
||||||
pid: item[1],
|
node.mem = item[4];
|
||||||
user: item[0]
|
node.ppid = item[2];
|
||||||
};
|
node.name = name;
|
||||||
|
node.user = item[0];
|
||||||
|
node.ptime = item[5];
|
||||||
|
|
||||||
|
node.items = node.children = null;
|
||||||
|
|
||||||
|
return node;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var root = [];
|
||||||
|
json.forEach(function(node) {
|
||||||
|
var parent = pidMap[node.ppid];
|
||||||
|
if (!parent) return root.push(node);
|
||||||
|
if (!parent.items) parent.items = [];
|
||||||
|
parent.items.push(node);
|
||||||
|
});
|
||||||
|
json = root;
|
||||||
|
|
||||||
|
setModel(json, model.columnsPs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateServerList() {
|
||||||
|
setModel(null, model.columnsLsof);
|
||||||
|
proc.execFile("bash", { args: ["-c",
|
||||||
|
"sudo -n lsof -P -i -F pcnTtu || lsof -P -i -F pcnTtu"
|
||||||
|
]}, function(err, stdout, stderr) {
|
||||||
|
if (err) return;
|
||||||
|
var json = [];
|
||||||
|
var node;
|
||||||
|
var oldNodes = model.pidMap;
|
||||||
|
if (!oldNodes || oldNodes.mode != mode)
|
||||||
|
oldNodes = { mode: mode };
|
||||||
|
model.pidMap = { mode: mode };
|
||||||
|
stdout.split("\n").forEach(function(part) {
|
||||||
|
if (part[0] == "p") {
|
||||||
|
if (node) json.push(node);
|
||||||
|
var pid = part.slice(1);
|
||||||
|
node = oldNodes[pid] || { pid: pid };
|
||||||
|
model.pidMap[pid] = node;
|
||||||
|
}
|
||||||
|
if (part[0] == "c")
|
||||||
|
node.command = part.slice(1);
|
||||||
|
if (part[0] == "n")
|
||||||
|
node.address = part.slice(1);
|
||||||
|
if (part[0] == "T" && /^TST=/.test(part))
|
||||||
|
node.status = part.slice(4);
|
||||||
|
if (part[0] == "t")
|
||||||
|
node.type = part.slice(1);
|
||||||
|
if (part[0] == "u")
|
||||||
|
node.uid = parseInt(part.slice(1), 10);
|
||||||
|
});
|
||||||
|
if (node) json.push(node);
|
||||||
|
|
||||||
|
setModel(json, model.columnsLsof);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setModel(json, columns) {
|
||||||
|
if (model.columns != columns) {
|
||||||
|
model.columns = columns;
|
||||||
|
datagrid.setDataProvider(model);
|
||||||
|
if (!json) json = [];
|
||||||
|
}
|
||||||
|
if (json) {
|
||||||
model.cachedRoot = json;
|
model.cachedRoot = json;
|
||||||
model.setRoot(json);
|
model.setRoot(json);
|
||||||
|
}
|
||||||
if (model.keyword)
|
if (model.keyword)
|
||||||
applyFilter();
|
applyFilter();
|
||||||
|
|
||||||
if (sel) {
|
|
||||||
var nodes = [];
|
|
||||||
var pids = sel.map(function(n) { return n.pid; });
|
|
||||||
|
|
||||||
model.root.items.forEach(function(item) {
|
|
||||||
if (pids.indexOf(item.pid) > -1)
|
|
||||||
nodes.push(item);
|
|
||||||
});
|
|
||||||
datagrid.selection.setSelection(nodes);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function forceKill() {
|
function forceKill() {
|
||||||
|
@ -201,22 +291,21 @@ define(function(require, exports, module) {
|
||||||
function kill(force) {
|
function kill(force) {
|
||||||
var nodes = datagrid.selection.getSelectedNodes();
|
var nodes = datagrid.selection.getSelectedNodes();
|
||||||
if (!nodes.length) return;
|
if (!nodes.length) return;
|
||||||
|
|
||||||
var button = force ? btnForceKill : btnKill;
|
var button = force ? btnForceKill : btnKill;
|
||||||
|
|
||||||
async.each(nodes, function(row, next) {
|
async.each(nodes, function(row, next) {
|
||||||
|
if (!/^\d+$/.test(row.pid)) return next();
|
||||||
button.disable();
|
button.disable();
|
||||||
|
var args = (force ? "" : "-9 ") + row.pid;
|
||||||
var args = [];
|
proc.execFile("bash", {
|
||||||
if (force) args.push("-9");
|
args: ["-c", "sudo -n kill " + args + " || kill " + args]
|
||||||
args.push(row.pid);
|
}, function(err, stdout, stderr) {
|
||||||
|
|
||||||
proc.execFile("kill", { args: args }, function(err, stdout, stderr) {
|
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
button.enable();
|
button.enable();
|
||||||
if (!err) updateProcessList();
|
if (err) return showError(err);
|
||||||
|
update();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -235,29 +324,33 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(reset, options) {
|
function show(mode, options) {
|
||||||
if (!options)
|
if (!options)
|
||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
|
setMode(mode);
|
||||||
return plugin.queue(function() {
|
return plugin.queue(function() {
|
||||||
// if (reset || current == -1) {
|
|
||||||
// path = [startPage];
|
|
||||||
// current = 0;
|
|
||||||
// activate(startPage);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMode(val) {
|
||||||
|
if ((val == "ps" || val == "lsof") && mode != val) {
|
||||||
|
mode = val;
|
||||||
|
if (timer) update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***** Lifecycle *****/
|
/***** Lifecycle *****/
|
||||||
|
|
||||||
plugin.on("show", function() {
|
plugin.on("show", function() {
|
||||||
timer = setInterval(function() {
|
timer = setInterval(function() {
|
||||||
updateProcessList();
|
update();
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
|
update();
|
||||||
});
|
});
|
||||||
plugin.on("hide", function() {
|
plugin.on("hide", function() {
|
||||||
clearInterval(timer);
|
timer = clearInterval(timer);
|
||||||
});
|
});
|
||||||
plugin.on("draw", function(options) {
|
plugin.on("draw", function(options) {
|
||||||
draw(options);
|
draw(options);
|
||||||
|
|
Ładowanie…
Reference in New Issue