mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-13 14:53:46 +00:00
1. Added 'getProcess' to process-manager for posix platforms with pgrep
2. Fixed parsing bug in user-sessions.getEnvFromPid 3. Updated linux-gnome-helpers to set environment and uid before calling gsettings
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -51,8 +51,11 @@ 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 child = require('child_process').execFile('/bin/sh', ['sh'], { env: { HOME: require('user-sessions').getHomeFolder(uid) } });
|
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 };
|
||||||
child.stderr.str = ''; child.stderr.on('data', function (c) { });
|
|
||||||
|
|
||||||
|
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.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.stdin.write('gsettings set org.gnome.desktop.background picture-uri file://' + filePath + '\nexit\n');
|
child.stdin.write('gsettings set org.gnome.desktop.background picture-uri file://' + filePath + '\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
|
|||||||
@@ -189,6 +189,33 @@ function processManager() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(this, '_pgrep', {
|
||||||
|
value: (function ()
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = '';
|
||||||
|
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
|
child.stdin.write("whereis pgrep | awk '{ print $2 }'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
return (child.stdout.str.trim());
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
|
||||||
|
if(this._pgrep != '')
|
||||||
|
{
|
||||||
|
this.getProcess = function getProcess(cmd)
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile(this._pgrep, ['pgrep', cmd]);
|
||||||
|
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.waitExit();
|
||||||
|
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
|
||||||
|
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
|
||||||
|
|
||||||
|
return (parseInt(child.stdout.str.trim()));
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new processManager();
|
module.exports = new processManager();
|
||||||
|
|||||||
@@ -719,24 +719,21 @@ function UserSessions()
|
|||||||
var ret = {};
|
var ret = {};
|
||||||
if (process.platform == 'linux')
|
if (process.platform == 'linux')
|
||||||
{
|
{
|
||||||
var ps, psx, v, vs = 0;
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
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.stdin.write("cat /proc/" + pid + "/environ | tr '\\0' '\\t' |" + ' awk -F"\t" \'{ printf "{"; for(i=1;i<NF;++i) { if(i>1) {printf ",";} x=split($i, tok, "="); printf "\\"%s\\": \\"%s\\"", tok[1], substr($i, 2+length(tok[1])); } printf "}"; }\'');
|
||||||
|
child.stdin.write('\nexit\n');
|
||||||
|
child.waitExit();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ps = require('fs').readFileSync('/proc/' + pid + '/environ');
|
return (JSON.parse(child.stdout.str.trim()));
|
||||||
}
|
}
|
||||||
catch (pse)
|
catch(ee)
|
||||||
{
|
{
|
||||||
return (ret);
|
return ({});
|
||||||
}
|
|
||||||
|
|
||||||
for (psx = 0; psx < ps.length; ++psx)
|
|
||||||
{
|
|
||||||
if (ps[psx] == 0)
|
|
||||||
{
|
|
||||||
v = ps.slice(vs, psx).toString().split('=');
|
|
||||||
ret[v[0]] = v[1];
|
|
||||||
vs = psx + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (process.platform == 'freebsd')
|
else if (process.platform == 'freebsd')
|
||||||
|
|||||||
Reference in New Issue
Block a user