wake mac screen with caffeinate (#5935)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Mar 15, 2024 at 12:13 UTC f874e76f0c2094550af6f5f5f07f92feaaf5c937
1 file changed +14
agents/meshcore.js
+14
@@ -2942,6 +2942,20 @@ function onTunnelData(data)
2942 if ((this.httprequest.xoptions != null) && (typeof this.httprequest.xoptions.tsid == 'number')) { tsid = this.httprequest.xoptions.tsid; }
2943 require('MeshAgent')._tsid = tsid;
2944
2945 + // If MacOS, Wake up device with caffeinate
2946 + if(process.platform == 'darwin'){
2947 + try {
2948 + var options = {};
2949 + try { options.uid = require('user-sessions').consoleUid(); } catch (ex) { }
2950 + options.type = require('child_process').SpawnTypes.TERM;
2951 + var replydata = "";
2952 + var cmdchild = require('child_process').execFile('/usr/bin/caffeinate', ['caffeinate', '-u', '-t', '10'], options);
2953 + cmdchild.descriptorMetadata = 'UserCommandsShell';
2954 + cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
2955 + cmdchild.stderr.on('data', function (c) { replydata + c.toString(); });
2956 + cmdchild.on('exit', function () { delete cmdchild; });
2957 + } catch(err) { }
2958 + }
2959 // Remote desktop using native pipes
2960 this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(tsid), tunnel: this };
2961 this.httprequest.desktop.kvm.parent = this.httprequest.desktop;