1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-10 05:13:38 +00:00

Added 'isLoaded' and 'load' helper on MacOS

This commit is contained in:
Bryan Roe
2019-04-19 15:12:06 -07:00
parent c64a726f2d
commit 1adcae7957
2 changed files with 27 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@@ -383,6 +383,7 @@ function serviceManager()
return (child.stdout.str.trim());
})()
});
if (!ret.alias)
{
Object.defineProperty(ret, 'alias', {
@@ -406,6 +407,23 @@ function serviceManager()
child.waitExit();
return (parseInt(child.stdout.str.trim()));
};
ret.isLoaded = function isLoaded()
{
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("launchctl list | grep '" + this.alias + "' | awk '{ if($3==\"" + this.alias + "\"){print $1;}}'\nexit\n");
child.waitExit();
return (child.stdout.str.trim() != '');
};
ret.load = function load()
{
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('launchctl load ' + this.plist + '\nexit\n');
child.waitExit();
};
ret.isRunning = function isRunning()
{
return (this.getPID() > 0);