1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-18 01:03:14 +00:00

1. Added ability to search env vars by uid

2. updated toaster to work with KDE
This commit is contained in:
Bryan Roe
2019-05-17 22:10:52 -07:00
parent bbe2098b7e
commit 020bae80a5
3 changed files with 88 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@@ -76,37 +76,69 @@ function Toaster()
} }
else else
{ {
if(!require('fs').existsSync('/usr/bin/notify-send')) var child = require('child_process').execFile('/bin/sh', ['sh']);
{ child.stdout.str = '';
throw ('Toast not supported on this platform'); child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
} child.stdin.write("whereis notify-send | awk '{ print $2 }'\nexit\n");
if (process.env['DISPLAY']) child.waitExit();
{ if (child.stdout.str.trim() == '') {
// DISPLAY is set, so we good to go // notify-send doesn't exist, lets check kdialog
retVal._notify = require('child_process').execFile('/usr/bin/notify-send', ['notify-send', retVal.title, retVal.caption]); 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 kdialog | awk '{ print $2 }'\nexit\n");
child.waitExit();
if (child.stdout.str.trim() == '') { throw ('Toast not supported on this platform'); }
// Let's use kdialog
if (process.env['DISPLAY'])
{
retVal._notify = require('child_process').execFile(child.stdout.str.trim(), ['kdialog', '--title', retVal.title, '--passivepopup', retVal.caption, '5']);
}
else
{
var consoleUid = require('user-sessions').consoleUid();
var xinfo = require('monitor-info').getXInfo(consoleUid);
var xdg = require('user-sessions').findEnv(consoleUid, 'XDG_RUNTIME_DIR');
if (!xinfo || !xinfo.display || !xinfo.xauthority || !xdg)
{
throw ('Internal Error');
}
retVal._notify = require('child_process').execFile(child.stdout.str.trim(), ['kdialog', '--title', retVal.title, '--passivepopup', retVal.caption, '5'], { uid: consoleUid, env: { DISPLAY: xinfo.display, XAUTHORITY: xinfo.xauthority, XDG_RUNTIME_DIR: xdg } });
}
retVal._notify.stdout.on('data', function (chunk) { });
retVal._notify.stderr.on('data', function (chunk) { });
retVal._notify.waitExit();
} }
else else
{ {
// We need to find the DISPLAY to use // Let's use notify-send
var consoleUid = require('user-sessions').consoleUid();
var username = require('user-sessions').getUsername(consoleUid); if (process.env['DISPLAY'])
var display = require('monitor-info').getXInfo(consoleUid).display; {
retVal._notify = require('child_process').execFile('/bin/sh', ['sh']); // DISPLAY is set, so we good to go
retVal._notify.stdin.write('su - ' + username + ' -c "DISPLAY=' + display + ' notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\n'); retVal._notify = require('child_process').execFile(child.stdout.str.trim(), ['notify-send', retVal.title, retVal.caption]);
retVal._notify.stdin.write('exit\n'); }
else
{
// We need to find the DISPLAY to use
var consoleUid = require('user-sessions').consoleUid();
var username = require('user-sessions').getUsername(consoleUid);
var display = require('monitor-info').getXInfo(consoleUid).display;
retVal._notify = require('child_process').execFile('/bin/sh', ['sh']);
retVal._notify.stdin.write('su - ' + username + ' -c "DISPLAY=' + display + ' notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\n');
retVal._notify.stdin.write('exit\n');
}
retVal._notify.stdout.on('data', function (chunk) { });
retVal._notify.waitExit();
// NOTIFY-SEND has a bug where timeouts don't work, so the default is 10 seconds
retVal._timeout = setTimeout(function onFakeDismissed(obj) {
obj.emit('Dismissed');
}, 10000, retVal);
toasters[retVal._hashCode()] = retVal;
retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; });
} }
retVal._notify.stdout.on('data', function (chunk) { });
retVal._notify.waitExit();
// NOTIFY-SEND has a bug where timeouts don't work, so the default is 10 seconds
retVal._timeout = setTimeout(function onFakeDismissed(obj)
{
obj.emit('Dismissed');
}, 10000, retVal);
toasters[retVal._hashCode()] = retVal;
retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; });
return (retVal); return (retVal);
} }
}; };

View File

@@ -620,7 +620,30 @@ function UserSessions()
} }
return (ret); return (ret);
}; };
this.findEnv = function findEnv(uid, env)
{
var uname = this.getUsername(uid);
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("ps -e -o pid -o user | grep " + uname + " | awk '{ print $1 }'\nexit\n");
child.waitExit();
var lines = child.stdout.str.split('\n');
for (var n in lines)
{
var ln = lines[n].trim();
if (ln.length > 0)
{
var e = this.getEnvFromPid(ln);
if (e[env])
{
return (e[env]);
}
}
}
return (null);
};
this.on('changed', this._recheckLoggedInUsers); // For linux Lock/Unlock monitoring, we need to watch for LogOn/LogOff, and keep track of the UID. this.on('changed', this._recheckLoggedInUsers); // For linux Lock/Unlock monitoring, we need to watch for LogOn/LogOff, and keep track of the UID.