wake mac screen with caffeinate (#5935)

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2024-03-15 12:13:19 +00:00 committed by GitHub
parent 105612c199
commit f874e76f0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2942,6 +2942,20 @@ function onTunnelData(data)
if ((this.httprequest.xoptions != null) && (typeof this.httprequest.xoptions.tsid == 'number')) { tsid = this.httprequest.xoptions.tsid; }
require('MeshAgent')._tsid = tsid;
// If MacOS, Wake up device with caffeinate
if(process.platform == 'darwin'){
try {
var options = {};
try { options.uid = require('user-sessions').consoleUid(); } catch (ex) { }
options.type = require('child_process').SpawnTypes.TERM;
var replydata = "";
var cmdchild = require('child_process').execFile('/usr/bin/caffeinate', ['caffeinate', '-u', '-t', '10'], options);
cmdchild.descriptorMetadata = 'UserCommandsShell';
cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
cmdchild.stderr.on('data', function (c) { replydata + c.toString(); });
cmdchild.on('exit', function () { delete cmdchild; });
} catch(err) { }
}
// Remote desktop using native pipes
this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(tsid), tunnel: this };
this.httprequest.desktop.kvm.parent = this.httprequest.desktop;