mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 15:53:55 +00:00
Updated zenity logic for notifications, because the version in the Deepin repo is broken
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -183,6 +183,8 @@ function linux_messageBox()
|
||||
var ret = { path: location, timeout: child.stdout.str.trim() == '' ? false : true };
|
||||
Object.defineProperty(ret, "timeout", {
|
||||
get: function ()
|
||||
{
|
||||
if (this._timeout == null)
|
||||
{
|
||||
var uid, xinfo;
|
||||
try
|
||||
@@ -201,12 +203,20 @@ function linux_messageBox()
|
||||
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(this, "_timeout", { value: child.stdout.str.trim() == '' ? false : true });
|
||||
return (this._timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (this._timeout);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(ret, "version", {
|
||||
get: function ()
|
||||
{
|
||||
if (this._version == null)
|
||||
{
|
||||
var uid, xinfo;
|
||||
try
|
||||
@@ -223,16 +233,25 @@ function linux_messageBox()
|
||||
|
||||
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()));
|
||||
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)
|
||||
{
|
||||
return ([2, 16]);
|
||||
Object.defineProperty(this, "_version", { value: [2, 16] });
|
||||
return (this._version);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (this._version);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -264,8 +283,7 @@ function linux_messageBox()
|
||||
})()
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Object.defineProperty(this, 'notifysend',
|
||||
{
|
||||
value: (function ()
|
||||
@@ -277,7 +295,7 @@ function linux_messageBox()
|
||||
return (child.stdout.str.trim() == '' ? null : { path: child.stdout.str.trim() });
|
||||
})()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.create = function create(title, caption, timeout, layout)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user