mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-18 01:03:14 +00:00
1. Fixed timeout for KDE dialogs
2. Updated to support timeout on older zenity platforms
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -129,11 +129,45 @@ function messageBox()
|
|||||||
function linux_messageBox()
|
function linux_messageBox()
|
||||||
{
|
{
|
||||||
this._ObjectID = 'message-box';
|
this._ObjectID = 'message-box';
|
||||||
|
Object.defineProperty(this, 'zenity',
|
||||||
|
{
|
||||||
|
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 zenity | awk '{ print $2 }'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
var location = child.stdout.str.trim();
|
||||||
|
if (location == '' && require('fs').existsSync('/usr/local/bin/zenity')) { location = '/usr/local/bin/zenity'; }
|
||||||
|
if (location == '') { return (null); }
|
||||||
|
|
||||||
|
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
|
child.stdin.write(location + ' --help-all | grep timeout\nexit\n');
|
||||||
|
child.waitExit();
|
||||||
|
|
||||||
|
return ({ path: location, timeout: child.stdout.str.trim() == '' ? false : true });
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
if (!this.zenity)
|
||||||
|
{
|
||||||
|
Object.defineProperty(this, 'kdialog',
|
||||||
|
{
|
||||||
|
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 kdialog | awk '{ print $2 }'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
return (child.stdout.str.trim() == '' ? null : { path: child.stdout.str.trim() });
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.create = function create(title, caption, timeout)
|
this.create = function create(title, caption, timeout)
|
||||||
{
|
{
|
||||||
if (timeout == null) { timeout = 10; }
|
if (timeout == null) { timeout = 10; }
|
||||||
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||||
var zenity = '', kdialog = '';
|
|
||||||
var uid;
|
var uid;
|
||||||
var xinfo;
|
var xinfo;
|
||||||
|
|
||||||
@@ -154,22 +188,28 @@ function linux_messageBox()
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
if (this.zenity)
|
||||||
child.stdout.str = '';
|
|
||||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
|
||||||
child.stdin.write("whereis zenity | awk '{ print $2 }'\nexit\n");
|
|
||||||
child.waitExit();
|
|
||||||
zenity = child.stdout.str.trim();
|
|
||||||
if (process.platform == 'freebsd' && zenity == '' && require('fs').existsSync('/usr/local/bin/zenity')) { zenity = '/usr/local/bin/zenity'; }
|
|
||||||
if (zenity != '')
|
|
||||||
{
|
{
|
||||||
// GNOME/ZENITY
|
// GNOME/ZENITY
|
||||||
ret.child = require('child_process').execFile(zenity, ['zenity', '--question', '--title=' + title, '--text=' + caption, '--timeout=' + timeout], { uid: uid, env: { XAUTHORITY: xinfo.xauthority, DISPLAY: xinfo.display } });
|
if (this.zenity.timeout)
|
||||||
|
{
|
||||||
|
ret.child = require('child_process').execFile(this.zenity.path, ['zenity', '--question', '--title=' + title, '--text=' + caption, '--timeout=' + timeout], { uid: uid, env: { XAUTHORITY: xinfo.xauthority, DISPLAY: xinfo.display } });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret.child = require('child_process').execFile(this.zenity.path, ['zenity', '--question', '--title=' + title, '--text=' + caption], { uid: uid, env: { XAUTHORITY: xinfo.xauthority, DISPLAY: xinfo.display } });
|
||||||
|
ret.child.timeout = setTimeout(function (c)
|
||||||
|
{
|
||||||
|
c.timeout = null;
|
||||||
|
c.kill();
|
||||||
|
}, timeout * 1000, ret.child);
|
||||||
|
}
|
||||||
ret.child.promise = ret;
|
ret.child.promise = ret;
|
||||||
ret.child.stderr.on('data', function (chunk) { });
|
ret.child.stderr.on('data', function (chunk) { });
|
||||||
ret.child.stdout.on('data', function (chunk) { });
|
ret.child.stdout.on('data', function (chunk) { });
|
||||||
ret.child.on('exit', function (code)
|
ret.child.on('exit', function (code)
|
||||||
{
|
{
|
||||||
|
if (this.timeout) { clearTimeout(this.timeout); }
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -184,42 +224,48 @@ function linux_messageBox()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else if(this.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();
|
|
||||||
kdialog = child.stdout.str.trim();
|
|
||||||
if (process.platform == 'freebsd' && kdialog == '' && require('fs').existsSync('/usr/local/bin/kdialog')) { kdialog = '/usr/local/bin/kdialog'; }
|
|
||||||
if (kdialog == '') { ret._rej('Platform not supported (zenity or kdialog not found)'); return (ret); }
|
|
||||||
if (process.platform != 'freebsd' && process.env['DISPLAY'])
|
if (process.platform != 'freebsd' && process.env['DISPLAY'])
|
||||||
{
|
{
|
||||||
ret.child = require('child_process').execFile(kdialog, ['kdialog', '--title', title, '--yesno', caption]);
|
ret.child = require('child_process').execFile(this.kdialog.path, ['kdialog', '--title', title, '--yesno', caption]);
|
||||||
ret.child.promise = ret;
|
ret.child.promise = ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var xdg = require('user-sessions').findEnv(uid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
var xdg = require('user-sessions').findEnv(uid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||||
if (!xinfo || !xinfo.display || !xinfo.xauthority) { ret._rej('Interal Error, could not determine X11/XDG env'); return (ret); }
|
if (!xinfo || !xinfo.display || !xinfo.xauthority) { ret._rej('Interal Error, could not determine X11/XDG env'); return (ret); }
|
||||||
ret.child = require('child_process').execFile(kdialog, ['kdialog', '--title', title, '--yesno', caption], { uid: uid, env: { DISPLAY: xinfo.display, XAUTHORITY: xinfo.xauthority, XDG_RUNTIME_DIR: xdg } });
|
ret.child = require('child_process').execFile(this.kdialog.path, ['kdialog', '--title', title, '--yesno', caption], { uid: uid, env: { DISPLAY: xinfo.display, XAUTHORITY: xinfo.xauthority, XDG_RUNTIME_DIR: xdg } });
|
||||||
ret.child.promise = ret;
|
ret.child.promise = ret;
|
||||||
}
|
}
|
||||||
|
ret.child.timeout = setTimeout(function (c)
|
||||||
|
{
|
||||||
|
c.timeout = null;
|
||||||
|
c.kill();
|
||||||
|
}, timeout * 1000, ret.child);
|
||||||
ret.child.stdout.on('data', function (chunk) { });
|
ret.child.stdout.on('data', function (chunk) { });
|
||||||
ret.child.stderr.on('data', function (chunk) { });
|
ret.child.stderr.on('data', function (chunk) { });
|
||||||
ret.child.on('exit', function (code)
|
ret.child.on('exit', function (code)
|
||||||
{
|
{
|
||||||
switch (code) {
|
if (this.timeout)
|
||||||
case 0:
|
{
|
||||||
this.promise._res();
|
clearTimeout(this.timeout);
|
||||||
break;
|
switch (code)
|
||||||
case 1:
|
{
|
||||||
this.promise._rej('denied');
|
case 0:
|
||||||
break;
|
this.promise._res();
|
||||||
default:
|
break;
|
||||||
this.promise._rej('timeout');
|
case 1:
|
||||||
break;
|
this.promise._rej('denied');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.promise._rej('timeout');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.promise._rej('timeout');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user