mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-19 09:43:20 +00:00
added power-monitor.sleepDisplay() support to macOS
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -184,8 +184,10 @@ function powerMonitor()
|
|||||||
{
|
{
|
||||||
var promise = require('promise');
|
var promise = require('promise');
|
||||||
p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||||
if (process.platform != 'win32') { p._rej('Not supported'); return (p); }
|
|
||||||
|
|
||||||
|
switch (process.platform)
|
||||||
|
{
|
||||||
|
case 'win32':
|
||||||
if (require('user-sessions').getProcessOwnerName(process.pid).tsid == 0)
|
if (require('user-sessions').getProcessOwnerName(process.pid).tsid == 0)
|
||||||
{
|
{
|
||||||
// We are running as LocalSystem, so we have to find a user session for this to work
|
// We are running as LocalSystem, so we have to find a user session for this to work
|
||||||
@@ -194,7 +196,7 @@ function powerMonitor()
|
|||||||
{
|
{
|
||||||
options.user = require('user-sessions').getUsername(require('user-sessions').consoleUid());
|
options.user = require('user-sessions').getUsername(require('user-sessions').consoleUid());
|
||||||
}
|
}
|
||||||
catch(ee)
|
catch (ee)
|
||||||
{
|
{
|
||||||
p._rej('No users logged in');
|
p._rej('No users logged in');
|
||||||
return (p);
|
return (p);
|
||||||
@@ -213,6 +215,19 @@ function powerMonitor()
|
|||||||
p._res();
|
p._res();
|
||||||
if (require('child-container').child) { process._exit(); }
|
if (require('child-container').child) { process._exit(); }
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 'darwin':
|
||||||
|
p.child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
p.child.promise = p;
|
||||||
|
p.child.stderr.on('data', function () { });
|
||||||
|
p.child.stdout.on('data', function () { });
|
||||||
|
p.child.on('exit', function () { this.promise._res(); });
|
||||||
|
p.child.stdin.write('pmset displaysleepnow\nexit\n');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
p._rej('Not Supported');
|
||||||
|
break;
|
||||||
|
}
|
||||||
return (p);
|
return (p);
|
||||||
};
|
};
|
||||||
this.wakeDisplay = function wakeDisplay()
|
this.wakeDisplay = function wakeDisplay()
|
||||||
|
|||||||
Reference in New Issue
Block a user