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:
File diff suppressed because one or more lines are too long
@@ -76,14 +76,47 @@ function Toaster()
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!require('fs').existsSync('/usr/bin/notify-send'))
|
||||
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 notify-send | awk '{ print $2 }'\nexit\n");
|
||||
child.waitExit();
|
||||
if (child.stdout.str.trim() == '') {
|
||||
// notify-send doesn't exist, lets check kdialog
|
||||
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'])
|
||||
{
|
||||
throw ('Toast not supported on this platform');
|
||||
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
|
||||
{
|
||||
// Let's use notify-send
|
||||
|
||||
if (process.env['DISPLAY'])
|
||||
{
|
||||
// DISPLAY is set, so we good to go
|
||||
retVal._notify = require('child_process').execFile('/usr/bin/notify-send', ['notify-send', retVal.title, retVal.caption]);
|
||||
retVal._notify = require('child_process').execFile(child.stdout.str.trim(), ['notify-send', retVal.title, retVal.caption]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -99,14 +132,13 @@ function Toaster()
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -620,7 +620,30 @@ function UserSessions()
|
||||
}
|
||||
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.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user