Put in guard code in meshcore.js to prevent new agent from crashing on setclip.
Ylian Saint-Hilaire committed
Aug 28, 2022 at 11:32 UTC
9042f1282c18517220ae44423cb66427a2dede55
1 file changed
+9
-1
agents/meshcore.js
+9
-1
@@ -45,6 +45,7 @@ var MESHRIGHT_CHATNOTIFY = 16384;
45
var MESHRIGHT_UNINSTALL = 32768;
46
var MESHRIGHT_NODESKTOP = 65536;
47
48
+var pendingSetClip = false; // This is a temporary hack to prevent multiple setclips at the same time to stop the agent from crashing.
49
50
function bcdOK() {
51
if (process.platform != 'win32') { return (false); }
@@ -1349,6 +1350,7 @@ function handleServerCommand(data) {
1350
break;
1351
}
1352
case 'setclip': {
1353
+ if (pendingSetClip) return;
1354
// Set the load clipboard to a user value
1355
if (typeof data.data == 'string') {
1356
MeshServerLogEx(22, [data.data.length], "Setting clipboard content, " + data.data.length + " byte(s)", data);
@@ -1368,11 +1370,13 @@ function handleServerCommand(data) {
1370
this._dispatcher = require('win-dispatcher').dispatch({ user: user, modules: [{ name: 'clip-dispatch', script: "module.exports = { dispatch: function dispatch(val) { require('clipboard')(val); process.exit(); } };" }], launch: { module: 'clip-dispatch', method: 'dispatch', args: [clipargs] } });
1371
this._dispatcher.parent = this;
1372
//require('events').setFinalizerMetadata.call(this._dispatcher, 'clip-dispatch');
1373
+ pendingSetClip = true;
1374
this._dispatcher.on('connection', function (c) {
1375
this._c = c;
1376
this._c.root = this.parent;
1377
this._c.on('end', function ()
1378
{
1379
+ pendingSetClip = false;
1380
try { this.root._dispatcher.close(); } catch (ex) { }
1381
this.root._dispatcher = null;
1382
this.root = null;
@@ -4327,7 +4331,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4331
}
4332
break;
4333
case 'setclip': {
4330
- if (args['_'].length != 1) {
4334
+ if (pendingSetClip) {
4335
+ response = 'Busy';
4336
+ } else if (args['_'].length != 1) {
4337
response = 'Proper usage: setclip "sample text"';
4338
} else {
4339
if (require('MeshAgent').isService) {
@@ -4345,11 +4351,13 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4351
this._dispatcher = require('win-dispatcher').dispatch({ user: user, modules: [{ name: 'clip-dispatch', script: "module.exports = { dispatch: function dispatch(val) { require('clipboard')(val); process.exit(); } };" }], launch: { module: 'clip-dispatch', method: 'dispatch', args: [clipargs] } });
4352
this._dispatcher.parent = this;
4353
//require('events').setFinalizerMetadata.call(this._dispatcher, 'clip-dispatch');
4354
+ pendingSetClip = true;
4355
this._dispatcher.on('connection', function (c) {
4356
this._c = c;
4357
this._c.root = this.parent;
4358
this._c.on('end', function ()
4359
{
4360
+ pendingSetClip = false;
4361
try { this.root._dispatcher.close(); } catch (ex) { }
4362
this.root._dispatcher = null;
4363
this.root = null;