1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 15:53:55 +00:00

1. Updated linux-dbus to support querying if a service is present

2. Updated toaster, so it will check if org.freedesktop.Notification is installed
This commit is contained in:
Bryan Roe
2019-08-22 16:57:12 -07:00
parent e666a5f7b9
commit fbd67d2c9c
3 changed files with 29 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -126,3 +126,12 @@ function dbus(address, uid)
} }
module.exports = dbus; module.exports = dbus;
module.exports.hasService = function hasService(name)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('cat /usr/share/dbus-1/services/*.service | grep "' + name + '" | awk -F= \'{ if( $2=="' + name + '" ) { print $2; } }\'\nexit\n');
child.waitExit();
return (child.stdout.str.trim() != '');
};

View File

@@ -118,7 +118,23 @@ function Toaster()
if (require('message-box').zenity) if (require('message-box').zenity)
{ {
if (require('message-box').zenity.version[0] < 3 || (require('message-box').zenity.version[0] == 3 && require('message-box').zenity.version[1] < 10)) 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)
{
// Timeout Supported
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + retVal.title, '--text=' + retVal.caption, '--timeout=5'], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
}
else
{
// No Timeout Support, so we must fake it
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + retVal.title, '--text=' + retVal.caption], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
retVal.child.timeout = setTimeout(function (c) { c.timeout = null; c.kill(); }, 5000, retVal.child);
}
}
else if (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 // ZENITY Notification is broken
if (require('message-box').notifysend) if (require('message-box').notifysend)