All files / root/gpii/node_modules/processReporter processesBridge.js

100% Statements 14/14
50% Branches 1/2
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                2x     2x 2x 2x   2x   2x         2x                                     2x 19x     19x 97x 97x         97x   19x    
/*!
GPII Process Reporter processes bridge -- gpii.processes.
 
Copyright 2016-2017 Inclusive Design Research Centre, OCAD University
 
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
 
You may obtain a copy of the License at
https://github.com/gpii/universal/LICENSE.txt
*/
 
/*global require */
 
"use strict";
 
var path = require("path"),
    // This conditional require is to run the electron version of edge.js
    // when this code runs on electron (gpii-app).
    edge = process.versions.electron ? require("electron-edge") : require("edge"),
    stringArgv = require("string-argv"),
    fluid = require("universal");
 
var gpii = fluid.registerNamespace("gpii");
 
var dotNetProcesses = edge.func({
    source: path.join(__dirname, "dotNetProcesses.csx"),
    references: ["System.Management.dll"]
});
 
fluid.defaults("gpii.processes.windows", {
    gradeNames: ["gpii.processes"],
    invokers: {
        getProcessList: {
            funcName: "gpii.processes.windows.getProcessList",
            args: ["{arguments}.0"]
                   // process name or id, optional.
        }
    }
});
 
/**
 * Return a list of processes -- a snapshot of the current processes.  If the
 * process name or process id is passed, then the return value will be limited
 * to only processes with that name or the process with that pid.
 *
 * @param {String} or {Number} Optional.  Specify a process to find via a name
 *                                        (string), or a process id (number).
 */
gpii.processes.windows.getProcessList = function (processIdentifier) {
    var procInfos = dotNetProcesses(processIdentifier, true);
 
    // Loop to convert the command line to an argv[].
    fluid.each(procInfos, function (aProcInfo) {
        aProcInfo.argv = stringArgv(aProcInfo.commandLine);
        delete aProcInfo.commandLine;
 
        // In some cases the first argument is just the command, e.g., "Notepad".
        // In others, it is the full path and may include the ".exe"
        // extension.  Normalize it to always be the full path.
        aProcInfo.argv[0] = aProcInfo.fullPath;
    });
    return procInfos;
};