From f874e76f0c2094550af6f5f5f07f92feaaf5c937 Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Fri, 15 Mar 2024 12:13:19 +0000 Subject: [PATCH] wake mac screen with caffeinate (#5935) Signed-off-by: si458 --- agents/meshcore.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/agents/meshcore.js b/agents/meshcore.js index 087b88c97b..bfbac734d2 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -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;