1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +00:00

Updated zenity logic for notifications, because the version in the Deepin repo is broken

This commit is contained in:
Bryan Roe
2020-06-10 22:47:35 -07:00
parent 8d71d9a634
commit f0a1744338
3 changed files with 101 additions and 62 deletions

File diff suppressed because one or more lines are too long

View File

@@ -184,55 +184,74 @@ function linux_messageBox()
Object.defineProperty(ret, "timeout", {
get: function ()
{
var uid, xinfo;
try
if (this._timeout == null)
{
uid = require('user-sessions').consoleUid();
xinfo = require('monitor-info').getXInfo(uid);
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.stdin.write(location + ' --help-all | grep timeout\nexit\n');
child.stderr.on('data', function (e) { });
child.waitExit();
Object.defineProperty(this, "_timeout", { value: child.stdout.str.trim() == '' ? false : true });
return (this._timeout);
}
catch (e)
else
{
uid = 0;
xinfo = require('monitor-info').getXInfo(0);
return (this._timeout);
}
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.stdin.write(location + ' --help-all | grep timeout\nexit\n');
child.stderr.on('data', function (e) { });
child.waitExit();
return (child.stdout.str.trim() == '' ? false : true);
}
});
Object.defineProperty(ret, "version", {
get: function ()
{
var uid, xinfo;
try
if (this._version == null)
{
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 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.stdin.write(location + ' --version | awk -F. \'{ printf "[%s, %s]\\n", $1, $2; } \'\nexit\n');
child.waitExit();
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.stderr.str = ''; child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write(location + ' --version | awk -F. \'{ printf "[%s, %s]\\n", $1, $2; } \'\nexit\n');
child.waitExit();
try
{
return (JSON.parse(child.stdout.str.trim()));
try
{
if (child.stderr.str.includes('-CRITICAL **')) { object.defineProperty(this, "broken", { value: true }); }
Object.defineProperty(this, "_version", {value: JSON.parse(child.stdout.str.trim())});
return (this._version);
}
catch (e)
{
Object.defineProperty(this, "_version", { value: [2, 16] });
return (this._version);
}
}
catch (e)
else
{
return ([2, 16]);
return (this._version);
}
}
});
@@ -264,20 +283,19 @@ function linux_messageBox()
})()
});
}
else
{
Object.defineProperty(this, 'notifysend',
Object.defineProperty(this, 'notifysend',
{
value: (function ()
{
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 notify-send | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim() == '' ? null : { path: child.stdout.str.trim() });
})()
});
}
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();
return (child.stdout.str.trim() == '' ? null : { path: child.stdout.str.trim() });
})()
});
this.create = function create(title, caption, timeout, layout)
{

View File

@@ -126,6 +126,7 @@ function Toaster()
{
if (process.platform == 'linux' && !require('linux-dbus').hasService('org.freedesktop.Notifications'))
{
// No D-Bus service to handle notifications, so we must fake a notification with ZENITY --info
if (require('message-box').zenity.timeout)
{
@@ -140,8 +141,9 @@ function Toaster()
}
retVal.child.descriptorMetadata = 'toaster (zenity/messagebox)'
}
else if (require('message-box').zenity.version[0] < 3 || (require('message-box').zenity.version[0] == 3 && require('message-box').zenity.version[1] < 10))
else if (require('message-box').zenity.broken || require('message-box').zenity.version[0] < 3 || (require('message-box').zenity.version[0] == 3 && require('message-box').zenity.version[1] < 10))
{
// ZENITY Notification is broken
if (require('message-box').notifysend)
{
@@ -149,8 +151,9 @@ function Toaster()
if (require('user-sessions').whoami() == 'root')
{
// We're root, so we must run in correct context
var xdg = require('user-sessions').findEnv(retVal.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
retVal.child = require('child_process').execFile('/bin/sh', ['sh']);
retVal.child.stdin.write('su - ' + retVal.username + ' -c "DISPLAY=\'' + retVal.xinfo.display + '\' notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\nexit\n');
retVal.child.stdin.write('su - ' + retVal.username + ' -c "export DISPLAY=' + retVal.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\nexit\n');
}
else
{
@@ -178,6 +181,7 @@ function Toaster()
}
else
{
// Use ZENITY Notification
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--notification', '--title=' + title, '--text=' + caption, '--timeout=5'], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
retVal.child.descriptorMetadata = 'toaster (zenity/notification)'
@@ -214,7 +218,24 @@ function Toaster()
}
else
{
if (require('message-box').xmessage)
if (require('message-box').notifysend)
{
// Using notify-send
if (require('user-sessions').whoami() == 'root')
{
// We're root, so we must run in correct context
var xdg = require('user-sessions').findEnv(retVal.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
retVal.child = require('child_process').execFile('/bin/sh', ['sh']);
retVal.child.stdin.write('su - ' + retVal.username + ' -c "export DISPLAY=' + retVal.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\nexit\n');
}
else
{
// We're a regular user, so we don't need to do anything special
retVal.child = require('child_process').execFile(require('message-box').notifysend.path, ['notify-send', retVal.title, retVal.caption]);
}
retVal.child.descriptorMetadata = 'toaster (notify-send)'
}
else if (require('message-box').xmessage)
{
retVal._mb = require('message-box').create(title, caption, 5, 'OK');
retVal._mb.ret = retVal;