mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-19 17:53:28 +00:00
1. Updated getProcess/getProcessEx to return an array
2. Updated setDesktopWallpaper, to check uid of gnome-session
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -51,8 +51,19 @@ function gnome_getDesktopWallpaper(uid)
|
|||||||
function gnome_setDesktopWallpaper(uid, filePath)
|
function gnome_setDesktopWallpaper(uid, filePath)
|
||||||
{
|
{
|
||||||
if (!filePath) { filePath = '/dev/null'; }
|
if (!filePath) { filePath = '/dev/null'; }
|
||||||
var v = { HOME: require('user-sessions').getHomeFolder(uid), DBUS_SESSION_BUS_ADDRESS: require('user-sessions').getEnvFromPid(require('process-manager').getProcess('gnome-session')).DBUS_SESSION_BUS_ADDRESS };
|
|
||||||
|
|
||||||
|
var v = { HOME: require('user-sessions').getHomeFolder(uid) };
|
||||||
|
var pids = require('process-manager').getProcess('gnome-session');
|
||||||
|
for (var i in pids)
|
||||||
|
{
|
||||||
|
var e = require('user-sessions').getEnvFromPid(pids[i]);
|
||||||
|
if (e.USER && require('user-sessions').getUid(e.USER)!=uid)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
v.DBUS_SESSION_BUS_ADDRESS = e.DBUS_SESSION_BUS_ADDRESS;
|
||||||
|
if (v.DBUS_SESSION_BUS_ADDRESS) { break; }
|
||||||
|
}
|
||||||
|
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: v });
|
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: v });
|
||||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
|||||||
@@ -206,14 +206,16 @@ function processManager() {
|
|||||||
{
|
{
|
||||||
this.getProcess = function getProcess(cmd)
|
this.getProcess = function getProcess(cmd)
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile(this._pgrep, ['pgrep', cmd]);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("pgrep gnome-session | tr '\\n' '\\t' |" + ' awk -F"\\t" \'{ printf "["; for(i=1;i<NF;++i) { if(i>1) { printf ","; } printf "%d", $i; } printf "]"; }\'');
|
||||||
|
child.stdin.write('\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
|
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
|
||||||
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
|
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
|
||||||
|
|
||||||
return (parseInt(child.stdout.str.trim()));
|
return (JSON.parse(child.stdout.str.trim()));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +226,7 @@ function processManager() {
|
|||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ for(i=1;i<NF;++i) { split($i,r," "); if(r[2]!="grep") { print r[1]; break; } } }\'');
|
child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ printf "["; for(i=1;i<NF;++i) { split($i,r," "); if(r[2]!="grep") { if(i>1) { printf ","; } printf "%s", r[1]; } } printf "]"; }\'');
|
||||||
child.stdin.write('\nexit\n');
|
child.stdin.write('\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
|
|
||||||
@@ -234,7 +236,7 @@ function processManager() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (parseInt(child.stdout.str.trim()));
|
return (JSON.parse(child.stdout.str.trim()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user