1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-16 08:13:30 +00:00

1. Added work-around for Zenity timeout support detection for platforms that require DISPLAY to be set in env just to query metadata

2. Fixed bug where timeout work-around resulted in success instead of timeout
This commit is contained in:
Bryan Roe
2020-04-28 03:03:18 -07:00
parent 7b339e08e0
commit dbbc47e751
2 changed files with 60 additions and 23 deletions

File diff suppressed because one or more lines are too long

View File

@@ -155,26 +155,62 @@ function linux_messageBox()
if (location == '' && require('fs').existsSync('/usr/local/bin/zenity')) { location = '/usr/local/bin/zenity'; } if (location == '' && require('fs').existsSync('/usr/local/bin/zenity')) { location = '/usr/local/bin/zenity'; }
if (location == '') { return (null); } if (location == '') { return (null); }
child = require('child_process').execFile('/bin/sh', ['sh']); var ret = { path: location, timeout: child.stdout.str.trim() == '' ? false : true };
Object.defineProperty(ret, "timeout", {
get: function ()
{
var uid, xinfo;
try
{
uid = require('user-sessions').consoleUid();
xinfo = require('monitor-info').getXInfo(uid);
}
catch (e)
{
uid = 0;
xinfo = require('monitor-info').getXInfo(0);
}
if (xinfo == null) { return (false); }
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: { XAUTHORITY: xinfo.xauthority ? xinfo.xauthority : "", DISPLAY: xinfo.display } });
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); }); child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write(location + ' --help-all | grep timeout\nexit\n'); child.stdin.write(location + ' --help-all | grep timeout\nexit\n');
child.stderr.on('data', function (e) { console.log(e); });
child.waitExit(); child.waitExit();
return (child.stdout.str.trim() == '' ? false : true);
}
});
var ret = { path: location, timeout: child.stdout.str.trim() == '' ? false : true }; Object.defineProperty(ret, "version", {
get: function ()
{
var uid, xinfo;
try
{
uid = require('user-sessions').consoleUid();
xinfo = require('monitor-info').getXInfo(uid);
}
catch (e)
{
uid = 0;
xinfo = require('monitor-info').getXInfo(0);
}
if (xinfo == null) { return (false); }
child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: { XAUTHORITY: xinfo.xauthority ? xinfo.xauthority : "", DISPLAY: xinfo.display } });
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); }); child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write(location + ' --version | awk -F. \'{ printf "[%s, %s]\\n", $1, $2; } \'\nexit\n'); child.stdin.write(location + ' --version | awk -F. \'{ printf "[%s, %s]\\n", $1, $2; } \'\nexit\n');
child.waitExit(); child.waitExit();
try try
{ {
ret.version = JSON.parse(child.stdout.str.trim()); return (JSON.parse(child.stdout.str.trim()));
} }
catch (e) catch (e)
{ {
ret.version = [2, 16]; return ([2, 16]);
} }
}
});
return (ret); return (ret);
})() })()
}); });
@@ -254,6 +290,7 @@ function linux_messageBox()
ret.child = require('child_process').execFile(this.zenity.path, ['zenity', layout == null ? '--question' : '--warning', '--title=' + title, '--text=' + caption], { uid: uid, env: { XAUTHORITY: xinfo.xauthority ? xinfo.xauthority : "", DISPLAY: xinfo.display } }); ret.child = require('child_process').execFile(this.zenity.path, ['zenity', layout == null ? '--question' : '--warning', '--title=' + title, '--text=' + caption], { uid: uid, env: { XAUTHORITY: xinfo.xauthority ? xinfo.xauthority : "", DISPLAY: xinfo.display } });
ret.child.timeout = setTimeout(function (c) ret.child.timeout = setTimeout(function (c)
{ {
c.promise._rej('timeout');
c.timeout = null; c.timeout = null;
c.kill(); c.kill();
}, timeout * 1000, ret.child); }, timeout * 1000, ret.child);